rgeo-kml 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Version +1 -0
- data/lib/rgeo-kml.rb +7 -0
- data/lib/rgeo/kml.rb +39 -0
- data/lib/rgeo/kml/coder.rb +222 -0
- data/lib/rgeo/kml/coordinates_builder.rb +37 -0
- data/lib/rgeo/kml/entities.rb +275 -0
- data/lib/rgeo/kml/interface.rb +99 -0
- data/lib/rgeo/kml/kml_stream_listener.rb +82 -0
- data/lib/rgeo/kml/line_string_builder.rb +20 -0
- data/lib/rgeo/kml/linear_ring_builder.rb +20 -0
- data/lib/rgeo/kml/multi_geometry_builder.rb +73 -0
- data/lib/rgeo/kml/point_builder.rb +20 -0
- data/lib/rgeo/kml/polygon_builder.rb +26 -0
- data/lib/rgeo/kml/version.rb +26 -0
- data/test/tc_basic_test.rb +328 -0
- metadata +75 -0
@@ -0,0 +1,99 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Kml toplevel interface
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
module RGeo
|
8
|
+
|
9
|
+
module Kml
|
10
|
+
|
11
|
+
class << self
|
12
|
+
|
13
|
+
|
14
|
+
# High-level convenience routine for encoding an object as Kml.
|
15
|
+
# Pass the object, which may one of the geometry objects specified
|
16
|
+
# in RGeo::Feature, or an appropriate Kml wrapper entity such
|
17
|
+
# as RGeo::Kml::Feature or RGeo::Kml::FeatureCollection.
|
18
|
+
#
|
19
|
+
# The only option supported is <tt>:entity_factory</tt>, which lets
|
20
|
+
# you override the types of Kml entities supported. See
|
21
|
+
# RGeo::Kml::EntityFactory for more information. By default,
|
22
|
+
# encode supports objects of type RGeo::Kml::Feature and
|
23
|
+
# RGeo::Kml::FeatureCollection.
|
24
|
+
|
25
|
+
def encode(object_, opts_={})
|
26
|
+
Coder.new(opts_).encode(object_)
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
# High-level convenience routine for decoding an object from Kml.
|
31
|
+
# The input may be a JSON hash, a String, or an IO object from which
|
32
|
+
# to read the JSON string.
|
33
|
+
#
|
34
|
+
# Options include:
|
35
|
+
#
|
36
|
+
# [<tt>:geo_factory</tt>]
|
37
|
+
# Specifies the geo factory to use to create geometry objects.
|
38
|
+
# Defaults to the preferred cartesian factory.
|
39
|
+
# [<tt>:entity_factory</tt>]
|
40
|
+
# Specifies an entity factory, which lets you override the types
|
41
|
+
# of Kml entities that are created. It defaults to the default
|
42
|
+
# RGeo::Kml::EntityFactory, which generates objects of type
|
43
|
+
# RGeo::Kml::Feature or RGeo::Kml::FeatureCollection.
|
44
|
+
# See RGeo::Kml::EntityFactory for more information.
|
45
|
+
# [<tt>:json_parser</tt>]
|
46
|
+
# Specifies a JSON parser to use when decoding a String or IO
|
47
|
+
# object. The value may be a Proc object taking the string as the
|
48
|
+
# sole argument and returning the JSON hash, or it may be one of
|
49
|
+
# the special values <tt>:json</tt>, <tt>:yajl</tt>, or
|
50
|
+
# <tt>:active_support</tt>. Setting one of those special values
|
51
|
+
# will require the corresponding library to be available. Note
|
52
|
+
# that the <tt>:json</tt> library is present in the standard
|
53
|
+
# library in Ruby 1.9, but requires the "json" gem in Ruby 1.8.
|
54
|
+
# If a parser is not specified, then the decode method will not
|
55
|
+
# accept a String or IO object; it will require a Hash.
|
56
|
+
|
57
|
+
def decode(input_, opts_={})
|
58
|
+
Coder.new(opts_).decode(input_)
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
# Creates and returns a coder object of type RGeo::Kml::Coder
|
63
|
+
# that encapsulates encoding and decoding settings (principally the
|
64
|
+
# RGeo::Feature::Factory and the RGeo::Kml::EntityFactory to be
|
65
|
+
# used).
|
66
|
+
#
|
67
|
+
# The geo factory is a required argument. Other options include:
|
68
|
+
#
|
69
|
+
# [<tt>:geo_factory</tt>]
|
70
|
+
# Specifies the geo factory to use to create geometry objects.
|
71
|
+
# Defaults to the preferred cartesian factory.
|
72
|
+
# [<tt>:entity_factory</tt>]
|
73
|
+
# Specifies an entity factory, which lets you override the types
|
74
|
+
# of Kml entities that are created. It defaults to the default
|
75
|
+
# RGeo::Kml::EntityFactory, which generates objects of type
|
76
|
+
# RGeo::Kml::Feature or RGeo::Kml::FeatureCollection.
|
77
|
+
# See RGeo::Kml::EntityFactory for more information.
|
78
|
+
# [<tt>:json_parser</tt>]
|
79
|
+
# Specifies a JSON parser to use when decoding a String or IO
|
80
|
+
# object. The value may be a Proc object taking the string as the
|
81
|
+
# sole argument and returning the JSON hash, or it may be one of
|
82
|
+
# the special values <tt>:json</tt>, <tt>:yajl</tt>, or
|
83
|
+
# <tt>:active_support</tt>. Setting one of those special values
|
84
|
+
# will require the corresponding library to be available. Note
|
85
|
+
# that the <tt>:json</tt> library is present in the standard
|
86
|
+
# library in Ruby 1.9, but requires the "json" gem in Ruby 1.8.
|
87
|
+
# If a parser is not specified, then the decode method will not
|
88
|
+
# accept a String or IO object; it will require a Hash.
|
89
|
+
|
90
|
+
def coder(opts_={})
|
91
|
+
Coder.new(opts_)
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require "rexml/document"
|
2
|
+
require "rexml/streamlistener"
|
3
|
+
require "set"
|
4
|
+
|
5
|
+
module RGeo
|
6
|
+
module Kml
|
7
|
+
|
8
|
+
class KmlStreamListener
|
9
|
+
include REXML::StreamListener
|
10
|
+
|
11
|
+
attr_reader :geo_factory, :tags, :current_builder, :first_builder, :result
|
12
|
+
|
13
|
+
def initialize( geo_factory, interesting_tags = %w{coordinates Point LineString LinearRing Polygon MultiGeometry}.freeze )
|
14
|
+
@geo_factory = geo_factory
|
15
|
+
@tags = interesting_tags
|
16
|
+
end
|
17
|
+
|
18
|
+
def tag_start(name, attrs)
|
19
|
+
case name
|
20
|
+
when "coordinates"
|
21
|
+
@current_builder = CoordinatesBuilder.new(geo_factory, @current_builder)
|
22
|
+
when "Point"
|
23
|
+
@current_builder = PointBuilder.new(geo_factory, @current_builder)
|
24
|
+
when "LineString"
|
25
|
+
@current_builder = LineStringBuilder.new(geo_factory, @current_builder)
|
26
|
+
when "LinearRing"
|
27
|
+
@current_builder = LinearRingBuilder.new(geo_factory, @current_builder)
|
28
|
+
when "Polygon"
|
29
|
+
@current_builder = PolygonBuilder.new(geo_factory, @current_builder)
|
30
|
+
when "MultiGeometry"
|
31
|
+
@current_builder = MultiGeometryBuilder.new(geo_factory, @current_builder)
|
32
|
+
else
|
33
|
+
#puts "Unknown or unparsed tag #{name}"
|
34
|
+
end
|
35
|
+
|
36
|
+
if tags.include?(name)
|
37
|
+
@first_builder = @current_builder if @first_builder == nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def tag_end(name)
|
42
|
+
if @first_builder == @current_builder
|
43
|
+
@result = @first_builder.build
|
44
|
+
else
|
45
|
+
@current_builder.build
|
46
|
+
|
47
|
+
case name
|
48
|
+
when "coordinates"
|
49
|
+
@current_builder.parent.points = @current_builder.points
|
50
|
+
@current_builder = @current_builder.parent
|
51
|
+
when "Point"
|
52
|
+
@current_builder.parent.add_point( @current_builder.point )
|
53
|
+
@current_builder = @current_builder.parent
|
54
|
+
when "LineString"
|
55
|
+
@current_builder.parent.add_line_string( @current_builder.line_string )
|
56
|
+
@current_builder = @current_builder.parent
|
57
|
+
when "LinearRing"
|
58
|
+
@current_builder.parent.add_linear_ring( @current_builder.linear_ring )
|
59
|
+
@current_builder = @current_builder.parent
|
60
|
+
when "Polygon"
|
61
|
+
@current_builder.parent.add_polygon( @current_builder.polygon )
|
62
|
+
@current_builder = @current_builder.parent
|
63
|
+
else
|
64
|
+
#puts "Unknown or unparsed tag #{name}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def text(text)
|
70
|
+
@cur_text = text
|
71
|
+
@current_builder.text = text
|
72
|
+
end
|
73
|
+
|
74
|
+
def parse(text)
|
75
|
+
return nil if text.nil?
|
76
|
+
REXML::Document.parse_stream(text, self)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module RGeo
|
2
|
+
module Kml
|
3
|
+
|
4
|
+
class LineStringBuilder
|
5
|
+
attr_reader :parent, :geo_factory, :line_string
|
6
|
+
attr_accessor :points, :text
|
7
|
+
|
8
|
+
def initialize(geo_factory, parent)
|
9
|
+
@geo_factory = geo_factory
|
10
|
+
@parent = parent
|
11
|
+
end
|
12
|
+
|
13
|
+
def build
|
14
|
+
return nil unless points.kind_of?(::Array)
|
15
|
+
@line_string = @geo_factory.line_string(points)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module RGeo
|
2
|
+
module Kml
|
3
|
+
|
4
|
+
class LinearRingBuilder
|
5
|
+
attr_reader :parent, :geo_factory, :linear_ring
|
6
|
+
attr_accessor :points, :text
|
7
|
+
|
8
|
+
def initialize(geo_factory, parent)
|
9
|
+
@geo_factory = geo_factory
|
10
|
+
@parent = parent
|
11
|
+
end
|
12
|
+
|
13
|
+
def build
|
14
|
+
return nil unless points.kind_of?(::Array)
|
15
|
+
@linear_ring = @geo_factory.linear_ring(points)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module RGeo
|
2
|
+
module Kml
|
3
|
+
|
4
|
+
class MultiGeometryBuilder
|
5
|
+
attr_reader :geo_factory, :parent
|
6
|
+
attr_accessor :text, :points, :line_strings, :linear_rings, :polygons
|
7
|
+
|
8
|
+
def initialize(geo_factory, parent)
|
9
|
+
@geo_factory = geo_factory
|
10
|
+
@parent = parent
|
11
|
+
@points = []
|
12
|
+
@linear_rings = []
|
13
|
+
@line_strings = []
|
14
|
+
@polygons = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_point(point)
|
18
|
+
@points << point
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_line_string(line_string)
|
22
|
+
@line_strings << line_string
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_linear_ring(linear_ring)
|
26
|
+
@linear_rings << linear_ring
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_polygon(polygon)
|
30
|
+
@polygons << polygon
|
31
|
+
end
|
32
|
+
|
33
|
+
def multi_geometries
|
34
|
+
puts [points, line_strings, linear_rings, polygons].reduce(:+).inspect
|
35
|
+
@multi_geometries ||= [points, line_strings, linear_rings, polygons].reduce(:+)
|
36
|
+
end
|
37
|
+
|
38
|
+
def multi_geometries?
|
39
|
+
geometries_counter = 0
|
40
|
+
|
41
|
+
geometries_counter += 1 if !points.empty?
|
42
|
+
geometries_counter += 1 if !line_strings.empty?
|
43
|
+
geometries_counter += 1 if !linear_rings.empty?
|
44
|
+
geometries_counter += 1 if !polygons.empty?
|
45
|
+
|
46
|
+
geometries_counter >=2 ? true : false
|
47
|
+
end
|
48
|
+
|
49
|
+
def build
|
50
|
+
if multi_geometries?
|
51
|
+
@geo_factory.collection(multi_geometries)
|
52
|
+
elsif !points.empty?
|
53
|
+
return nil unless points.kind_of?(::Array)
|
54
|
+
@geo_factory.multi_point(points)
|
55
|
+
elsif !line_strings.empty?
|
56
|
+
return nil unless line_strings.kind_of?(::Array)
|
57
|
+
@geo_factory.multi_line_string(line_strings)
|
58
|
+
elsif !linear_rings.empty?
|
59
|
+
return nil unless linear_rings.kind_of?(::Array)
|
60
|
+
@geo_factory.multi_linear_ring(linear_rings)
|
61
|
+
elsif !polygons.empty?
|
62
|
+
return nil unless polygons.kind_of?(::Array)
|
63
|
+
@geo_factory.multi_polygon(polygons)
|
64
|
+
else
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module RGeo
|
2
|
+
module Kml
|
3
|
+
|
4
|
+
class PointBuilder
|
5
|
+
attr_reader :parent, :point, :geo_factory
|
6
|
+
attr_accessor :points, :text
|
7
|
+
|
8
|
+
def initialize(geo_factory, parent)
|
9
|
+
@geo_factory = geo_factory
|
10
|
+
@parent = parent
|
11
|
+
end
|
12
|
+
|
13
|
+
def build
|
14
|
+
@point = points.first
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module RGeo
|
2
|
+
module Kml
|
3
|
+
|
4
|
+
class PolygonBuilder
|
5
|
+
attr_reader :parent, :geo_factory, :polygon
|
6
|
+
attr_accessor :linear_rings, :text
|
7
|
+
|
8
|
+
def initialize(geo_factory, parent)
|
9
|
+
@geo_factory = geo_factory
|
10
|
+
@parent = parent
|
11
|
+
@linear_rings = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_linear_ring(linear_ring)
|
15
|
+
linear_rings << linear_ring
|
16
|
+
end
|
17
|
+
|
18
|
+
def build
|
19
|
+
return nil unless ( linear_rings.kind_of?(::Array) || linear_rings.size != 0 )
|
20
|
+
@polygon = @geo_factory.polygon(linear_rings[0], linear_rings[1..-1])
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Version of rgeo-kml
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'versionomy'
|
9
|
+
rescue ::LoadError
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
module RGeo
|
14
|
+
|
15
|
+
module Kml
|
16
|
+
|
17
|
+
# Current version of RGeo::Kml as a frozen string
|
18
|
+
VERSION_STRING = ::File.read(::File.dirname(__FILE__)+'/../../../Version').strip.freeze
|
19
|
+
|
20
|
+
# Current version of RGeo::Kml as a Versionomy object, if the
|
21
|
+
# Versionomy gem is available; otherwise equal to VERSION_STRING.
|
22
|
+
VERSION = defined?(::Versionomy) ? ::Versionomy.parse(VERSION_STRING) : VERSION_STRING
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,328 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Tests for basic Kml usage
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
require 'rgeo/kml'
|
9
|
+
|
10
|
+
|
11
|
+
module RGeo
|
12
|
+
module Kml
|
13
|
+
module Tests # :nodoc:
|
14
|
+
|
15
|
+
class TestKml < ::Test::Unit::TestCase # :nodoc:
|
16
|
+
|
17
|
+
|
18
|
+
def setup
|
19
|
+
@geo_factory = ::RGeo::Cartesian.simple_factory(:srid => 4326)
|
20
|
+
@geo_factory_z = ::RGeo::Cartesian.simple_factory(:srid => 4326, :has_z_coordinate => true)
|
21
|
+
@geo_factory_m = ::RGeo::Cartesian.simple_factory(:srid => 4326, :has_m_coordinate => true)
|
22
|
+
@geo_factory_zm = ::RGeo::Cartesian.simple_factory(:srid => 4326, :has_z_coordinate => true, :has_m_coordinate => true)
|
23
|
+
@entity_factory = ::RGeo::Kml::EntityFactory.instance
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def test_has_version
|
28
|
+
assert_not_nil(::RGeo::Kml::VERSION)
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def test_nil
|
33
|
+
assert_nil(::RGeo::Kml.encode(nil))
|
34
|
+
assert_nil(::RGeo::Kml.decode(nil, :geo_factory => @geo_factory))
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def test_point
|
39
|
+
object_ = @geo_factory.point(10, 20)
|
40
|
+
kml_ = "<Point>\n<coordinates>10.0,20.0</coordinates>\n</Point>\n"
|
41
|
+
|
42
|
+
assert_equal(kml_, ::RGeo::Kml.encode(object_))
|
43
|
+
assert(::RGeo::Kml.decode(kml_, :geo_factory => @geo_factory) == object_ )
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def test_point_z
|
48
|
+
object_ = @geo_factory_z.point(10, 20, -1)
|
49
|
+
kml_ = "<Point>
|
50
|
+
<coordinates>10.0,20.0,-1.0</coordinates>
|
51
|
+
</Point>\n"
|
52
|
+
|
53
|
+
assert_equal(kml_, ::RGeo::Kml.encode(object_))
|
54
|
+
assert(::RGeo::Kml.decode(kml_, :geo_factory => @geo_factory_z).equals?(object_))
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
# def test_point_m
|
59
|
+
# object_ = @geo_factory_m.point(10, 20, -1)
|
60
|
+
# kml_ = "<Point>\n<coordinates>10.0,20.0,-1.0</coordinates>\n</Point>\n"
|
61
|
+
|
62
|
+
# assert_equal(kml_, ::RGeo::Kml.encode(object_))
|
63
|
+
# assert(::RGeo::Kml.decode(kml_, :geo_factory => @geo_factory_m).eql?(object_))
|
64
|
+
# end
|
65
|
+
|
66
|
+
|
67
|
+
# def test_point_zm
|
68
|
+
# object_ = @geo_factory_zm.point(10, 20, -1, -2)
|
69
|
+
# kml_ = {
|
70
|
+
# 'type' => 'Point',
|
71
|
+
# 'coordinates' => [10.0, 20.0, -1.0, -2.0],
|
72
|
+
# }
|
73
|
+
# assert_equal(kml_, ::RGeo::Kml.encode(object_))
|
74
|
+
# assert(::RGeo::Kml.decode(kml_, :geo_factory => @geo_factory_zm).eql?(object_))
|
75
|
+
# end
|
76
|
+
|
77
|
+
|
78
|
+
def test_line_string
|
79
|
+
object_ = @geo_factory.line_string([@geo_factory.point(10, 20), @geo_factory.point(12, 22), @geo_factory.point(-3, 24)])
|
80
|
+
kml_ = "<LineString>
|
81
|
+
<coordinates>
|
82
|
+
10.0,20.0
|
83
|
+
12.0,22.0
|
84
|
+
-3.0,24.0
|
85
|
+
</coordinates>
|
86
|
+
</LineString>\n"
|
87
|
+
|
88
|
+
assert_equal(kml_, ::RGeo::Kml.encode(object_))
|
89
|
+
assert(::RGeo::Kml.decode(kml_, :geo_factory => @geo_factory) == object_ )
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def test_polygon
|
94
|
+
object_ = @geo_factory.polygon(@geo_factory.linear_ring([@geo_factory.point(10, 20), @geo_factory.point(12, 22), @geo_factory.point(-3, 24), @geo_factory.point(10, 20)]))
|
95
|
+
kml_ = "<Polygon>
|
96
|
+
<outerBoundaryIs><LinearRing><coordinates>
|
97
|
+
10.0,20.0
|
98
|
+
12.0,22.0
|
99
|
+
-3.0,24.0
|
100
|
+
10.0,20.0
|
101
|
+
</coordinates></LinearRing></outerBoundaryIs>
|
102
|
+
</Polygon>\n"
|
103
|
+
|
104
|
+
assert_equal(kml_, ::RGeo::Kml.encode(object_))
|
105
|
+
assert(::RGeo::Kml.decode(kml_, :geo_factory => @geo_factory) == object_ )
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
def test_polygon_complex
|
110
|
+
object_ = @geo_factory.polygon(@geo_factory.linear_ring([@geo_factory.point(0, 0), @geo_factory.point(10, 0), @geo_factory.point(10, 10), @geo_factory.point(0, 10), @geo_factory.point(0, 0)]), [@geo_factory.linear_ring([@geo_factory.point(4, 4), @geo_factory.point(6, 5), @geo_factory.point(4, 6), @geo_factory.point(4, 4)])])
|
111
|
+
|
112
|
+
kml_ = "<Polygon>
|
113
|
+
<outerBoundaryIs><LinearRing><coordinates>
|
114
|
+
0.0,0.0
|
115
|
+
10.0,0.0
|
116
|
+
10.0,10.0
|
117
|
+
0.0,10.0
|
118
|
+
0.0,0.0
|
119
|
+
</coordinates></LinearRing></outerBoundaryIs>
|
120
|
+
<innerBoundaryIs><LinearRing><coordinates>
|
121
|
+
4.0,4.0
|
122
|
+
6.0,5.0
|
123
|
+
4.0,6.0
|
124
|
+
4.0,4.0
|
125
|
+
</coordinates></LinearRing></innerBoundaryIs>
|
126
|
+
</Polygon>\n"
|
127
|
+
|
128
|
+
assert_equal(kml_, ::RGeo::Kml.encode(object_))
|
129
|
+
assert(::RGeo::Kml.decode(kml_, :geo_factory => @geo_factory) == object_ )
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
def test_multi_point
|
134
|
+
object_ = @geo_factory.multi_point([@geo_factory.point(10, 20), @geo_factory.point(12, 22), @geo_factory.point(-3, 24)])
|
135
|
+
|
136
|
+
kml_ = "<MultiGeometry>
|
137
|
+
<Point>
|
138
|
+
<coordinates>10.0,20.0</coordinates>
|
139
|
+
</Point>
|
140
|
+
<Point>
|
141
|
+
<coordinates>12.0,22.0</coordinates>
|
142
|
+
</Point>
|
143
|
+
<Point>
|
144
|
+
<coordinates>-3.0,24.0</coordinates>
|
145
|
+
</Point>
|
146
|
+
</MultiGeometry>\n"
|
147
|
+
|
148
|
+
assert_equal(kml_, ::RGeo::Kml.encode(object_))
|
149
|
+
assert(::RGeo::Kml.decode(kml_, :geo_factory => @geo_factory) == object_ )
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
def test_multi_line_string
|
154
|
+
object_ = @geo_factory.multi_line_string([@geo_factory.line_string([@geo_factory.point(10, 20), @geo_factory.point(12, 22), @geo_factory.point(-3, 24)]), @geo_factory.line_string([@geo_factory.point(1, 2), @geo_factory.point(3, 4)])])
|
155
|
+
kml_ = "<MultiGeometry>
|
156
|
+
<LineString>
|
157
|
+
<coordinates>
|
158
|
+
10.0,20.0
|
159
|
+
12.0,22.0
|
160
|
+
-3.0,24.0
|
161
|
+
</coordinates>
|
162
|
+
</LineString>
|
163
|
+
<LineString>
|
164
|
+
<coordinates>
|
165
|
+
1.0,2.0
|
166
|
+
3.0,4.0
|
167
|
+
</coordinates>
|
168
|
+
</LineString>
|
169
|
+
</MultiGeometry>\n"
|
170
|
+
assert_equal(kml_, ::RGeo::Kml.encode(object_))
|
171
|
+
assert(::RGeo::Kml.decode(kml_, :geo_factory => @geo_factory) == object_ )
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
def test_multi_polygon
|
176
|
+
object_ = @geo_factory.multi_polygon([@geo_factory.polygon(@geo_factory.linear_ring([@geo_factory.point(0, 0), @geo_factory.point(10, 0), @geo_factory.point(10, 10), @geo_factory.point(0, 10), @geo_factory.point(0, 0)]), [@geo_factory.linear_ring([@geo_factory.point(4, 4), @geo_factory.point(6, 5), @geo_factory.point(4, 6), @geo_factory.point(4, 4)])]), @geo_factory.polygon(@geo_factory.linear_ring([@geo_factory.point(-10,-10), @geo_factory.point(-15, -10), @geo_factory.point(-10, -15), @geo_factory.point(-10, -10)]))])
|
177
|
+
kml_ = "<MultiGeometry>
|
178
|
+
<Polygon>
|
179
|
+
<outerBoundaryIs><LinearRing><coordinates>
|
180
|
+
0.0,0.0
|
181
|
+
10.0,0.0
|
182
|
+
10.0,10.0
|
183
|
+
0.0,10.0
|
184
|
+
0.0,0.0
|
185
|
+
</coordinates></LinearRing></outerBoundaryIs>
|
186
|
+
<innerBoundaryIs><LinearRing><coordinates>
|
187
|
+
4.0,4.0
|
188
|
+
6.0,5.0
|
189
|
+
4.0,6.0
|
190
|
+
4.0,4.0
|
191
|
+
</coordinates></LinearRing></innerBoundaryIs>
|
192
|
+
</Polygon>
|
193
|
+
<Polygon>
|
194
|
+
<outerBoundaryIs><LinearRing><coordinates>
|
195
|
+
-10.0,-10.0
|
196
|
+
-15.0,-10.0
|
197
|
+
-10.0,-15.0
|
198
|
+
-10.0,-10.0
|
199
|
+
</coordinates></LinearRing></outerBoundaryIs>
|
200
|
+
</Polygon>
|
201
|
+
</MultiGeometry>\n"
|
202
|
+
assert_equal(kml_, ::RGeo::Kml.encode(object_))
|
203
|
+
assert(::RGeo::Kml.decode(kml_, :geo_factory => @geo_factory) == object_ )
|
204
|
+
end
|
205
|
+
|
206
|
+
|
207
|
+
def test_geometry_collection
|
208
|
+
object_ = @geo_factory.collection([@geo_factory.point(10, 20), @geo_factory.line_string([@geo_factory.point(12, 22), @geo_factory.point(-3, 24)])])
|
209
|
+
kml_ = "<MultiGeometry>
|
210
|
+
<Point>
|
211
|
+
<coordinates>10.0,20.0</coordinates>
|
212
|
+
</Point>
|
213
|
+
<LineString>
|
214
|
+
<coordinates>
|
215
|
+
12.0,22.0
|
216
|
+
-3.0,24.0
|
217
|
+
</coordinates>
|
218
|
+
</LineString>
|
219
|
+
</MultiGeometry>\n"
|
220
|
+
assert_equal(kml_, ::RGeo::Kml.encode(object_))
|
221
|
+
assert(::RGeo::Kml.decode(kml_, :geo_factory => @geo_factory) == object_ )
|
222
|
+
end
|
223
|
+
|
224
|
+
|
225
|
+
# def test_feature
|
226
|
+
# object_ = @entity_factory.feature(@geo_factory.point(10, 20))
|
227
|
+
# kml_ = {
|
228
|
+
# 'type' => 'Feature',
|
229
|
+
# 'geometry' => {
|
230
|
+
# 'type' => 'Point',
|
231
|
+
# 'coordinates' => [10.0, 20.0],
|
232
|
+
# },
|
233
|
+
# 'properties' => {},
|
234
|
+
# }
|
235
|
+
# assert_equal(kml_, ::RGeo::Kml.encode(object_))
|
236
|
+
# assert(::RGeo::Kml.decode(kml_, :geo_factory => @geo_factory).eql?(object_))
|
237
|
+
# end
|
238
|
+
|
239
|
+
|
240
|
+
# def test_feature_nulls
|
241
|
+
# kml_ = {
|
242
|
+
# 'type' => 'Feature',
|
243
|
+
# 'geometry' => nil,
|
244
|
+
# 'properties' => nil,
|
245
|
+
# }
|
246
|
+
# obj_ = ::RGeo::Kml.decode(kml_, :geo_factory => @geo_factory)
|
247
|
+
# assert_not_nil(obj_)
|
248
|
+
# assert_nil(obj_.geometry)
|
249
|
+
# assert_equal({}, obj_.properties)
|
250
|
+
# end
|
251
|
+
|
252
|
+
|
253
|
+
# def test_feature_complex
|
254
|
+
# object_ = @entity_factory.feature(@geo_factory.point(10, 20), 2, {'prop1' => 'foo', 'prop2' => 'bar'})
|
255
|
+
# kml_ = {
|
256
|
+
# 'type' => 'Feature',
|
257
|
+
# 'geometry' => {
|
258
|
+
# 'type' => 'Point',
|
259
|
+
# 'coordinates' => [10.0, 20.0],
|
260
|
+
# },
|
261
|
+
# 'id' => 2,
|
262
|
+
# 'properties' => {'prop1' => 'foo', 'prop2' => 'bar'},
|
263
|
+
# }
|
264
|
+
# assert_equal(kml_, ::RGeo::Kml.encode(object_))
|
265
|
+
# assert(::RGeo::Kml.decode(kml_, :geo_factory => @geo_factory).eql?(object_))
|
266
|
+
# end
|
267
|
+
|
268
|
+
|
269
|
+
# def test_feature_with_symbol_prop_keys
|
270
|
+
# object_ = @entity_factory.feature(@geo_factory.point(10, 20), 2, {:prop1 => 'foo', 'prop2' => 'bar'})
|
271
|
+
# kml_ = {
|
272
|
+
# 'type' => 'Feature',
|
273
|
+
# 'geometry' => {
|
274
|
+
# 'type' => 'Point',
|
275
|
+
# 'coordinates' => [10.0, 20.0],
|
276
|
+
# },
|
277
|
+
# 'id' => 2,
|
278
|
+
# 'properties' => {'prop1' => 'foo', 'prop2' => 'bar'},
|
279
|
+
# }
|
280
|
+
# assert_equal('foo', object_.property('prop1'))
|
281
|
+
# assert_equal('bar', object_.property(:prop2))
|
282
|
+
# assert_equal(kml_, ::RGeo::Kml.encode(object_))
|
283
|
+
# assert(::RGeo::Kml.decode(kml_, :geo_factory => @geo_factory).eql?(object_))
|
284
|
+
# end
|
285
|
+
|
286
|
+
|
287
|
+
# def test_feature_collection
|
288
|
+
# object_ = @entity_factory.feature_collection([@entity_factory.feature(@geo_factory.point(10, 20)), @entity_factory.feature(@geo_factory.point(11, 22)), @entity_factory.feature(@geo_factory.point(10, 20), 8)])
|
289
|
+
# kml_ = {
|
290
|
+
# 'type' => 'FeatureCollection',
|
291
|
+
# 'features' => [
|
292
|
+
# {
|
293
|
+
# 'type' => 'Feature',
|
294
|
+
# 'geometry' => {
|
295
|
+
# 'type' => 'Point',
|
296
|
+
# 'coordinates' => [10.0, 20.0],
|
297
|
+
# },
|
298
|
+
# 'properties' => {},
|
299
|
+
# },
|
300
|
+
# {
|
301
|
+
# 'type' => 'Feature',
|
302
|
+
# 'geometry' => {
|
303
|
+
# 'type' => 'Point',
|
304
|
+
# 'coordinates' => [11.0, 22.0],
|
305
|
+
# },
|
306
|
+
# 'properties' => {},
|
307
|
+
# },
|
308
|
+
# {
|
309
|
+
# 'type' => 'Feature',
|
310
|
+
# 'geometry' => {
|
311
|
+
# 'type' => 'Point',
|
312
|
+
# 'coordinates' => [10.0, 20.0],
|
313
|
+
# },
|
314
|
+
# 'id' => 8,
|
315
|
+
# 'properties' => {},
|
316
|
+
# },
|
317
|
+
# ]
|
318
|
+
# }
|
319
|
+
# assert_equal(kml_, ::RGeo::Kml.encode(object_))
|
320
|
+
# assert(::RGeo::Kml.decode(kml_, :geo_factory => @geo_factory).eql?(object_))
|
321
|
+
# end
|
322
|
+
|
323
|
+
|
324
|
+
end
|
325
|
+
|
326
|
+
end
|
327
|
+
end
|
328
|
+
end
|