rgeo 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/History.rdoc +22 -0
  2. data/README.rdoc +124 -0
  3. data/Version +1 -0
  4. data/ext/geos_c_impl/extconf.rb +72 -0
  5. data/ext/geos_c_impl/factory.c +468 -0
  6. data/ext/geos_c_impl/factory.h +217 -0
  7. data/ext/geos_c_impl/geometry.c +644 -0
  8. data/ext/geos_c_impl/geometry.h +65 -0
  9. data/ext/geos_c_impl/geometry_collection.c +580 -0
  10. data/ext/geos_c_impl/geometry_collection.h +79 -0
  11. data/ext/geos_c_impl/globals.h +58 -0
  12. data/ext/geos_c_impl/line_string.c +468 -0
  13. data/ext/geos_c_impl/line_string.h +74 -0
  14. data/ext/geos_c_impl/main.c +65 -0
  15. data/ext/geos_c_impl/point.c +201 -0
  16. data/ext/geos_c_impl/point.h +77 -0
  17. data/ext/geos_c_impl/polygon.c +259 -0
  18. data/ext/geos_c_impl/polygon.h +76 -0
  19. data/ext/geos_c_impl/preface.h +42 -0
  20. data/lib/rgeo.rb +68 -0
  21. data/lib/rgeo/errors.rb +59 -0
  22. data/lib/rgeo/features.rb +89 -0
  23. data/lib/rgeo/features/curve.rb +155 -0
  24. data/lib/rgeo/features/factory.rb +191 -0
  25. data/lib/rgeo/features/geometry.rb +560 -0
  26. data/lib/rgeo/features/geometry_collection.rb +118 -0
  27. data/lib/rgeo/features/line.rb +65 -0
  28. data/lib/rgeo/features/line_string.rb +101 -0
  29. data/lib/rgeo/features/linear_ring.rb +65 -0
  30. data/lib/rgeo/features/multi_curve.rb +112 -0
  31. data/lib/rgeo/features/multi_line_string.rb +65 -0
  32. data/lib/rgeo/features/multi_point.rb +72 -0
  33. data/lib/rgeo/features/multi_polygon.rb +96 -0
  34. data/lib/rgeo/features/multi_surface.rb +115 -0
  35. data/lib/rgeo/features/point.rb +97 -0
  36. data/lib/rgeo/features/polygon.rb +141 -0
  37. data/lib/rgeo/features/surface.rb +121 -0
  38. data/lib/rgeo/geo_json.rb +58 -0
  39. data/lib/rgeo/geo_json/coder.rb +305 -0
  40. data/lib/rgeo/geo_json/entities.rb +284 -0
  41. data/lib/rgeo/geo_json/interface.rb +95 -0
  42. data/lib/rgeo/geography.rb +75 -0
  43. data/lib/rgeo/geography/common/geometry_collection_methods.rb +206 -0
  44. data/lib/rgeo/geography/common/geometry_methods.rb +92 -0
  45. data/lib/rgeo/geography/common/helper.rb +102 -0
  46. data/lib/rgeo/geography/common/line_string_methods.rb +187 -0
  47. data/lib/rgeo/geography/common/point_methods.rb +149 -0
  48. data/lib/rgeo/geography/common/polygon_methods.rb +122 -0
  49. data/lib/rgeo/geography/factories.rb +136 -0
  50. data/lib/rgeo/geography/factory.rb +246 -0
  51. data/lib/rgeo/geography/projected_window.rb +467 -0
  52. data/lib/rgeo/geography/simple_mercator/feature_classes.rb +320 -0
  53. data/lib/rgeo/geography/simple_mercator/feature_methods.rb +291 -0
  54. data/lib/rgeo/geography/simple_mercator/projector.rb +116 -0
  55. data/lib/rgeo/geography/simple_spherical/calculations.rb +70 -0
  56. data/lib/rgeo/geography/simple_spherical/geometry_collection_impl.rb +66 -0
  57. data/lib/rgeo/geography/simple_spherical/geometry_methods.rb +59 -0
  58. data/lib/rgeo/geography/simple_spherical/line_string_impl.rb +104 -0
  59. data/lib/rgeo/geography/simple_spherical/multi_line_string_impl.rb +67 -0
  60. data/lib/rgeo/geography/simple_spherical/multi_point_impl.rb +67 -0
  61. data/lib/rgeo/geography/simple_spherical/multi_polygon_impl.rb +67 -0
  62. data/lib/rgeo/geography/simple_spherical/point_impl.rb +85 -0
  63. data/lib/rgeo/geography/simple_spherical/polygon_impl.rb +66 -0
  64. data/lib/rgeo/geos.rb +72 -0
  65. data/lib/rgeo/geos/factory.rb +260 -0
  66. data/lib/rgeo/geos/impl_additions.rb +57 -0
  67. data/lib/rgeo/geos/interface.rb +74 -0
  68. data/lib/rgeo/version.rb +52 -0
  69. data/tests/geos/tc_factory.rb +91 -0
  70. data/tests/geos/tc_geometry_collection.rb +226 -0
  71. data/tests/geos/tc_line_string.rb +310 -0
  72. data/tests/geos/tc_misc.rb +72 -0
  73. data/tests/geos/tc_multi_line_string.rb +211 -0
  74. data/tests/geos/tc_multi_point.rb +202 -0
  75. data/tests/geos/tc_multi_polygon.rb +210 -0
  76. data/tests/geos/tc_point.rb +305 -0
  77. data/tests/geos/tc_polygon.rb +240 -0
  78. data/tests/simple_mercator/tc_point.rb +303 -0
  79. data/tests/simple_mercator/tc_window.rb +219 -0
  80. data/tests/tc_geojson.rb +230 -0
  81. data/tests/tc_oneoff.rb +61 -0
  82. metadata +162 -0
@@ -0,0 +1,57 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # GEOS implementation additions written in Ruby
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2010 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+
37
+ # :stopdoc:
38
+
39
+ module RGeo
40
+
41
+ module Geos
42
+
43
+
44
+ class GeometryImpl
45
+
46
+ def inspect
47
+ "#<#{self.class}:0x#{object_id.to_s(16)} #{as_text.inspect}>"
48
+ end
49
+
50
+ end
51
+
52
+
53
+ end
54
+
55
+ end
56
+
57
+ # :startdoc:
@@ -0,0 +1,74 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # GEOS toplevel interface
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2010 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+
37
+ module RGeo
38
+
39
+ module Geos
40
+
41
+ @supported = nil
42
+
43
+ class << self
44
+
45
+
46
+ # Returns true if GEOS implementation is supported.
47
+ # If this returns false, GEOS features are not available.
48
+
49
+ def supported?
50
+ @supported.nil? ? (@supported = Factory.respond_to?(:_create)) : @supported
51
+ end
52
+
53
+
54
+ # Returns true if the given feature is a GEOS feature, or if the given
55
+ # factory is a GEOS factory.
56
+
57
+ def is_geos?(object_)
58
+ supported? ? Factory === object_ || GeometryImpl === object_ : false
59
+ end
60
+
61
+
62
+ # Returns a factory for the GEOS implementation.
63
+ # Returns nil if the GEOS implementation is not supported.
64
+
65
+ def factory(opts_={})
66
+ supported? ? Factory.create(opts_) : nil
67
+ end
68
+
69
+
70
+ end
71
+
72
+ end
73
+
74
+ end
@@ -0,0 +1,52 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # RGeo version
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2010 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+
37
+ begin
38
+ require 'versionomy'
39
+ rescue ::LoadError
40
+ end
41
+
42
+
43
+ module RGeo
44
+
45
+ # Current version of RGeo as a frozen string
46
+ VERSION_STRING = ::File.read(::File.dirname(__FILE__)+'/../../Version').strip.freeze
47
+
48
+ # Current version of RGeo as a Versionomy object, if the Versionomy gem
49
+ # is available.
50
+ VERSION = defined?(::Versionomy) ? ::Versionomy.parse(VERSION_STRING) : VERSION_STRING
51
+
52
+ end
@@ -0,0 +1,91 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Tests for the GEOS factory
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2010 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+
37
+ require 'test/unit'
38
+ require 'rgeo'
39
+
40
+
41
+ module RGeo
42
+ module Tests # :nodoc:
43
+ module Geos
44
+
45
+ class TestFactory < ::Test::Unit::TestCase # :nodoc:
46
+
47
+
48
+ def setup
49
+ @factory = ::RGeo::Geos.factory(:srid => 4326)
50
+ end
51
+
52
+
53
+ def test_srid_preserved_through_factory
54
+ geom_ = @factory.point(-10, 20)
55
+ assert_equal(4326, geom_.srid)
56
+ factory_ = geom_.factory
57
+ assert_equal(4326, factory_.srid)
58
+ geom2_ = factory_.point(-20, 25)
59
+ assert_equal(4326, geom2_.srid)
60
+ end
61
+
62
+
63
+ def test_srid_preserved_through_geom_operations
64
+ geom1_ = @factory.point(-10, 20)
65
+ geom2_ = @factory.point(-20, 25)
66
+ geom3_ = geom1_.union(geom2_)
67
+ assert_equal(4326, geom3_.srid)
68
+ assert_equal(4326, geom3_.geometry_n(0).srid)
69
+ assert_equal(4326, geom3_.geometry_n(1).srid)
70
+ end
71
+
72
+
73
+ def test_srid_preserved_through_geom_functions
74
+ geom1_ = @factory.point(-10, 20)
75
+ geom2_ = geom1_.boundary
76
+ assert_equal(4326, geom2_.srid)
77
+ end
78
+
79
+
80
+ def test_srid_preserved_through_dup
81
+ geom1_ = @factory.point(-10, 20)
82
+ geom2_ = geom1_.clone
83
+ assert_equal(4326, geom2_.srid)
84
+ end
85
+
86
+
87
+ end
88
+
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,226 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Tests for the GEOS geometry collection implementation
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2010 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+
37
+ require 'test/unit'
38
+ require 'rgeo'
39
+
40
+
41
+ module RGeo
42
+ module Tests # :nodoc:
43
+ module Geos
44
+
45
+ class TestGeometryCollection < ::Test::Unit::TestCase # :nodoc:
46
+
47
+
48
+ def setup
49
+ @factory = ::RGeo::Geos.factory
50
+ @point1 = @factory.point(0, 0)
51
+ @point2 = @factory.point(1, 0)
52
+ @point3 = @factory.point(-4, 2)
53
+ @point4 = @factory.point(-5, 3)
54
+ @line1 = @factory.line_string([@point3, @point4])
55
+ @line2 = @factory.line_string([@point3, @point4, @point1])
56
+ @line3 = @factory.line(@point3, @point4)
57
+ end
58
+
59
+
60
+ def test_creation_simple
61
+ geom_ = @factory.collection([@point1, @line1])
62
+ assert_not_nil(geom_)
63
+ assert_kind_of(::RGeo::Geos::GeometryCollectionImpl, geom_)
64
+ assert(::RGeo::Features::GeometryCollection === geom_)
65
+ assert_equal(::RGeo::Features::GeometryCollection, geom_.geometry_type)
66
+ assert_equal(2, geom_.num_geometries)
67
+ assert_equal([@point1, @line1], geom_.to_a)
68
+ end
69
+
70
+
71
+ def test_creation_empty
72
+ geom_ = @factory.collection([])
73
+ assert_not_nil(geom_)
74
+ assert_kind_of(::RGeo::Geos::GeometryCollectionImpl, geom_)
75
+ assert(::RGeo::Features::GeometryCollection === geom_)
76
+ assert_equal(::RGeo::Features::GeometryCollection, geom_.geometry_type)
77
+ assert_equal(0, geom_.num_geometries)
78
+ assert_equal([], geom_.to_a)
79
+ end
80
+
81
+
82
+ def test_creation_save_klass
83
+ geom_ = @factory.collection([@point1, @line3])
84
+ assert_not_nil(geom_)
85
+ assert_kind_of(::RGeo::Geos::GeometryCollectionImpl, geom_)
86
+ assert(::RGeo::Features::GeometryCollection === geom_)
87
+ assert_equal(::RGeo::Features::GeometryCollection, geom_.geometry_type)
88
+ assert_equal(2, geom_.num_geometries)
89
+ assert(geom_[1].eql?(@line3))
90
+ end
91
+
92
+
93
+ def test_creation_compound
94
+ geom1_ = @factory.collection([@point1, @line1])
95
+ geom2_ = @factory.collection([@point2, geom1_])
96
+ assert_not_nil(geom2_)
97
+ assert_kind_of(::RGeo::Geos::GeometryCollectionImpl, geom2_)
98
+ assert(::RGeo::Features::GeometryCollection === geom2_)
99
+ assert_equal(::RGeo::Features::GeometryCollection, geom2_.geometry_type)
100
+ assert_equal(2, geom2_.num_geometries)
101
+ assert(geom2_[1].eql?(geom1_))
102
+ end
103
+
104
+
105
+ def test_creation_compound_save_klass
106
+ geom1_ = @factory.collection([@point1, @line3])
107
+ geom2_ = @factory.collection([@point2, geom1_])
108
+ ::GC.start
109
+ assert_not_nil(geom2_)
110
+ assert_kind_of(::RGeo::Geos::GeometryCollectionImpl, geom2_)
111
+ assert(::RGeo::Features::GeometryCollection === geom2_)
112
+ assert_equal(::RGeo::Features::GeometryCollection, geom2_.geometry_type)
113
+ assert_equal(2, geom2_.num_geometries)
114
+ assert(::RGeo::Features::Line === geom2_[1][1])
115
+ end
116
+
117
+
118
+ def test_fully_equal
119
+ geom1_ = @factory.collection([@point1, @line1])
120
+ geom2_ = @factory.collection([@point1, @line1])
121
+ assert(geom1_.eql?(geom2_))
122
+ assert(geom1_.equals?(geom2_))
123
+ end
124
+
125
+
126
+ def test_geometrically_equal
127
+ geom1_ = @factory.collection([@point2, @line2])
128
+ geom2_ = @factory.collection([@point2, @line1, @line2])
129
+ assert(!geom1_.eql?(geom2_))
130
+ assert(geom1_.equals?(geom2_))
131
+ end
132
+
133
+
134
+ def test_empty_equal
135
+ geom1_ = @factory.collection([])
136
+ geom2_ = @factory.collection([])
137
+ assert(geom1_.eql?(geom2_))
138
+ assert(geom1_.equals?(geom2_))
139
+ end
140
+
141
+
142
+ def test_not_equal
143
+ geom1_ = @factory.collection([@point1, @line1])
144
+ geom2_ = @factory.collection([@point2, @line1])
145
+ assert(!geom1_.eql?(geom2_))
146
+ assert(!geom1_.equals?(geom2_))
147
+ end
148
+
149
+
150
+ def test_wkt_creation_simple
151
+ parsed_geom_ = @factory.parse_wkt('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(-4 2, -5 3))')
152
+ built_geom_ = @factory.collection([@point1, @line1])
153
+ assert_equal(built_geom_, parsed_geom_)
154
+ end
155
+
156
+
157
+ def test_wkt_creation_empty
158
+ parsed_geom_ = @factory.parse_wkt('GEOMETRYCOLLECTION EMPTY')
159
+ assert_equal(0, parsed_geom_.num_geometries)
160
+ assert_equal([], parsed_geom_.to_a)
161
+ end
162
+
163
+
164
+ def test_clone
165
+ geom1_ = @factory.collection([@point1, @line1])
166
+ geom2_ = geom1_.clone
167
+ assert_equal(geom1_, geom2_)
168
+ assert_equal(::RGeo::Features::GeometryCollection, geom2_.geometry_type)
169
+ assert_equal(2, geom2_.num_geometries)
170
+ assert_equal([@point1, @line1], geom2_.to_a)
171
+ end
172
+
173
+
174
+ def test_type_check
175
+ geom1_ = @factory.collection([@point1, @line1])
176
+ assert(::RGeo::Features::Geometry.check_type(geom1_))
177
+ assert(!::RGeo::Features::Point.check_type(geom1_))
178
+ assert(::RGeo::Features::GeometryCollection.check_type(geom1_))
179
+ assert(!::RGeo::Features::MultiPoint.check_type(geom1_))
180
+ geom2_ = @factory.collection([@point1, @point2])
181
+ assert(::RGeo::Features::Geometry.check_type(geom2_))
182
+ assert(!::RGeo::Features::Point.check_type(geom2_))
183
+ assert(::RGeo::Features::GeometryCollection.check_type(geom2_))
184
+ assert(!::RGeo::Features::MultiPoint.check_type(geom2_))
185
+ end
186
+
187
+
188
+ def test_as_text_wkt_round_trip
189
+ geom1_ = @factory.collection([@point1, @line1])
190
+ text_ = geom1_.as_text
191
+ geom2_ = @factory.parse_wkt(text_)
192
+ assert_equal(geom1_, geom2_)
193
+ end
194
+
195
+
196
+ def test_as_binary_wkb_round_trip
197
+ geom1_ = @factory.collection([@point1, @line1])
198
+ binary_ = geom1_.as_binary
199
+ geom2_ = @factory.parse_wkb(binary_)
200
+ assert_equal(geom1_, geom2_)
201
+ end
202
+
203
+
204
+ def test_dimension
205
+ geom1_ = @factory.collection([@point1, @line1])
206
+ assert_equal(1, geom1_.dimension)
207
+ geom2_ = @factory.collection([@point1, @point2])
208
+ assert_equal(0, geom2_.dimension)
209
+ geom3_ = @factory.collection([])
210
+ assert_equal(-1, geom3_.dimension)
211
+ end
212
+
213
+
214
+ def test_is_empty
215
+ geom1_ = @factory.collection([@point1, @line1])
216
+ assert(!geom1_.is_empty?)
217
+ geom2_ = @factory.collection([])
218
+ assert(geom2_.is_empty?)
219
+ end
220
+
221
+
222
+ end
223
+
224
+ end
225
+ end
226
+ end