schleyfox-rgeo 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. data/History.rdoc +199 -0
  2. data/README.rdoc +172 -0
  3. data/Spatial_Programming_With_RGeo.rdoc +440 -0
  4. data/Version +1 -0
  5. data/ext/geos_c_impl/extconf.rb +84 -0
  6. data/ext/geos_c_impl/factory.c +468 -0
  7. data/ext/geos_c_impl/factory.h +224 -0
  8. data/ext/geos_c_impl/geometry.c +705 -0
  9. data/ext/geos_c_impl/geometry.h +55 -0
  10. data/ext/geos_c_impl/geometry_collection.c +482 -0
  11. data/ext/geos_c_impl/geometry_collection.h +69 -0
  12. data/ext/geos_c_impl/line_string.c +509 -0
  13. data/ext/geos_c_impl/line_string.h +64 -0
  14. data/ext/geos_c_impl/main.c +70 -0
  15. data/ext/geos_c_impl/point.c +193 -0
  16. data/ext/geos_c_impl/point.h +62 -0
  17. data/ext/geos_c_impl/polygon.c +265 -0
  18. data/ext/geos_c_impl/polygon.h +66 -0
  19. data/ext/geos_c_impl/preface.h +50 -0
  20. data/ext/proj4_c_impl/extconf.rb +88 -0
  21. data/ext/proj4_c_impl/main.c +271 -0
  22. data/lib/rgeo.rb +124 -0
  23. data/lib/rgeo/cartesian.rb +60 -0
  24. data/lib/rgeo/cartesian/analysis.rb +118 -0
  25. data/lib/rgeo/cartesian/bounding_box.rb +337 -0
  26. data/lib/rgeo/cartesian/calculations.rb +161 -0
  27. data/lib/rgeo/cartesian/factory.rb +209 -0
  28. data/lib/rgeo/cartesian/feature_classes.rb +173 -0
  29. data/lib/rgeo/cartesian/feature_methods.rb +106 -0
  30. data/lib/rgeo/cartesian/interface.rb +150 -0
  31. data/lib/rgeo/coord_sys.rb +79 -0
  32. data/lib/rgeo/coord_sys/cs/entities.rb +1524 -0
  33. data/lib/rgeo/coord_sys/cs/factories.rb +208 -0
  34. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +308 -0
  35. data/lib/rgeo/coord_sys/proj4.rb +312 -0
  36. data/lib/rgeo/coord_sys/srs_database/active_record_table.rb +194 -0
  37. data/lib/rgeo/coord_sys/srs_database/interface.rb +165 -0
  38. data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +188 -0
  39. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +108 -0
  40. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +108 -0
  41. data/lib/rgeo/error.rb +63 -0
  42. data/lib/rgeo/feature.rb +88 -0
  43. data/lib/rgeo/feature/curve.rb +156 -0
  44. data/lib/rgeo/feature/factory.rb +332 -0
  45. data/lib/rgeo/feature/factory_generator.rb +138 -0
  46. data/lib/rgeo/feature/geometry.rb +614 -0
  47. data/lib/rgeo/feature/geometry_collection.rb +129 -0
  48. data/lib/rgeo/feature/line.rb +66 -0
  49. data/lib/rgeo/feature/line_string.rb +102 -0
  50. data/lib/rgeo/feature/linear_ring.rb +66 -0
  51. data/lib/rgeo/feature/multi_curve.rb +113 -0
  52. data/lib/rgeo/feature/multi_line_string.rb +66 -0
  53. data/lib/rgeo/feature/multi_point.rb +73 -0
  54. data/lib/rgeo/feature/multi_polygon.rb +97 -0
  55. data/lib/rgeo/feature/multi_surface.rb +116 -0
  56. data/lib/rgeo/feature/point.rb +120 -0
  57. data/lib/rgeo/feature/polygon.rb +141 -0
  58. data/lib/rgeo/feature/surface.rb +122 -0
  59. data/lib/rgeo/feature/types.rb +305 -0
  60. data/lib/rgeo/geographic.rb +75 -0
  61. data/lib/rgeo/geographic/factory.rb +287 -0
  62. data/lib/rgeo/geographic/interface.rb +410 -0
  63. data/lib/rgeo/geographic/proj4_projector.rb +98 -0
  64. data/lib/rgeo/geographic/projected_feature_classes.rb +213 -0
  65. data/lib/rgeo/geographic/projected_feature_methods.rb +228 -0
  66. data/lib/rgeo/geographic/projected_window.rb +467 -0
  67. data/lib/rgeo/geographic/simple_mercator_projector.rb +157 -0
  68. data/lib/rgeo/geographic/spherical_feature_classes.rb +212 -0
  69. data/lib/rgeo/geographic/spherical_feature_methods.rb +97 -0
  70. data/lib/rgeo/geographic/spherical_math.rb +206 -0
  71. data/lib/rgeo/geos.rb +72 -0
  72. data/lib/rgeo/geos/factory.rb +301 -0
  73. data/lib/rgeo/geos/impl_additions.rb +76 -0
  74. data/lib/rgeo/geos/interface.rb +139 -0
  75. data/lib/rgeo/geos/zm_factory.rb +275 -0
  76. data/lib/rgeo/geos/zm_impl.rb +432 -0
  77. data/lib/rgeo/impl_helper.rb +53 -0
  78. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +235 -0
  79. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +85 -0
  80. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +197 -0
  81. data/lib/rgeo/impl_helper/basic_point_methods.rb +138 -0
  82. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +121 -0
  83. data/lib/rgeo/impl_helper/math.rb +50 -0
  84. data/lib/rgeo/version.rb +52 -0
  85. data/lib/rgeo/wkrep.rb +72 -0
  86. data/lib/rgeo/wkrep/wkb_generator.rb +267 -0
  87. data/lib/rgeo/wkrep/wkb_parser.rb +315 -0
  88. data/lib/rgeo/wkrep/wkt_generator.rb +275 -0
  89. data/lib/rgeo/wkrep/wkt_parser.rb +496 -0
  90. data/test/common/geometry_collection_tests.rb +238 -0
  91. data/test/common/line_string_tests.rb +324 -0
  92. data/test/common/multi_line_string_tests.rb +209 -0
  93. data/test/common/multi_point_tests.rb +201 -0
  94. data/test/common/multi_polygon_tests.rb +208 -0
  95. data/test/common/point_tests.rb +331 -0
  96. data/test/common/polygon_tests.rb +232 -0
  97. data/test/coord_sys/tc_active_record_table.rb +102 -0
  98. data/test/coord_sys/tc_ogc_cs.rb +356 -0
  99. data/test/coord_sys/tc_proj4.rb +138 -0
  100. data/test/coord_sys/tc_proj4_srs_data.rb +76 -0
  101. data/test/coord_sys/tc_sr_org.rb +70 -0
  102. data/test/coord_sys/tc_url_reader.rb +82 -0
  103. data/test/geos/tc_factory.rb +91 -0
  104. data/test/geos/tc_geometry_collection.rb +62 -0
  105. data/test/geos/tc_line_string.rb +62 -0
  106. data/test/geos/tc_misc.rb +72 -0
  107. data/test/geos/tc_multi_line_string.rb +62 -0
  108. data/test/geos/tc_multi_point.rb +62 -0
  109. data/test/geos/tc_multi_polygon.rb +63 -0
  110. data/test/geos/tc_point.rb +86 -0
  111. data/test/geos/tc_polygon.rb +86 -0
  112. data/test/geos/tc_zmfactory.rb +85 -0
  113. data/test/projected_geographic/tc_geometry_collection.rb +62 -0
  114. data/test/projected_geographic/tc_line_string.rb +62 -0
  115. data/test/projected_geographic/tc_multi_line_string.rb +62 -0
  116. data/test/projected_geographic/tc_multi_point.rb +62 -0
  117. data/test/projected_geographic/tc_multi_polygon.rb +63 -0
  118. data/test/projected_geographic/tc_point.rb +93 -0
  119. data/test/projected_geographic/tc_polygon.rb +62 -0
  120. data/test/simple_cartesian/tc_calculations.rb +145 -0
  121. data/test/simple_cartesian/tc_geometry_collection.rb +69 -0
  122. data/test/simple_cartesian/tc_line_string.rb +70 -0
  123. data/test/simple_cartesian/tc_multi_line_string.rb +67 -0
  124. data/test/simple_cartesian/tc_multi_point.rb +67 -0
  125. data/test/simple_cartesian/tc_multi_polygon.rb +70 -0
  126. data/test/simple_cartesian/tc_point.rb +91 -0
  127. data/test/simple_cartesian/tc_polygon.rb +67 -0
  128. data/test/simple_mercator/tc_geometry_collection.rb +62 -0
  129. data/test/simple_mercator/tc_line_string.rb +62 -0
  130. data/test/simple_mercator/tc_multi_line_string.rb +62 -0
  131. data/test/simple_mercator/tc_multi_point.rb +62 -0
  132. data/test/simple_mercator/tc_multi_polygon.rb +63 -0
  133. data/test/simple_mercator/tc_point.rb +93 -0
  134. data/test/simple_mercator/tc_polygon.rb +62 -0
  135. data/test/simple_mercator/tc_window.rb +219 -0
  136. data/test/spherical_geographic/tc_calculations.rb +203 -0
  137. data/test/spherical_geographic/tc_geometry_collection.rb +70 -0
  138. data/test/spherical_geographic/tc_line_string.rb +70 -0
  139. data/test/spherical_geographic/tc_multi_line_string.rb +67 -0
  140. data/test/spherical_geographic/tc_multi_point.rb +67 -0
  141. data/test/spherical_geographic/tc_multi_polygon.rb +70 -0
  142. data/test/spherical_geographic/tc_point.rb +100 -0
  143. data/test/spherical_geographic/tc_polygon.rb +67 -0
  144. data/test/tc_cartesian_analysis.rb +107 -0
  145. data/test/tc_oneoff.rb +63 -0
  146. data/test/wkrep/tc_wkb_generator.rb +249 -0
  147. data/test/wkrep/tc_wkb_parser.rb +353 -0
  148. data/test/wkrep/tc_wkt_generator.rb +362 -0
  149. data/test/wkrep/tc_wkt_parser.rb +480 -0
  150. metadata +267 -0
@@ -0,0 +1,209 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Common tests for multi line string implementations
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 'rgeo'
38
+
39
+
40
+ module RGeo
41
+ module Tests # :nodoc:
42
+ module Common # :nodoc:
43
+
44
+ module MultiLineStringTests # :nodoc:
45
+
46
+
47
+ def setup
48
+ @factory = create_factory
49
+ point1_ = @factory.point(0, 0)
50
+ point2_ = @factory.point(1, 0)
51
+ point3_ = @factory.point(-4, 2)
52
+ point4_ = @factory.point(-5, 3)
53
+ point5_ = @factory.point(-3, 5)
54
+ @linestring1 = @factory.line_string([point1_, point2_])
55
+ @linestring2 = @factory.line_string([point3_, point4_, point5_])
56
+ @linearring1 = @factory.linear_ring([point5_, point3_, point4_, point5_])
57
+ @line1 = @factory.line(point1_, point2_)
58
+ end
59
+
60
+
61
+ def test_creation_simple
62
+ geom_ = @factory.multi_line_string([@linestring1, @linestring2])
63
+ assert_not_nil(geom_)
64
+ assert(::RGeo::Feature::MultiLineString === geom_)
65
+ assert_equal(::RGeo::Feature::MultiLineString, geom_.geometry_type)
66
+ assert_equal(2, geom_.num_geometries)
67
+ assert(@linestring1.eql?(geom_[0]))
68
+ assert(@linestring2.eql?(geom_[1]))
69
+ end
70
+
71
+
72
+ def test_creation_empty
73
+ geom_ = @factory.multi_line_string([])
74
+ assert_not_nil(geom_)
75
+ assert(::RGeo::Feature::MultiLineString === geom_)
76
+ assert_equal(::RGeo::Feature::MultiLineString, 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_types
83
+ geom_ = @factory.multi_line_string([@linestring1, @linearring1, @line1])
84
+ assert_not_nil(geom_)
85
+ assert(::RGeo::Feature::MultiLineString === geom_)
86
+ assert_equal(::RGeo::Feature::MultiLineString, geom_.geometry_type)
87
+ assert_equal(3, geom_.num_geometries)
88
+ assert(geom_[1].eql?(@linearring1))
89
+ assert(geom_[2].eql?(@line1))
90
+ end
91
+
92
+
93
+ def test_creation_casting
94
+ mls1_ = @factory.collection([@line1])
95
+ mls2_ = @factory.multi_line_string([@linearring1])
96
+ geom_ = @factory.multi_line_string([@linestring1, @linestring2, mls1_, mls2_])
97
+ assert_not_nil(geom_)
98
+ assert_equal(::RGeo::Feature::MultiLineString, geom_.geometry_type)
99
+ assert_equal(4, geom_.num_geometries)
100
+ assert(@linestring1.eql?(geom_[0]))
101
+ assert(@linestring2.eql?(geom_[1]))
102
+ assert(@line1.eql?(geom_[2]))
103
+ assert(@linearring1.eql?(geom_[3]))
104
+ end
105
+
106
+
107
+ def test_fully_equal
108
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2])
109
+ geom2_ = @factory.multi_line_string([@linestring1, @linestring2])
110
+ assert(geom1_.eql?(geom2_))
111
+ assert(geom1_.equals?(geom2_))
112
+ end
113
+
114
+
115
+ def test_geometrically_equal
116
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2, @linearring1])
117
+ geom2_ = @factory.multi_line_string([@line1, @linearring1])
118
+ assert(!geom1_.eql?(geom2_))
119
+ assert(geom1_.equals?(geom2_))
120
+ end
121
+
122
+
123
+ def test_not_equal
124
+ geom1_ = @factory.multi_line_string([@linestring2])
125
+ geom2_ = @factory.multi_line_string([@linearring1])
126
+ assert(!geom1_.eql?(geom2_))
127
+ assert(!geom1_.equals?(geom2_))
128
+ end
129
+
130
+
131
+ def test_wkt_creation_simple
132
+ parsed_geom_ = @factory.parse_wkt('MULTILINESTRING((0 0, 1 0), (-4 2, -5 3, -3 5))')
133
+ built_geom_ = @factory.multi_line_string([@linestring1, @linestring2])
134
+ assert(built_geom_.eql?(parsed_geom_))
135
+ end
136
+
137
+
138
+ def test_wkt_creation_empty
139
+ parsed_geom_ = @factory.parse_wkt('MULTILINESTRING EMPTY')
140
+ assert_equal(::RGeo::Feature::MultiLineString, parsed_geom_.geometry_type)
141
+ assert_equal(0, parsed_geom_.num_geometries)
142
+ assert_equal([], parsed_geom_.to_a)
143
+ end
144
+
145
+
146
+ def test_clone
147
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2])
148
+ geom2_ = geom1_.clone
149
+ assert(geom1_.eql?(geom2_))
150
+ assert_equal(::RGeo::Feature::MultiLineString, geom2_.geometry_type)
151
+ assert_equal(2, geom2_.num_geometries)
152
+ assert(@linestring1.eql?(geom2_[0]))
153
+ assert(@linestring2.eql?(geom2_[1]))
154
+ end
155
+
156
+
157
+ def test_type_check
158
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2])
159
+ assert(::RGeo::Feature::Geometry.check_type(geom1_))
160
+ assert(!::RGeo::Feature::LineString.check_type(geom1_))
161
+ assert(::RGeo::Feature::GeometryCollection.check_type(geom1_))
162
+ assert(!::RGeo::Feature::MultiPoint.check_type(geom1_))
163
+ assert(::RGeo::Feature::MultiLineString.check_type(geom1_))
164
+ geom2_ = @factory.multi_line_string([])
165
+ assert(::RGeo::Feature::Geometry.check_type(geom2_))
166
+ assert(!::RGeo::Feature::LineString.check_type(geom2_))
167
+ assert(::RGeo::Feature::GeometryCollection.check_type(geom2_))
168
+ assert(!::RGeo::Feature::MultiPoint.check_type(geom2_))
169
+ assert(::RGeo::Feature::MultiLineString.check_type(geom2_))
170
+ end
171
+
172
+
173
+ def test_as_text_wkt_round_trip
174
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2])
175
+ text_ = geom1_.as_text
176
+ geom2_ = @factory.parse_wkt(text_)
177
+ assert(geom1_.eql?(geom2_))
178
+ end
179
+
180
+
181
+ def test_as_binary_wkb_round_trip
182
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2])
183
+ binary_ = geom1_.as_binary
184
+ geom2_ = @factory.parse_wkb(binary_)
185
+ assert(geom1_.eql?(geom2_))
186
+ end
187
+
188
+
189
+ def test_dimension
190
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2])
191
+ assert_equal(1, geom1_.dimension)
192
+ geom2_ = @factory.multi_line_string([])
193
+ assert_equal(-1, geom2_.dimension)
194
+ end
195
+
196
+
197
+ def test_is_empty
198
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2])
199
+ assert(!geom1_.is_empty?)
200
+ geom2_ = @factory.multi_line_string([])
201
+ assert(geom2_.is_empty?)
202
+ end
203
+
204
+
205
+ end
206
+
207
+ end
208
+ end
209
+ end
@@ -0,0 +1,201 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Common tests for multi point implementations
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 'rgeo'
38
+
39
+
40
+ module RGeo
41
+ module Tests # :nodoc:
42
+ module Common # :nodoc:
43
+
44
+ module MultiPointTests # :nodoc:
45
+
46
+
47
+ def setup
48
+ @factory = create_factory
49
+ @point1 = @factory.point(0, 0)
50
+ @point2 = @factory.point(1, 0)
51
+ @point3 = @factory.point(-4, 2)
52
+ @point4 = @factory.point(-5, 3)
53
+ @point5 = @factory.point(-5, 3)
54
+ end
55
+
56
+
57
+ def test_creation_simple
58
+ geom_ = @factory.multi_point([@point1, @point2])
59
+ assert_not_nil(geom_)
60
+ assert(::RGeo::Feature::MultiPoint === geom_)
61
+ assert_equal(::RGeo::Feature::MultiPoint, geom_.geometry_type)
62
+ assert_equal(2, geom_.num_geometries)
63
+ assert(@point1.eql?(geom_[0]))
64
+ assert(@point2.eql?(geom_[1]))
65
+ end
66
+
67
+
68
+ def test_creation_empty
69
+ geom_ = @factory.multi_point([])
70
+ assert_not_nil(geom_)
71
+ assert(::RGeo::Feature::MultiPoint === geom_)
72
+ assert_equal(::RGeo::Feature::MultiPoint, geom_.geometry_type)
73
+ assert_equal(0, geom_.num_geometries)
74
+ assert_equal([], geom_.to_a)
75
+ end
76
+
77
+
78
+ def test_creation_casting
79
+ mp1_ = @factory.collection([@point3])
80
+ mp2_ = @factory.multi_point([@point4])
81
+ geom_ = @factory.multi_point([@point1, @point2, mp1_, mp2_])
82
+ assert_not_nil(geom_)
83
+ assert_equal(::RGeo::Feature::MultiPoint, geom_.geometry_type)
84
+ assert_equal(4, geom_.num_geometries)
85
+ assert(@point1.eql?(geom_[0]))
86
+ assert(@point2.eql?(geom_[1]))
87
+ assert(@point3.eql?(geom_[2]))
88
+ assert(@point4.eql?(geom_[3]))
89
+ end
90
+
91
+
92
+ def test_creation_wrong_type
93
+ line_ = @factory.line_string([@point1, @point2])
94
+ geom_ = @factory.multi_point([@point3, line_])
95
+ assert_nil(geom_)
96
+ end
97
+
98
+
99
+ def test_fully_equal
100
+ geom1_ = @factory.multi_point([@point1, @point2])
101
+ geom2_ = @factory.multi_point([@point1, @point2])
102
+ assert(geom1_.eql?(geom2_))
103
+ assert(geom1_.equals?(geom2_))
104
+ end
105
+
106
+
107
+ def test_geometrically_equal
108
+ geom1_ = @factory.multi_point([@point1, @point4])
109
+ geom2_ = @factory.multi_point([@point1, @point4, @point5])
110
+ assert(!geom1_.eql?(geom2_))
111
+ assert(geom1_.equals?(geom2_))
112
+ end
113
+
114
+
115
+ def test_not_equal
116
+ geom1_ = @factory.multi_point([@point1, @point2])
117
+ geom2_ = @factory.multi_point([@point1])
118
+ assert(!geom1_.eql?(geom2_))
119
+ assert(!geom1_.equals?(geom2_))
120
+ end
121
+
122
+
123
+ def test_wkt_creation_simple
124
+ parsed_geom_ = @factory.parse_wkt('MULTIPOINT((0 0), (-4 2), (-5 3))')
125
+ built_geom_ = @factory.multi_point([@point1, @point3, @point4])
126
+ assert(built_geom_.eql?(parsed_geom_))
127
+ end
128
+
129
+
130
+ def test_wkt_creation_empty
131
+ parsed_geom_ = @factory.parse_wkt('MULTIPOINT EMPTY')
132
+ assert(::RGeo::Feature::MultiPoint === parsed_geom_)
133
+ assert_equal(0, parsed_geom_.num_geometries)
134
+ assert_equal([], parsed_geom_.to_a)
135
+ end
136
+
137
+
138
+ def test_clone
139
+ geom1_ = @factory.multi_point([@point1, @point2])
140
+ geom2_ = geom1_.clone
141
+ assert(geom1_.eql?(geom2_))
142
+ assert_equal(::RGeo::Feature::MultiPoint, geom2_.geometry_type)
143
+ assert_equal(2, geom2_.num_geometries)
144
+ assert(@point1.eql?(geom2_[0]))
145
+ assert(@point2.eql?(geom2_[1]))
146
+ end
147
+
148
+
149
+ def test_type_check
150
+ geom1_ = @factory.multi_point([@point1, @point2])
151
+ assert(::RGeo::Feature::Geometry.check_type(geom1_))
152
+ assert(!::RGeo::Feature::Point.check_type(geom1_))
153
+ assert(::RGeo::Feature::GeometryCollection.check_type(geom1_))
154
+ assert(::RGeo::Feature::MultiPoint.check_type(geom1_))
155
+ assert(!::RGeo::Feature::MultiLineString.check_type(geom1_))
156
+ geom2_ = @factory.multi_point([])
157
+ assert(::RGeo::Feature::Geometry.check_type(geom2_))
158
+ assert(!::RGeo::Feature::Point.check_type(geom2_))
159
+ assert(::RGeo::Feature::GeometryCollection.check_type(geom2_))
160
+ assert(::RGeo::Feature::MultiPoint.check_type(geom2_))
161
+ assert(!::RGeo::Feature::MultiLineString.check_type(geom2_))
162
+ end
163
+
164
+
165
+ def test_as_text_wkt_round_trip
166
+ geom1_ = @factory.multi_point([@point1, @point2])
167
+ text_ = geom1_.as_text
168
+ geom2_ = @factory.parse_wkt(text_)
169
+ assert(geom1_.eql?(geom2_))
170
+ end
171
+
172
+
173
+ def test_as_binary_wkb_round_trip
174
+ geom1_ = @factory.multi_point([@point1, @point2])
175
+ binary_ = geom1_.as_binary
176
+ geom2_ = @factory.parse_wkb(binary_)
177
+ assert(geom1_.eql?(geom2_))
178
+ end
179
+
180
+
181
+ def test_dimension
182
+ geom1_ = @factory.multi_point([@point1, @point2])
183
+ assert_equal(0, geom1_.dimension)
184
+ geom2_ = @factory.multi_point([])
185
+ assert_equal(-1, geom2_.dimension)
186
+ end
187
+
188
+
189
+ def test_is_empty
190
+ geom1_ = @factory.multi_point([@point1, @point2])
191
+ assert(!geom1_.is_empty?)
192
+ geom2_ = @factory.multi_point([])
193
+ assert(geom2_.is_empty?)
194
+ end
195
+
196
+
197
+ end
198
+
199
+ end
200
+ end
201
+ end
@@ -0,0 +1,208 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Common tests for multi polygon implementations
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 'rgeo'
38
+
39
+
40
+ module RGeo
41
+ module Tests # :nodoc:
42
+ module Common # :nodoc:
43
+
44
+ module MultiPolygonTests # :nodoc:
45
+
46
+
47
+ def setup
48
+ create_factories
49
+ point1_ = @factory.point(0, 0)
50
+ point2_ = @factory.point(0, 10)
51
+ point3_ = @factory.point(10, 10)
52
+ point4_ = @factory.point(10, 0)
53
+ point5_ = @factory.point(4, 4)
54
+ point6_ = @factory.point(5, 6)
55
+ point7_ = @factory.point(6, 4)
56
+ point8_ = @factory.point(0, -10)
57
+ point9_ = @factory.point(-10, 0)
58
+ exterior1_ = @factory.linear_ring([point1_, point8_, point9_, point1_])
59
+ exterior2_ = @factory.linear_ring([point1_, point2_, point3_, point4_, point1_])
60
+ exterior3_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
61
+ exterior4_ = @factory.linear_ring([point1_, point3_, point4_, point1_])
62
+ interior1_ = @factory.linear_ring([point5_, point6_, point7_, point5_])
63
+ @poly1 = @factory.polygon(exterior1_)
64
+ @poly2 = @factory.polygon(exterior2_, [interior1_])
65
+ @poly3 = @factory.polygon(exterior3_)
66
+ @poly4 = @factory.polygon(exterior4_)
67
+ @line1 = interior1_
68
+ end
69
+
70
+
71
+ def test_creation_simple
72
+ geom_ = @factory.multi_polygon([@poly1, @poly2])
73
+ assert_not_nil(geom_)
74
+ assert(::RGeo::Feature::MultiPolygon === geom_)
75
+ assert_equal(::RGeo::Feature::MultiPolygon, geom_.geometry_type)
76
+ assert_equal(2, geom_.num_geometries)
77
+ assert(@poly1.eql?(geom_[0]))
78
+ assert(@poly2.eql?(geom_[1]))
79
+ end
80
+
81
+
82
+ def test_creation_empty
83
+ geom_ = @factory.multi_polygon([])
84
+ assert_not_nil(geom_)
85
+ assert(::RGeo::Feature::MultiPolygon === geom_)
86
+ assert_equal(::RGeo::Feature::MultiPolygon, geom_.geometry_type)
87
+ assert_equal(0, geom_.num_geometries)
88
+ assert_equal([], geom_.to_a)
89
+ end
90
+
91
+
92
+ def test_creation_wrong_type
93
+ geom_ = @factory.multi_polygon([@poly1, @line1])
94
+ assert_nil(geom_)
95
+ end
96
+
97
+
98
+ def test_creation_overlapping
99
+ geom_ = @factory.multi_polygon([@poly1, @poly1])
100
+ assert_nil(geom_)
101
+ geom2_ = @lenient_factory.multi_polygon([@poly1, @poly1])
102
+ assert_not_nil(geom2_)
103
+ end
104
+
105
+
106
+ def test_creation_connected
107
+ geom_ = @factory.multi_polygon([@poly3, @poly4])
108
+ assert_nil(geom_)
109
+ geom2_ = @lenient_factory.multi_polygon([@poly3, @poly4])
110
+ assert_not_nil(geom2_)
111
+ end
112
+
113
+
114
+ def test_equal
115
+ geom1_ = @factory.multi_polygon([@poly1, @poly2])
116
+ geom2_ = @factory.multi_polygon([@poly1, @poly2])
117
+ assert(geom1_.eql?(geom2_))
118
+ assert(geom1_.equals?(geom2_))
119
+ end
120
+
121
+
122
+ def test_not_equal
123
+ geom1_ = @factory.multi_polygon([@poly1])
124
+ geom2_ = @factory.multi_polygon([@poly2])
125
+ assert(!geom1_.eql?(geom2_))
126
+ assert(!geom1_.equals?(geom2_))
127
+ end
128
+
129
+
130
+ def test_wkt_creation_simple
131
+ parsed_geom_ = @factory.parse_wkt('MULTIPOLYGON(((0 0, 0 -10, -10 0, 0 0)), ((0 0, 0 10, 10 10, 10 0, 0 0), (4 4, 5 6, 6 4, 4 4)))')
132
+ built_geom_ = @factory.multi_polygon([@poly1, @poly2])
133
+ assert(built_geom_.eql?(parsed_geom_))
134
+ end
135
+
136
+
137
+ def test_wkt_creation_empty
138
+ parsed_geom_ = @factory.parse_wkt('MULTIPOLYGON EMPTY')
139
+ assert_equal(::RGeo::Feature::MultiPolygon, parsed_geom_.geometry_type)
140
+ assert_equal(0, parsed_geom_.num_geometries)
141
+ assert_equal([], parsed_geom_.to_a)
142
+ end
143
+
144
+
145
+ def test_clone
146
+ geom1_ = @factory.multi_polygon([@poly1, @poly2])
147
+ geom2_ = geom1_.clone
148
+ assert(geom1_.eql?(geom2_))
149
+ assert_equal(::RGeo::Feature::MultiPolygon, geom2_.geometry_type)
150
+ assert_equal(2, geom2_.num_geometries)
151
+ assert(@poly1.eql?(geom2_[0]))
152
+ assert(@poly2.eql?(geom2_[1]))
153
+ end
154
+
155
+
156
+ def test_type_check
157
+ geom1_ = @factory.multi_polygon([@poly1, @poly2])
158
+ assert(::RGeo::Feature::Geometry.check_type(geom1_))
159
+ assert(!::RGeo::Feature::Polygon.check_type(geom1_))
160
+ assert(::RGeo::Feature::GeometryCollection.check_type(geom1_))
161
+ assert(!::RGeo::Feature::MultiPoint.check_type(geom1_))
162
+ assert(::RGeo::Feature::MultiPolygon.check_type(geom1_))
163
+ geom2_ = @factory.multi_polygon([])
164
+ assert(::RGeo::Feature::Geometry.check_type(geom2_))
165
+ assert(!::RGeo::Feature::Polygon.check_type(geom2_))
166
+ assert(::RGeo::Feature::GeometryCollection.check_type(geom2_))
167
+ assert(!::RGeo::Feature::MultiPoint.check_type(geom2_))
168
+ assert(::RGeo::Feature::MultiPolygon.check_type(geom2_))
169
+ end
170
+
171
+
172
+ def test_as_text_wkt_round_trip
173
+ geom1_ = @factory.multi_polygon([@poly1, @poly2])
174
+ text_ = geom1_.as_text
175
+ geom2_ = @factory.parse_wkt(text_)
176
+ assert(geom1_.eql?(geom2_))
177
+ end
178
+
179
+
180
+ def test_as_binary_wkb_round_trip
181
+ geom1_ = @factory.multi_polygon([@poly1, @poly2])
182
+ binary_ = geom1_.as_binary
183
+ geom2_ = @factory.parse_wkb(binary_)
184
+ assert(geom1_.eql?(geom2_))
185
+ end
186
+
187
+
188
+ def test_dimension
189
+ geom1_ = @factory.multi_polygon([@poly1, @poly2])
190
+ assert_equal(2, geom1_.dimension)
191
+ geom2_ = @factory.multi_polygon([])
192
+ assert_equal(-1, geom2_.dimension)
193
+ end
194
+
195
+
196
+ def test_is_empty
197
+ geom1_ = @factory.multi_polygon([@poly1, @poly2])
198
+ assert(!geom1_.is_empty?)
199
+ geom2_ = @factory.multi_polygon([])
200
+ assert(geom2_.is_empty?)
201
+ end
202
+
203
+
204
+ end
205
+
206
+ end
207
+ end
208
+ end