Module: RGeo::Kml

Defined in:
lib/rgeo/kml.rb,
lib/rgeo/kml/coder.rb,
lib/rgeo/kml/version.rb,
lib/rgeo/kml/entities.rb,
lib/rgeo/kml/interface.rb,
lib/rgeo/kml/point_builder.rb,
lib/rgeo/kml/polygon_builder.rb,
lib/rgeo/kml/coordinates_builder.rb,
lib/rgeo/kml/kml_stream_listener.rb,
lib/rgeo/kml/line_string_builder.rb,
lib/rgeo/kml/linear_ring_builder.rb,
lib/rgeo/kml/multi_geometry_builder.rb

Overview

This is a namespace for a set of tools that provide KML encoding. See developers.google.com/kml/documentation/ for more information about this specification.

Defined Under Namespace

Classes: Coder, CoordinatesBuilder, EntityFactory, Feature, FeatureCollection, KmlStreamListener, LineStringBuilder, LinearRingBuilder, MultiGeometryBuilder, PointBuilder, PolygonBuilder

Constant Summary collapse

VERSION_STRING =

Current version of RGeo::Kml as a frozen string

::File.read(::File.dirname(__FILE__)+'/../../../Version').strip.freeze
VERSION =

Current version of RGeo::Kml as a Versionomy object, if the Versionomy gem is available; otherwise equal to VERSION_STRING.

defined?(::Versionomy) ? ::Versionomy.parse(VERSION_STRING) : VERSION_STRING

Class Method Summary collapse

Class Method Details

.coder(opts_ = {}) ⇒ Object

Creates and returns a coder object of type RGeo::Kml::Coder that encapsulates encoding and decoding settings (principally the RGeo::Feature::Factory and the RGeo::Kml::EntityFactory to be used).

The geo factory is a required argument. Other options include:

:geo_factory

Specifies the geo factory to use to create geometry objects. Defaults to the preferred cartesian factory.

:entity_factory

Specifies an entity factory, which lets you override the types of Kml entities that are created. It defaults to the default RGeo::Kml::EntityFactory, which generates objects of type RGeo::Kml::Feature or RGeo::Kml::FeatureCollection. See RGeo::Kml::EntityFactory for more information.

:json_parser

Specifies a JSON parser to use when decoding a String or IO object. The value may be a Proc object taking the string as the sole argument and returning the JSON hash, or it may be one of the special values :json, :yajl, or :active_support. Setting one of those special values will require the corresponding library to be available. Note that the :json library is present in the standard library in Ruby 1.9, but requires the “json” gem in Ruby 1.8. If a parser is not specified, then the decode method will not accept a String or IO object; it will require a Hash.


90
91
92
# File 'lib/rgeo/kml/interface.rb', line 90

def coder(opts_={})
  Coder.new(opts_)
end

.decode(input_, opts_ = {}) ⇒ Object

High-level convenience routine for decoding an object from Kml. The input may be a JSON hash, a String, or an IO object from which to read the JSON string.

Options include:

:geo_factory

Specifies the geo factory to use to create geometry objects. Defaults to the preferred cartesian factory.

:entity_factory

Specifies an entity factory, which lets you override the types of Kml entities that are created. It defaults to the default RGeo::Kml::EntityFactory, which generates objects of type RGeo::Kml::Feature or RGeo::Kml::FeatureCollection. See RGeo::Kml::EntityFactory for more information.

:json_parser

Specifies a JSON parser to use when decoding a String or IO object. The value may be a Proc object taking the string as the sole argument and returning the JSON hash, or it may be one of the special values :json, :yajl, or :active_support. Setting one of those special values will require the corresponding library to be available. Note that the :json library is present in the standard library in Ruby 1.9, but requires the “json” gem in Ruby 1.8. If a parser is not specified, then the decode method will not accept a String or IO object; it will require a Hash.


57
58
59
# File 'lib/rgeo/kml/interface.rb', line 57

def decode(input_, opts_={})
  Coder.new(opts_).decode(input_)
end

.encode(object_, opts_ = {}) ⇒ Object

High-level convenience routine for encoding an object as Kml. Pass the object, which may one of the geometry objects specified in RGeo::Feature, or an appropriate Kml wrapper entity such as RGeo::Kml::Feature or RGeo::Kml::FeatureCollection.

The only option supported is :entity_factory, which lets you override the types of Kml entities supported. See RGeo::Kml::EntityFactory for more information. By default, encode supports objects of type RGeo::Kml::Feature and RGeo::Kml::FeatureCollection.


25
26
27
# File 'lib/rgeo/kml/interface.rb', line 25

def encode(object_, opts_={})
  Coder.new(opts_).encode(object_)
end