rgeo 0.1.22 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/History.rdoc +31 -0
  2. data/README.rdoc +53 -59
  3. data/Spatial_Programming_With_RGeo.rdoc +120 -67
  4. data/Version +1 -1
  5. data/ext/proj4_c_impl/extconf.rb +1 -1
  6. data/lib/rgeo.rb +80 -87
  7. data/lib/rgeo/cartesian.rb +0 -10
  8. data/lib/rgeo/coord_sys.rb +0 -7
  9. data/lib/rgeo/coord_sys/proj4.rb +2 -2
  10. data/lib/rgeo/error.rb +2 -6
  11. data/lib/rgeo/feature.rb +0 -7
  12. data/lib/rgeo/feature/curve.rb +5 -5
  13. data/lib/rgeo/feature/factory.rb +45 -5
  14. data/lib/rgeo/feature/factory_generator.rb +2 -4
  15. data/lib/rgeo/feature/geometry.rb +97 -27
  16. data/lib/rgeo/feature/geometry_collection.rb +3 -3
  17. data/lib/rgeo/feature/line_string.rb +3 -3
  18. data/lib/rgeo/feature/multi_curve.rb +2 -2
  19. data/lib/rgeo/feature/multi_surface.rb +3 -3
  20. data/lib/rgeo/feature/point.rb +6 -6
  21. data/lib/rgeo/feature/polygon.rb +4 -4
  22. data/lib/rgeo/feature/surface.rb +3 -3
  23. data/lib/rgeo/geographic.rb +0 -11
  24. data/lib/rgeo/geographic/factory.rb +5 -2
  25. data/lib/rgeo/geographic/interface.rb +1 -1
  26. data/lib/rgeo/geos.rb +0 -7
  27. data/lib/rgeo/geos/factory.rb +1 -1
  28. data/lib/rgeo/impl_helper.rb +0 -7
  29. data/lib/rgeo/wkrep.rb +0 -7
  30. data/lib/rgeo/wkrep/wkb_parser.rb +2 -2
  31. data/test/tc_oneoff.rb +0 -1
  32. metadata +7 -155
  33. data/lib/active_record/connection_adapters/mysql2spatial_adapter.rb +0 -124
  34. data/lib/active_record/connection_adapters/mysqlspatial_adapter.rb +0 -136
  35. data/lib/active_record/connection_adapters/postgis_adapter.rb +0 -426
  36. data/lib/active_record/connection_adapters/spatialite_adapter.rb +0 -488
  37. data/lib/rgeo/active_record/arel_modifications.rb +0 -78
  38. data/lib/rgeo/active_record/base_modifications.rb +0 -124
  39. data/lib/rgeo/active_record/common.rb +0 -166
  40. data/lib/rgeo/active_record/mysql_common.rb +0 -150
  41. data/lib/rgeo/all.rb +0 -49
  42. data/lib/rgeo/geo_json.rb +0 -60
  43. data/lib/rgeo/geo_json/coder.rb +0 -401
  44. data/lib/rgeo/geo_json/entities.rb +0 -285
  45. data/lib/rgeo/geo_json/interface.rb +0 -129
  46. data/lib/rgeo/shapefile.rb +0 -60
  47. data/lib/rgeo/shapefile/reader.rb +0 -898
  48. data/test/active_record/common_setup_methods.rb +0 -129
  49. data/test/active_record/readme.txt +0 -43
  50. data/test/active_record/tc_mysqlspatial.rb +0 -170
  51. data/test/active_record/tc_postgis.rb +0 -282
  52. data/test/active_record/tc_spatialite.rb +0 -198
  53. data/test/shapefile/shapelib_testcases/readme.txt +0 -11
  54. data/test/shapefile/shapelib_testcases/test.dbf +0 -0
  55. data/test/shapefile/shapelib_testcases/test.shp +0 -0
  56. data/test/shapefile/shapelib_testcases/test.shx +0 -0
  57. data/test/shapefile/shapelib_testcases/test0.shp +0 -0
  58. data/test/shapefile/shapelib_testcases/test0.shx +0 -0
  59. data/test/shapefile/shapelib_testcases/test1.shp +0 -0
  60. data/test/shapefile/shapelib_testcases/test1.shx +0 -0
  61. data/test/shapefile/shapelib_testcases/test10.shp +0 -0
  62. data/test/shapefile/shapelib_testcases/test10.shx +0 -0
  63. data/test/shapefile/shapelib_testcases/test11.shp +0 -0
  64. data/test/shapefile/shapelib_testcases/test11.shx +0 -0
  65. data/test/shapefile/shapelib_testcases/test12.shp +0 -0
  66. data/test/shapefile/shapelib_testcases/test12.shx +0 -0
  67. data/test/shapefile/shapelib_testcases/test13.shp +0 -0
  68. data/test/shapefile/shapelib_testcases/test13.shx +0 -0
  69. data/test/shapefile/shapelib_testcases/test2.shp +0 -0
  70. data/test/shapefile/shapelib_testcases/test2.shx +0 -0
  71. data/test/shapefile/shapelib_testcases/test3.shp +0 -0
  72. data/test/shapefile/shapelib_testcases/test3.shx +0 -0
  73. data/test/shapefile/shapelib_testcases/test4.shp +0 -0
  74. data/test/shapefile/shapelib_testcases/test4.shx +0 -0
  75. data/test/shapefile/shapelib_testcases/test5.shp +0 -0
  76. data/test/shapefile/shapelib_testcases/test5.shx +0 -0
  77. data/test/shapefile/shapelib_testcases/test6.shp +0 -0
  78. data/test/shapefile/shapelib_testcases/test6.shx +0 -0
  79. data/test/shapefile/shapelib_testcases/test7.shp +0 -0
  80. data/test/shapefile/shapelib_testcases/test7.shx +0 -0
  81. data/test/shapefile/shapelib_testcases/test8.shp +0 -0
  82. data/test/shapefile/shapelib_testcases/test8.shx +0 -0
  83. data/test/shapefile/shapelib_testcases/test9.shp +0 -0
  84. data/test/shapefile/shapelib_testcases/test9.shx +0 -0
  85. data/test/shapefile/tc_shapelib_tests.rb +0 -527
  86. data/test/tc_geojson.rb +0 -279
@@ -1,279 +0,0 @@
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::Cartesian.simple_factory(:srid => 4326)
49
- @geo_factory_z = ::RGeo::Cartesian.simple_factory(:srid => 4326, :has_z_coordinate => true)
50
- @geo_factory_m = ::RGeo::Cartesian.simple_factory(:srid => 4326, :has_m_coordinate => true)
51
- @geo_factory_zm = ::RGeo::Cartesian.simple_factory(:srid => 4326, :has_z_coordinate => true, :has_m_coordinate => true)
52
- @entity_factory = ::RGeo::GeoJSON::EntityFactory.instance
53
- end
54
-
55
-
56
- def test_point
57
- object_ = @geo_factory.point(10, 20)
58
- json_ = {
59
- 'type' => 'Point',
60
- 'coordinates' => [10.0, 20.0],
61
- }
62
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
63
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
64
- end
65
-
66
-
67
- def test_point_z
68
- object_ = @geo_factory_z.point(10, 20, -1)
69
- json_ = {
70
- 'type' => 'Point',
71
- 'coordinates' => [10.0, 20.0, -1.0],
72
- }
73
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
74
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory_z).eql?(object_))
75
- end
76
-
77
-
78
- def test_point_m
79
- object_ = @geo_factory_m.point(10, 20, -1)
80
- json_ = {
81
- 'type' => 'Point',
82
- 'coordinates' => [10.0, 20.0, -1.0],
83
- }
84
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
85
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory_m).eql?(object_))
86
- end
87
-
88
-
89
- def test_point_zm
90
- object_ = @geo_factory_zm.point(10, 20, -1, -2)
91
- json_ = {
92
- 'type' => 'Point',
93
- 'coordinates' => [10.0, 20.0, -1.0, -2.0],
94
- }
95
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
96
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory_zm).eql?(object_))
97
- end
98
-
99
-
100
- def test_line_string
101
- object_ = @geo_factory.line_string([@geo_factory.point(10, 20), @geo_factory.point(12, 22), @geo_factory.point(-3, 24)])
102
- json_ = {
103
- 'type' => 'LineString',
104
- 'coordinates' => [[10.0, 20.0], [12.0, 22.0], [-3.0, 24.0]],
105
- }
106
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
107
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
108
- end
109
-
110
-
111
- def test_polygon
112
- 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)]))
113
- json_ = {
114
- 'type' => 'Polygon',
115
- 'coordinates' => [[[10.0, 20.0], [12.0, 22.0], [-3.0, 24.0], [10.0, 20.0]]],
116
- }
117
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
118
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
119
- end
120
-
121
-
122
- def test_polygon_complex
123
- 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)])])
124
- json_ = {
125
- 'type' => 'Polygon',
126
- '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]]],
127
- }
128
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
129
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(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
- json_ = {
136
- 'type' => 'MultiPoint',
137
- 'coordinates' => [[10.0, 20.0], [12.0, 22.0], [-3.0, 24.0]],
138
- }
139
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
140
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
141
- end
142
-
143
-
144
- def test_multi_line_string
145
- 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)])])
146
- json_ = {
147
- 'type' => 'MultiLineString',
148
- 'coordinates' => [[[10.0, 20.0], [12.0, 22.0], [-3.0, 24.0]], [[1.0, 2.0], [3.0, 4.0]]],
149
- }
150
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
151
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
152
- end
153
-
154
-
155
- def test_multi_polygon
156
- 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)]))])
157
- json_ = {
158
- 'type' => 'MultiPolygon',
159
- '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]]]]
160
- }
161
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
162
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
163
- end
164
-
165
-
166
- def test_geometry_collection
167
- object_ = @geo_factory.collection([@geo_factory.point(10, 20), @geo_factory.collection([@geo_factory.point(12, 22), @geo_factory.point(-3, 24)])])
168
- json_ = {
169
- 'type' => 'GeometryCollection',
170
- 'geometries' => [
171
- {
172
- 'type' => 'Point',
173
- 'coordinates' => [10.0, 20.0],
174
- },
175
- {
176
- 'type' => 'GeometryCollection',
177
- 'geometries' => [
178
- {
179
- 'type' => 'Point',
180
- 'coordinates' => [12.0, 22.0],
181
- },
182
- {
183
- 'type' => 'Point',
184
- 'coordinates' => [-3.0, 24.0],
185
- },
186
- ],
187
- },
188
- ],
189
- }
190
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
191
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
192
- end
193
-
194
-
195
- def test_feature
196
- object_ = @entity_factory.feature(@geo_factory.point(10, 20))
197
- json_ = {
198
- 'type' => 'Feature',
199
- 'geometry' => {
200
- 'type' => 'Point',
201
- 'coordinates' => [10.0, 20.0],
202
- },
203
- 'properties' => {},
204
- }
205
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
206
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
207
- end
208
-
209
-
210
- def test_feature_nulls
211
- json_ = {
212
- 'type' => 'Feature',
213
- 'geometry' => nil,
214
- 'properties' => nil,
215
- }
216
- obj_ = ::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory)
217
- assert_not_nil(obj_)
218
- assert_nil(obj_.geometry)
219
- assert_equal({}, obj_.properties)
220
- end
221
-
222
-
223
- def test_feature_complex
224
- object_ = @entity_factory.feature(@geo_factory.point(10, 20), 2, {'prop1' => 'foo', 'prop2' => 'bar'})
225
- json_ = {
226
- 'type' => 'Feature',
227
- 'geometry' => {
228
- 'type' => 'Point',
229
- 'coordinates' => [10.0, 20.0],
230
- },
231
- 'id' => 2,
232
- 'properties' => {'prop1' => 'foo', 'prop2' => 'bar'},
233
- }
234
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
235
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
236
- end
237
-
238
-
239
- def test_feature_collection
240
- 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)])
241
- json_ = {
242
- 'type' => 'FeatureCollection',
243
- 'features' => [
244
- {
245
- 'type' => 'Feature',
246
- 'geometry' => {
247
- 'type' => 'Point',
248
- 'coordinates' => [10.0, 20.0],
249
- },
250
- 'properties' => {},
251
- },
252
- {
253
- 'type' => 'Feature',
254
- 'geometry' => {
255
- 'type' => 'Point',
256
- 'coordinates' => [11.0, 22.0],
257
- },
258
- 'properties' => {},
259
- },
260
- {
261
- 'type' => 'Feature',
262
- 'geometry' => {
263
- 'type' => 'Point',
264
- 'coordinates' => [10.0, 20.0],
265
- },
266
- 'id' => 8,
267
- 'properties' => {},
268
- },
269
- ]
270
- }
271
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
272
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
273
- end
274
-
275
-
276
- end
277
-
278
- end
279
- end