rgeo 0.1.10

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.
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,219 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Tests for the simple mercator window 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 SimpleMercator
44
+
45
+ class TestWindow < ::Test::Unit::TestCase # :nodoc:
46
+
47
+
48
+ def setup
49
+ @factory = ::RGeo::Geography.simple_mercator
50
+ end
51
+
52
+
53
+ def assert_close_enough(p1_, p2_)
54
+ assert((p1_.x - p2_.x).abs < 0.00001 && (p1_.y - p2_.y).abs < 0.00001)
55
+ end
56
+
57
+
58
+ def assert_contains_approx(p_, mp_)
59
+ assert(mp_.any?{ |q_| (p_.x - q_.x).abs < 0.00001 && (p_.y - q_.y).abs < 0.00001 })
60
+ end
61
+
62
+
63
+ def test_limits
64
+ limits_ = @factory.projection_limits_window
65
+ assert_in_delta(-20037508, limits_.x_min, 1)
66
+ assert_in_delta(-20037508, limits_.y_min, 1)
67
+ assert_in_delta(20037508, limits_.x_max, 1)
68
+ assert_in_delta(20037508, limits_.y_max, 1)
69
+ end
70
+
71
+
72
+ def test_limits_unprojected
73
+ limits_ = @factory.projection_limits_window
74
+ assert_close_enough(@factory.point(-180, -85.051129), limits_.sw_point)
75
+ assert_close_enough(@factory.point(180, -85.051129), limits_.se_point)
76
+ assert_close_enough(@factory.point(-180, 85.051129), limits_.nw_point)
77
+ assert_close_enough(@factory.point(180, 85.051129), limits_.ne_point)
78
+ assert_close_enough(@factory.point(0, 0), limits_.center_point)
79
+ end
80
+
81
+
82
+ def test_center_point
83
+ window1_ = Geography::ProjectedWindow.for_corners(@factory.point(-160, -30), @factory.point(170, 30))
84
+ assert_close_enough(@factory.point(5, 0), window1_.center_point)
85
+ window2_ = Geography::ProjectedWindow.for_corners(@factory.point(160, -30), @factory.point(-170, 30))
86
+ assert_close_enough(@factory.point(175, 0), window2_.center_point)
87
+ end
88
+
89
+
90
+ def test_crosses_seam
91
+ window1_ = Geography::ProjectedWindow.for_corners(@factory.point(-170, 30), @factory.point(170, 40))
92
+ assert(!window1_.crosses_seam?)
93
+ window2_ = Geography::ProjectedWindow.for_corners(@factory.point(170, 30), @factory.point(-170, 40))
94
+ assert(window2_.crosses_seam?)
95
+ end
96
+
97
+
98
+ def test_degenerate
99
+ window1_ = Geography::ProjectedWindow.for_corners(@factory.point(-20, 30), @factory.point(-10, 40))
100
+ assert(!window1_.degenerate?)
101
+ window2_ = Geography::ProjectedWindow.for_corners(@factory.point(-20, 30), @factory.point(-20, 40))
102
+ assert(window2_.degenerate?)
103
+ window3_ = Geography::ProjectedWindow.for_corners(@factory.point(-20, 30), @factory.point(-10, 30))
104
+ assert(window3_.degenerate?)
105
+ end
106
+
107
+
108
+ def test_contains_point
109
+ window1_ = Geography::ProjectedWindow.for_corners(@factory.point(-170, 30), @factory.point(-160, 40))
110
+ window2_ = Geography::ProjectedWindow.for_corners(@factory.point(170, 30), @factory.point(-170, 40))
111
+ point1_ = @factory.point(-169, 32)
112
+ point2_ = @factory.point(-171, 32)
113
+ point3_ = @factory.point(-169, 29)
114
+ point4_ = @factory.point(171, 32)
115
+ point5_ = @factory.point(169, 32)
116
+ assert(window1_.contains_point?(point1_))
117
+ assert(!window1_.contains_point?(point2_))
118
+ assert(!window1_.contains_point?(point3_))
119
+ assert(!window2_.contains_point?(point1_))
120
+ assert(window2_.contains_point?(point2_))
121
+ assert(window2_.contains_point?(point4_))
122
+ assert(!window2_.contains_point?(point5_))
123
+ end
124
+
125
+
126
+ def test_noseam_contains_window
127
+ window1_ = Geography::ProjectedWindow.for_corners(@factory.point(10, 10), @factory.point(30, 30))
128
+ assert(window1_.contains_window?(Geography::ProjectedWindow.for_corners(@factory.point(15, 15), @factory.point(25, 25))))
129
+
130
+ assert(!window1_.contains_window?(Geography::ProjectedWindow.for_corners(@factory.point(5, 15), @factory.point(25, 25))))
131
+ assert(!window1_.contains_window?(Geography::ProjectedWindow.for_corners(@factory.point(15, 15), @factory.point(35, 25))))
132
+ assert(!window1_.contains_window?(Geography::ProjectedWindow.for_corners(@factory.point(0, 15), @factory.point(5, 25))))
133
+ assert(!window1_.contains_window?(Geography::ProjectedWindow.for_corners(@factory.point(35, 15), @factory.point(40, 25))))
134
+ assert(!window1_.contains_window?(Geography::ProjectedWindow.for_corners(@factory.point(5, 15), @factory.point(35, 25))))
135
+
136
+ assert(!window1_.contains_window?(Geography::ProjectedWindow.for_corners(@factory.point(15, 5), @factory.point(25, 25))))
137
+ assert(!window1_.contains_window?(Geography::ProjectedWindow.for_corners(@factory.point(15, 15), @factory.point(25, 35))))
138
+ assert(!window1_.contains_window?(Geography::ProjectedWindow.for_corners(@factory.point(15, 0), @factory.point(25, 5))))
139
+ assert(!window1_.contains_window?(Geography::ProjectedWindow.for_corners(@factory.point(15, 35), @factory.point(25, 40))))
140
+ assert(!window1_.contains_window?(Geography::ProjectedWindow.for_corners(@factory.point(15, 5), @factory.point(25, 35))))
141
+
142
+ assert(!window1_.contains_window?(Geography::ProjectedWindow.for_corners(@factory.point(170, 35), @factory.point(-170, 40))))
143
+ end
144
+
145
+
146
+ def test_seam_contains_window
147
+ window1_ = Geography::ProjectedWindow.for_corners(@factory.point(160, 10), @factory.point(-160, 30))
148
+ assert(window1_.contains_window?(Geography::ProjectedWindow.for_corners(@factory.point(175, 15), @factory.point(-175, 25))))
149
+ assert(window1_.contains_window?(Geography::ProjectedWindow.for_corners(@factory.point(170, 15), @factory.point(175, 25))))
150
+ assert(window1_.contains_window?(Geography::ProjectedWindow.for_corners(@factory.point(-175, 15), @factory.point(-170, 25))))
151
+
152
+ assert(!window1_.contains_window?(Geography::ProjectedWindow.for_corners(@factory.point(150, 15), @factory.point(170, 25))))
153
+ assert(!window1_.contains_window?(Geography::ProjectedWindow.for_corners(@factory.point(150, 15), @factory.point(-170, 25))))
154
+ assert(!window1_.contains_window?(Geography::ProjectedWindow.for_corners(@factory.point(-170, 15), @factory.point(-150, 25))))
155
+ assert(!window1_.contains_window?(Geography::ProjectedWindow.for_corners(@factory.point(170, 15), @factory.point(-150, 25))))
156
+
157
+ assert(!window1_.contains_window?(Geography::ProjectedWindow.for_corners(@factory.point(-150, 15), @factory.point(150, 25))))
158
+ assert(!window1_.contains_window?(Geography::ProjectedWindow.for_corners(@factory.point(150, 15), @factory.point(-150, 25))))
159
+ end
160
+
161
+
162
+ def test_scaled_by
163
+ window1_ = Geography::ProjectedWindow.for_corners(@factory.point(20, -20), @factory.point(50, 40))
164
+ window1s_ = window1_.scaled_by(2, 1.5)
165
+ assert(window1s_.contains_point?(@factory.point(10, -25)))
166
+ assert(window1s_.contains_point?(@factory.point(60, 45)))
167
+ assert(!window1s_.contains_point?(@factory.point(0, -25)))
168
+ assert(!window1s_.contains_point?(@factory.point(10, -35)))
169
+ end
170
+
171
+
172
+ def test_scaled_by_across_seam
173
+ window1_ = Geography::ProjectedWindow.for_corners(@factory.point(170, -20), @factory.point(-160, 40))
174
+ window1s_ = window1_.scaled_by(2, 1.5)
175
+ assert(window1s_.contains_point?(@factory.point(160, -25)))
176
+ assert(window1s_.contains_point?(@factory.point(-150, 45)))
177
+ assert(!window1s_.contains_point?(@factory.point(150, -25)))
178
+ assert(!window1s_.contains_point?(@factory.point(-140, 45)))
179
+ end
180
+
181
+
182
+ def test_surrounding_point
183
+ window1_ = Geography::ProjectedWindow.surrounding_point(@factory.point(20, -20), 1)
184
+ assert(window1_.contains_point?(@factory.point(20, -20)))
185
+ assert(!window1_.contains_point?(@factory.point(20, -21)))
186
+ assert(!window1_.contains_point?(@factory.point(19, -20)))
187
+ end
188
+
189
+
190
+ def test_bounding_1_point
191
+ window1_ = Geography::ProjectedWindow.bounding_points([@factory.point(20, -20)]).with_margin(1)
192
+ assert(window1_.contains_point?(@factory.point(20, -20)))
193
+ assert(!window1_.contains_point?(@factory.point(20, -21)))
194
+ assert(!window1_.contains_point?(@factory.point(19, -20)))
195
+ end
196
+
197
+
198
+ def test_bounding_2_points
199
+ window1_ = Geography::ProjectedWindow.bounding_points([@factory.point(10, 10), @factory.point(30, 30)])
200
+ assert(window1_.contains_point?(@factory.point(20, 20)))
201
+ assert(!window1_.contains_point?(@factory.point(5, 20)))
202
+ assert(!window1_.contains_point?(@factory.point(20, 35)))
203
+ end
204
+
205
+
206
+ def test_bounding_2_points_across_seam
207
+ window1_ = Geography::ProjectedWindow.bounding_points([@factory.point(-170, 10), @factory.point(170, 30)])
208
+ assert(window1_.contains_point?(@factory.point(-174, 20)))
209
+ assert(!window1_.contains_point?(@factory.point(-160, 20)))
210
+ assert(!window1_.contains_point?(@factory.point(160, 20)))
211
+ assert(!window1_.contains_point?(@factory.point(-174, 35)))
212
+ end
213
+
214
+
215
+ end
216
+
217
+ end
218
+ end
219
+ end
@@ -0,0 +1,230 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Tests for basic GeoJSON usage
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
+
44
+ class TestGeoJSON < ::Test::Unit::TestCase # :nodoc:
45
+
46
+
47
+ def setup
48
+ @geo_factory = ::RGeo::Geos.factory(:srid => 4326)
49
+ @entity_factory = ::RGeo::GeoJSON::EntityFactory.instance
50
+ end
51
+
52
+
53
+ def test_point
54
+ object_ = @geo_factory.point(10, 20)
55
+ json_ = {
56
+ 'type' => 'Point',
57
+ 'coordinates' => [10.0, 20.0],
58
+ }
59
+ assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
60
+ assert(::RGeo::GeoJSON.decode(json_, @geo_factory).eql?(object_))
61
+ end
62
+
63
+
64
+ def test_line_string
65
+ object_ = @geo_factory.line_string([@geo_factory.point(10, 20), @geo_factory.point(12, 22), @geo_factory.point(-3, 24)])
66
+ json_ = {
67
+ 'type' => 'LineString',
68
+ 'coordinates' => [[10.0, 20.0], [12.0, 22.0], [-3.0, 24.0]],
69
+ }
70
+ assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
71
+ assert(::RGeo::GeoJSON.decode(json_, @geo_factory).eql?(object_))
72
+ end
73
+
74
+
75
+ def test_polygon
76
+ 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)]))
77
+ json_ = {
78
+ 'type' => 'Polygon',
79
+ 'coordinates' => [[[10.0, 20.0], [12.0, 22.0], [-3.0, 24.0], [10.0, 20.0]]],
80
+ }
81
+ assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
82
+ assert(::RGeo::GeoJSON.decode(json_, @geo_factory).eql?(object_))
83
+ end
84
+
85
+
86
+ def test_polygon_complex
87
+ 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)])])
88
+ json_ = {
89
+ 'type' => 'Polygon',
90
+ 'coordinates' => [[[0.0, 0.0], [10.0, 0.0], [10.0, 10.0], [0.0, 10.0], [0.0, 0.0]], [[4.0, 4.0], [6.0, 5.0], [4.0, 6.0], [4.0, 4.0]]],
91
+ }
92
+ assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
93
+ assert(::RGeo::GeoJSON.decode(json_, @geo_factory).eql?(object_))
94
+ end
95
+
96
+
97
+ def test_multi_point
98
+ object_ = @geo_factory.multi_point([@geo_factory.point(10, 20), @geo_factory.point(12, 22), @geo_factory.point(-3, 24)])
99
+ json_ = {
100
+ 'type' => 'MultiPoint',
101
+ 'coordinates' => [[10.0, 20.0], [12.0, 22.0], [-3.0, 24.0]],
102
+ }
103
+ assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
104
+ assert(::RGeo::GeoJSON.decode(json_, @geo_factory).eql?(object_))
105
+ end
106
+
107
+
108
+ def test_multi_line_string
109
+ 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)])])
110
+ json_ = {
111
+ 'type' => 'MultiLineString',
112
+ 'coordinates' => [[[10.0, 20.0], [12.0, 22.0], [-3.0, 24.0]], [[1.0, 2.0], [3.0, 4.0]]],
113
+ }
114
+ assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
115
+ assert(::RGeo::GeoJSON.decode(json_, @geo_factory).eql?(object_))
116
+ end
117
+
118
+
119
+ def test_multi_polygon
120
+ 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)]))])
121
+ json_ = {
122
+ 'type' => 'MultiPolygon',
123
+ 'coordinates' => [[[[0.0, 0.0], [10.0, 0.0], [10.0, 10.0], [0.0, 10.0], [0.0, 0.0]], [[4.0, 4.0], [6.0, 5.0], [4.0, 6.0], [4.0, 4.0]]], [[[-10.0, -10.0], [-15.0, -10.0], [-10.0, -15.0], [-10.0, -10.0]]]]
124
+ }
125
+ assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
126
+ assert(::RGeo::GeoJSON.decode(json_, @geo_factory).eql?(object_))
127
+ end
128
+
129
+
130
+ def test_geometry_collection
131
+ object_ = @geo_factory.collection([@geo_factory.point(10, 20), @geo_factory.collection([@geo_factory.point(12, 22), @geo_factory.point(-3, 24)])])
132
+ json_ = {
133
+ 'type' => 'GeometryCollection',
134
+ 'geometries' => [
135
+ {
136
+ 'type' => 'Point',
137
+ 'coordinates' => [10.0, 20.0],
138
+ },
139
+ {
140
+ 'type' => 'GeometryCollection',
141
+ 'geometries' => [
142
+ {
143
+ 'type' => 'Point',
144
+ 'coordinates' => [12.0, 22.0],
145
+ },
146
+ {
147
+ 'type' => 'Point',
148
+ 'coordinates' => [-3.0, 24.0],
149
+ },
150
+ ],
151
+ },
152
+ ],
153
+ }
154
+ assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
155
+ assert(::RGeo::GeoJSON.decode(json_, @geo_factory).eql?(object_))
156
+ end
157
+
158
+
159
+ def test_feature
160
+ object_ = @entity_factory.feature(@geo_factory.point(10, 20))
161
+ json_ = {
162
+ 'type' => 'Feature',
163
+ 'geometry' => {
164
+ 'type' => 'Point',
165
+ 'coordinates' => [10.0, 20.0],
166
+ },
167
+ 'properties' => {},
168
+ }
169
+ assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
170
+ assert(::RGeo::GeoJSON.decode(json_, @geo_factory).eql?(object_))
171
+ end
172
+
173
+
174
+ def test_feature_complex
175
+ object_ = @entity_factory.feature(@geo_factory.point(10, 20), 2, {'prop1' => 'foo', 'prop2' => 'bar'})
176
+ json_ = {
177
+ 'type' => 'Feature',
178
+ 'geometry' => {
179
+ 'type' => 'Point',
180
+ 'coordinates' => [10.0, 20.0],
181
+ },
182
+ 'id' => 2,
183
+ 'properties' => {'prop1' => 'foo', 'prop2' => 'bar'},
184
+ }
185
+ assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
186
+ assert(::RGeo::GeoJSON.decode(json_, @geo_factory).eql?(object_))
187
+ end
188
+
189
+
190
+ def test_feature_collection
191
+ 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)])
192
+ json_ = {
193
+ 'type' => 'FeatureCollection',
194
+ 'features' => [
195
+ {
196
+ 'type' => 'Feature',
197
+ 'geometry' => {
198
+ 'type' => 'Point',
199
+ 'coordinates' => [10.0, 20.0],
200
+ },
201
+ 'properties' => {},
202
+ },
203
+ {
204
+ 'type' => 'Feature',
205
+ 'geometry' => {
206
+ 'type' => 'Point',
207
+ 'coordinates' => [11.0, 22.0],
208
+ },
209
+ 'properties' => {},
210
+ },
211
+ {
212
+ 'type' => 'Feature',
213
+ 'geometry' => {
214
+ 'type' => 'Point',
215
+ 'coordinates' => [10.0, 20.0],
216
+ },
217
+ 'id' => 8,
218
+ 'properties' => {},
219
+ },
220
+ ]
221
+ }
222
+ assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
223
+ assert(::RGeo::GeoJSON.decode(json_, @geo_factory).eql?(object_))
224
+ end
225
+
226
+
227
+ end
228
+
229
+ end
230
+ end
@@ -0,0 +1,61 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # A container file for one-off tests
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
+
44
+ class TestOneOff < ::Test::Unit::TestCase # :nodoc:
45
+
46
+
47
+ def setup
48
+ @mercator_factory = ::RGeo::Geography.simple_mercator
49
+ @geos_factory = ::RGeo::Geos.factory(:srid => 4326)
50
+ @entity_factory = ::RGeo::GeoJSON::EntityFactory.instance
51
+ end
52
+
53
+
54
+ def test_dummy
55
+ end
56
+
57
+
58
+ end
59
+
60
+ end
61
+ end