rgeo 0.1.12 → 0.1.13

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 +9 -7
  2. data/README.rdoc +7 -5
  3. data/Version +1 -1
  4. data/ext/geos_c_impl/factory.c +12 -19
  5. data/ext/geos_c_impl/factory.h +15 -21
  6. data/ext/geos_c_impl/geometry.c +19 -36
  7. data/ext/geos_c_impl/geometry.h +2 -12
  8. data/ext/geos_c_impl/geometry_collection.c +38 -157
  9. data/ext/geos_c_impl/geometry_collection.h +2 -12
  10. data/ext/geos_c_impl/line_string.c +83 -80
  11. data/ext/geos_c_impl/line_string.h +2 -12
  12. data/ext/geos_c_impl/main.c +5 -0
  13. data/ext/geos_c_impl/point.c +2 -12
  14. data/ext/geos_c_impl/point.h +2 -12
  15. data/ext/geos_c_impl/polygon.c +5 -14
  16. data/ext/geos_c_impl/polygon.h +2 -12
  17. data/ext/geos_c_impl/preface.h +8 -0
  18. data/lib/rgeo.rb +34 -16
  19. data/lib/rgeo/{geography/simple_spherical/geometry_collection_impl.rb → cartesian.rb} +19 -26
  20. data/lib/rgeo/cartesian/calculations.rb +129 -0
  21. data/lib/rgeo/cartesian/interface.rb +85 -0
  22. data/lib/rgeo/cartesian/simple_factory.rb +159 -0
  23. data/lib/rgeo/cartesian/simple_feature_classes.rb +187 -0
  24. data/lib/rgeo/cartesian/simple_feature_methods.rb +97 -0
  25. data/lib/rgeo/features.rb +1 -0
  26. data/lib/rgeo/features/curve.rb +3 -2
  27. data/lib/rgeo/features/factory.rb +62 -37
  28. data/lib/rgeo/features/geometry.rb +10 -32
  29. data/lib/rgeo/features/geometry_collection.rb +3 -2
  30. data/lib/rgeo/features/line.rb +3 -2
  31. data/lib/rgeo/features/line_string.rb +3 -2
  32. data/lib/rgeo/features/linear_ring.rb +3 -2
  33. data/lib/rgeo/features/multi_curve.rb +3 -2
  34. data/lib/rgeo/features/multi_line_string.rb +3 -2
  35. data/lib/rgeo/features/multi_point.rb +3 -2
  36. data/lib/rgeo/features/multi_polygon.rb +3 -2
  37. data/lib/rgeo/features/multi_surface.rb +3 -2
  38. data/lib/rgeo/features/point.rb +3 -2
  39. data/lib/rgeo/features/polygon.rb +3 -2
  40. data/lib/rgeo/features/surface.rb +3 -2
  41. data/lib/rgeo/features/types.rb +198 -0
  42. data/lib/rgeo/geography.rb +4 -14
  43. data/lib/rgeo/geography/factory.rb +7 -64
  44. data/lib/rgeo/geography/{simple_spherical/geometry_methods.rb → helper.rb} +4 -13
  45. data/lib/rgeo/geography/simple_mercator/feature_classes.rb +35 -89
  46. data/lib/rgeo/geography/simple_mercator/feature_methods.rb +22 -31
  47. data/lib/rgeo/geography/simple_mercator/projector.rb +4 -8
  48. data/lib/rgeo/geography/simple_spherical/calculations.rb +11 -9
  49. data/lib/rgeo/geography/simple_spherical/feature_classes.rb +189 -0
  50. data/lib/rgeo/geography/simple_spherical/{line_string_impl.rb → feature_methods.rb} +16 -64
  51. data/lib/rgeo/geos/factory.rb +26 -40
  52. data/lib/rgeo/geos/impl_additions.rb +3 -5
  53. data/lib/rgeo/{geography/simple_spherical/polygon_impl.rb → impl_helpers.rb} +16 -26
  54. data/lib/rgeo/impl_helpers/basic_geometry_collection_methods.rb +186 -0
  55. data/lib/rgeo/impl_helpers/basic_geometry_methods.rb +90 -0
  56. data/lib/rgeo/impl_helpers/basic_line_string_methods.rb +188 -0
  57. data/lib/rgeo/impl_helpers/basic_point_methods.rb +149 -0
  58. data/lib/rgeo/{geography/common/helper.rb → impl_helpers/basic_polygon_methods.rb} +62 -53
  59. data/lib/rgeo/{geography/common/polygon_methods.rb → impl_helpers/serialization.rb} +50 -42
  60. data/tests/common/geometry_collection_tests.rb +9 -7
  61. data/tests/common/multi_line_string_tests.rb +16 -13
  62. data/tests/common/multi_point_tests.rb +16 -13
  63. data/tests/common/multi_polygon_tests.rb +8 -6
  64. data/tests/common/point_tests.rb +1 -2
  65. data/tests/common/polygon_tests.rb +9 -9
  66. data/tests/geos/tc_multi_line_string.rb +2 -2
  67. data/tests/simple_cartesian/tc_calculations.rb +138 -0
  68. data/tests/simple_cartesian/tc_geometry_collection.rb +68 -0
  69. data/tests/simple_cartesian/tc_line_string.rb +70 -0
  70. data/{lib/rgeo/geography/simple_spherical/multi_line_string_impl.rb → tests/simple_cartesian/tc_multi_line_string.rb} +19 -19
  71. data/{lib/rgeo/geography/simple_spherical/multi_polygon_impl.rb → tests/simple_cartesian/tc_multi_point.rb} +19 -19
  72. data/{lib/rgeo/geography/common/geometry_methods.rb → tests/simple_cartesian/tc_multi_polygon.rb} +19 -41
  73. data/{lib/rgeo/geography/simple_spherical/point_impl.rb → tests/simple_cartesian/tc_point.rb} +33 -35
  74. data/tests/simple_cartesian/tc_polygon.rb +67 -0
  75. data/tests/simple_spherical/tc_geometry_collection.rb +68 -0
  76. data/tests/simple_spherical/tc_line_string.rb +10 -171
  77. data/tests/simple_spherical/tc_multi_line_string.rb +67 -0
  78. data/{lib/rgeo/geography/simple_spherical/multi_point_impl.rb → tests/simple_spherical/tc_multi_point.rb} +19 -19
  79. data/tests/simple_spherical/tc_multi_polygon.rb +70 -0
  80. data/tests/simple_spherical/tc_point.rb +17 -115
  81. data/tests/simple_spherical/tc_polygon.rb +67 -0
  82. metadata +46 -18
  83. data/ext/geos_c_impl/globals.h +0 -58
  84. data/lib/rgeo/geography/common/geometry_collection_methods.rb +0 -217
  85. data/lib/rgeo/geography/common/line_string_methods.rb +0 -201
  86. data/lib/rgeo/geography/common/point_methods.rb +0 -153
@@ -50,21 +50,11 @@ end
50
50
  # Dependency source files.
51
51
  paths_ = [
52
52
  'features',
53
- 'geography/common/helper',
54
- 'geography/common/geometry_methods',
55
- 'geography/common/point_methods',
56
- 'geography/common/line_string_methods',
57
- 'geography/common/polygon_methods',
58
- 'geography/common/geometry_collection_methods',
53
+ 'cartesian',
54
+ 'geography/helper',
59
55
  'geography/simple_spherical/calculations',
60
- 'geography/simple_spherical/geometry_methods',
61
- 'geography/simple_spherical/point_impl',
62
- 'geography/simple_spherical/line_string_impl',
63
- 'geography/simple_spherical/polygon_impl',
64
- 'geography/simple_spherical/geometry_collection_impl',
65
- 'geography/simple_spherical/multi_point_impl',
66
- 'geography/simple_spherical/multi_line_string_impl',
67
- 'geography/simple_spherical/multi_polygon_impl',
56
+ 'geography/simple_spherical/feature_methods',
57
+ 'geography/simple_spherical/feature_classes',
68
58
  'geography/simple_mercator/projector',
69
59
  'geography/simple_mercator/feature_methods',
70
60
  'geography/simple_mercator/feature_classes',
@@ -45,7 +45,7 @@ module RGeo
45
45
 
46
46
  class Factory
47
47
 
48
- include Features::Factory
48
+ include Features::Factory::Instance
49
49
 
50
50
 
51
51
  def initialize(namespace_, opts_={}) # :nodoc:
@@ -82,13 +82,13 @@ module RGeo
82
82
  # Projects the given geometry into the projected coordinate space,
83
83
  # and returns the projected geometry.
84
84
  # Returns nil if this factory does not support a projection.
85
- # Raises Errors::IllegalGeometry if the given geometry is not of
85
+ # Raises Errors::InvalidGeometry if the given geometry is not of
86
86
  # this factory.
87
87
 
88
88
  def project(geometry_)
89
89
  return nil unless @projector
90
90
  unless geometry_.factory == self
91
- raise Errors::IllegalGeometry, 'Wrong geometry type'
91
+ raise Errors::InvalidGeometry, 'Wrong geometry type'
92
92
  end
93
93
  @projector.project(geometry_)
94
94
  end
@@ -96,12 +96,12 @@ module RGeo
96
96
 
97
97
  # Reverse-projects the given geometry from the projected coordinate
98
98
  # space into lat-long space.
99
- # Raises Errors::IllegalGeometry if the given geometry is not of
99
+ # Raises Errors::InvalidGeometry if the given geometry is not of
100
100
  # the projection defined by this factory.
101
101
 
102
102
  def unproject(geometry_)
103
103
  unless @projector && @projector.projection_factory == geometry_.factory
104
- raise Errors::IllegalGeometry, 'You can unproject only features that are in the projected coordinate space.'
104
+ raise Errors::InvalidGeometry, 'You can unproject only features that are in the projected coordinate space.'
105
105
  end
106
106
  @projector.unproject(geometry_)
107
107
  end
@@ -129,14 +129,14 @@ module RGeo
129
129
  # See ::RGeo::Features::Factory#parse_wkt
130
130
 
131
131
  def parse_wkt(str_)
132
- Common::Helper.parse_wkt(str_, self)
132
+ ImplHelpers::Serialization.parse_wkt(str_, self)
133
133
  end
134
134
 
135
135
 
136
136
  # See ::RGeo::Features::Factory#parse_wkb
137
137
 
138
138
  def parse_wkb(str_)
139
- Common::Helper.parse_wkb(str_, self)
139
+ ImplHelpers::Serialization.parse_wkb(str_, self)
140
140
  end
141
141
 
142
142
 
@@ -164,9 +164,6 @@ module RGeo
164
164
  # See ::RGeo::Features::Factory#linear_ring
165
165
 
166
166
  def linear_ring(points_)
167
- if points_.size > 1 && points_.first != points_.last
168
- points_ << points_.first
169
- end
170
167
  @namespace.const_get(:LinearRingImpl).new(self, points_) rescue nil
171
168
  end
172
169
 
@@ -174,7 +171,6 @@ module RGeo
174
171
  # See ::RGeo::Features::Factory#polygon
175
172
 
176
173
  def polygon(outer_ring_, inner_rings_=nil)
177
- inner_rings_ = inner_rings_.to_a unless inner_rings_.kind_of?(::Array)
178
174
  @namespace.const_get(:PolygonImpl).new(self, outer_ring_, inner_rings_) rescue nil
179
175
  end
180
176
 
@@ -189,8 +185,6 @@ module RGeo
189
185
  # See ::RGeo::Features::Factory#multi_point
190
186
 
191
187
  def multi_point(elems_)
192
- elems_ = _flatten(elems_, Features::Point)
193
- return nil unless elems_
194
188
  @namespace.const_get(:MultiPointImpl).new(self, elems_) rescue nil
195
189
  end
196
190
 
@@ -198,8 +192,6 @@ module RGeo
198
192
  # See ::RGeo::Features::Factory#multi_line_string
199
193
 
200
194
  def multi_line_string(elems_)
201
- elems_ = _flatten(elems_, Features::LineString)
202
- return nil unless elems_
203
195
  @namespace.const_get(:MultiLineStringImpl).new(self, elems_) rescue nil
204
196
  end
205
197
 
@@ -207,59 +199,10 @@ module RGeo
207
199
  # See ::RGeo::Features::Factory#multi_polygon
208
200
 
209
201
  def multi_polygon(elems_)
210
- elems_ = _flatten(elems_, Features::Polygon)
211
- return nil unless elems_
212
202
  @namespace.const_get(:MultiPolygonImpl).new(self, elems_) rescue nil
213
203
  end
214
204
 
215
205
 
216
- # See ::RGeo::Features::Factory#cast
217
-
218
- def cast(original_, force_new_=false)
219
- if self == original_.factory
220
- force_new_ ? original_.dup : original_
221
- else
222
- case original_
223
- when Features::Point
224
- @namespace.const_get(:PointImpl).new(self, original_.x, original_.y) rescue nil
225
- when Features::Line
226
- @namespace.const_get(:LineImpl).new(self, cast(original_.start_point), cast(original_.end_point)) rescue nil
227
- when Features::LinearRing
228
- @namespace.const_get(:LinearRingImpl).new(self, original_.points.map{ |g_| cast(g_) }) rescue nil
229
- when Features::LineString
230
- @namespace.const_get(:LineStringImpl).new(self, original_.points.map{ |g_| cast(g_) }) rescue nil
231
- when Features::Polygon
232
- @namespace.const_get(:PolygonImpl).new(self, cast(original_.exterior_ring), original_.interior_rings.map{ |g_| cast(g_) }) rescue nil
233
- when Features::MultiPoint
234
- @namespace.const_get(:MultiPointImpl).new(self, original_.to_a.map{ |g_| cast(g_) }) rescue nil
235
- when Features::MultiLineString
236
- @namespace.const_get(:MultiLineStringImpl).new(self, original_.to_a.map{ |g_| cast(g_) }) rescue nil
237
- when Features::MultiPolygon
238
- @namespace.const_get(:MultiPolygonImpl).new(self, original_.to_a.map{ |g_| cast(g_) }) rescue nil
239
- when Features::GeometryCollection
240
- @namespace.const_get(:GeometryCollectionImpl).new(self, original_.to_a.map{ |g_| cast(g_) }) rescue nil
241
- else
242
- nil
243
- end
244
- end
245
- end
246
-
247
-
248
- def _flatten(elems_, type_, array_=[])
249
- elems_.each do |elem_|
250
- case elem_
251
- when type_
252
- array_ << elem_
253
- when Features::GeometryCollection
254
- return nil unless _flatten(elem_, type_, array_)
255
- else
256
- return nil
257
- end
258
- end
259
- array_
260
- end
261
-
262
-
263
206
  end
264
207
 
265
208
  end
@@ -1,6 +1,6 @@
1
1
  # -----------------------------------------------------------------------------
2
2
  #
3
- # Spherical base methods
3
+ # Helper for geography implementations
4
4
  #
5
5
  # -----------------------------------------------------------------------------
6
6
  # Copyright 2010 Daniel Azuma
@@ -38,19 +38,10 @@ module RGeo
38
38
 
39
39
  module Geography
40
40
 
41
- module SimpleSpherical
42
-
43
-
44
- module GeometryMethods
45
-
46
-
47
- def srid
48
- 4326
49
- end
50
-
51
-
52
- end
41
+ module Helper # :nodoc:
53
42
 
43
+ RADIANS_PER_DEGREE = ::Math::PI/180.0
44
+ DEGREES_PER_RADIAN = 180.0/::Math::PI
54
45
 
55
46
  end
56
47
 
@@ -38,22 +38,16 @@ module RGeo
38
38
 
39
39
  module Geography
40
40
 
41
- module SimpleMercator
41
+ module SimpleMercator # :nodoc:
42
42
 
43
43
 
44
- class PointImpl
44
+ class PointImpl # :nodoc:
45
45
 
46
46
 
47
47
  include Features::Point
48
- include Common::GeometryMethods
48
+ include ImplHelpers::BasicGeometryMethods
49
49
  include SimpleMercator::GeometryMethods
50
- include Common::PointMethods
51
-
52
-
53
- def initialize(factory_, x_, y_)
54
- _set_factory(factory_)
55
- _setup(x_, y_)
56
- end
50
+ include ImplHelpers::BasicPointMethods
57
51
 
58
52
 
59
53
  def _validate_geometry
@@ -64,7 +58,7 @@ module RGeo
64
58
 
65
59
 
66
60
  def _make_projection(projection_factory_) # :nodoc:
67
- rpd_ = Common::Helper::RADIANS_PER_DEGREE
61
+ rpd_ = Helper::RADIANS_PER_DEGREE
68
62
  mpr_ = EQUATORIAL_RADIUS
69
63
  projection_factory_.point(@x * rpd_ * mpr_,
70
64
  ::Math.log(::Math.tan(::Math::PI / 4.0 + @y * rpd_ / 2.0)) * mpr_)
@@ -72,7 +66,7 @@ module RGeo
72
66
 
73
67
 
74
68
  def scaling_factor
75
- 1.0 / ::Math.cos(Common::Helper::RADIANS_PER_DEGREE * @y)
69
+ 1.0 / ::Math.cos(Helper::RADIANS_PER_DEGREE * @y)
76
70
  end
77
71
 
78
72
 
@@ -90,24 +84,18 @@ module RGeo
90
84
  end
91
85
 
92
86
 
93
- class LineStringImpl
87
+ class LineStringImpl # :nodoc:
94
88
 
95
89
 
96
90
  include Features::LineString
97
- include Common::GeometryMethods
91
+ include ImplHelpers::BasicGeometryMethods
98
92
  include SimpleMercator::GeometryMethods
99
93
  include SimpleMercator::NCurveMethods
100
94
  include SimpleMercator::CurveMethods
101
- include Common::LineStringMethods
95
+ include ImplHelpers::BasicLineStringMethods
102
96
  include SimpleMercator::LineStringMethods
103
97
 
104
98
 
105
- def initialize(factory_, points_)
106
- _set_factory(factory_)
107
- _setup(points_)
108
- end
109
-
110
-
111
99
  def _make_projection(projection_factory_) # :nodoc:
112
100
  projection_factory_.line_string(@points.map{ |p_| p_.projection })
113
101
  end
@@ -116,23 +104,17 @@ module RGeo
116
104
  end
117
105
 
118
106
 
119
- class LinearRingImpl
107
+ class LinearRingImpl # :nodoc:
120
108
 
121
109
 
122
110
  include Features::Line
123
- include Common::GeometryMethods
111
+ include ImplHelpers::BasicGeometryMethods
124
112
  include SimpleMercator::GeometryMethods
125
113
  include SimpleMercator::NCurveMethods
126
114
  include SimpleMercator::CurveMethods
127
- include Common::LineStringMethods
115
+ include ImplHelpers::BasicLineStringMethods
128
116
  include SimpleMercator::LineStringMethods
129
- include Common::LinearRingMethods
130
-
131
-
132
- def initialize(factory_, points_)
133
- _set_factory(factory_)
134
- _setup(points_)
135
- end
117
+ include ImplHelpers::BasicLinearRingMethods
136
118
 
137
119
 
138
120
  def _make_projection(projection_factory_) # :nodoc:
@@ -143,23 +125,17 @@ module RGeo
143
125
  end
144
126
 
145
127
 
146
- class LineImpl
128
+ class LineImpl # :nodoc:
147
129
 
148
130
 
149
131
  include Features::Line
150
- include Common::GeometryMethods
132
+ include ImplHelpers::BasicGeometryMethods
151
133
  include SimpleMercator::GeometryMethods
152
134
  include SimpleMercator::NCurveMethods
153
135
  include SimpleMercator::CurveMethods
154
- include Common::LineStringMethods
136
+ include ImplHelpers::BasicLineStringMethods
155
137
  include SimpleMercator::LineStringMethods
156
- include Common::LineMethods
157
-
158
-
159
- def initialize(factory_, start_, end_)
160
- _set_factory(factory_)
161
- _setup([start_, end_])
162
- end
138
+ include ImplHelpers::BasicLineMethods
163
139
 
164
140
 
165
141
  def _make_projection(projection_factory_) # :nodoc:
@@ -170,21 +146,15 @@ module RGeo
170
146
  end
171
147
 
172
148
 
173
- class PolygonImpl
149
+ class PolygonImpl # :nodoc:
174
150
 
175
151
 
176
152
  include Features::Polygon
177
- include Common::GeometryMethods
153
+ include ImplHelpers::BasicGeometryMethods
178
154
  include SimpleMercator::GeometryMethods
179
155
  include SimpleMercator::NSurfaceMethods
180
156
  include SimpleMercator::SurfaceMethods
181
- include Common::PolygonMethods
182
-
183
-
184
- def initialize(factory_, exterior_ring_, interior_rings_)
185
- _set_factory(factory_)
186
- _setup(exterior_ring_, interior_rings_)
187
- end
157
+ include ImplHelpers::BasicPolygonMethods
188
158
 
189
159
 
190
160
  def _validate_geometry
@@ -204,22 +174,16 @@ module RGeo
204
174
  end
205
175
 
206
176
 
207
- class GeometryCollectionImpl
177
+ class GeometryCollectionImpl # :nodoc:
208
178
 
209
179
 
210
180
  include Features::GeometryCollection
211
- include Common::GeometryMethods
181
+ include ImplHelpers::BasicGeometryMethods
212
182
  include SimpleMercator::GeometryMethods
213
- include Common::GeometryCollectionMethods
183
+ include ImplHelpers::BasicGeometryCollectionMethods
214
184
  include SimpleMercator::GeometryCollectionMethods
215
185
 
216
186
 
217
- def initialize(factory_, elements_)
218
- _set_factory(factory_)
219
- _setup(elements_)
220
- end
221
-
222
-
223
187
  def _make_projection(projection_factory_) # :nodoc:
224
188
  projection_factory_.collection(@elements.map{ |p_| p_.projection })
225
189
  end
@@ -228,21 +192,15 @@ module RGeo
228
192
  end
229
193
 
230
194
 
231
- class MultiPointImpl
195
+ class MultiPointImpl # :nodoc:
232
196
 
233
197
 
234
198
  include Features::GeometryCollection
235
- include Common::GeometryMethods
199
+ include ImplHelpers::BasicGeometryMethods
236
200
  include SimpleMercator::GeometryMethods
237
- include Common::GeometryCollectionMethods
201
+ include ImplHelpers::BasicGeometryCollectionMethods
238
202
  include SimpleMercator::GeometryCollectionMethods
239
- include Common::MultiPointMethods
240
-
241
-
242
- def initialize(factory_, elements_)
243
- _set_factory(factory_)
244
- _setup(elements_)
245
- end
203
+ include ImplHelpers::BasicMultiPointMethods
246
204
 
247
205
 
248
206
  def _make_projection(projection_factory_) # :nodoc:
@@ -253,22 +211,16 @@ module RGeo
253
211
  end
254
212
 
255
213
 
256
- class MultiLineStringImpl
214
+ class MultiLineStringImpl # :nodoc:
257
215
 
258
216
 
259
217
  include Features::GeometryCollection
260
- include Common::GeometryMethods
218
+ include ImplHelpers::BasicGeometryMethods
261
219
  include SimpleMercator::GeometryMethods
262
220
  include SimpleMercator::NCurveMethods
263
- include Common::GeometryCollectionMethods
221
+ include ImplHelpers::BasicGeometryCollectionMethods
264
222
  include SimpleMercator::GeometryCollectionMethods
265
- include Common::MultiLineStringMethods
266
-
267
-
268
- def initialize(factory_, elements_)
269
- _set_factory(factory_)
270
- _setup(elements_)
271
- end
223
+ include ImplHelpers::BasicMultiLineStringMethods
272
224
 
273
225
 
274
226
  def _make_projection(projection_factory_) # :nodoc:
@@ -279,22 +231,16 @@ module RGeo
279
231
  end
280
232
 
281
233
 
282
- class MultiPolygonImpl
234
+ class MultiPolygonImpl # :nodoc:
283
235
 
284
236
 
285
237
  include Features::GeometryCollection
286
- include Common::GeometryMethods
238
+ include ImplHelpers::BasicGeometryMethods
287
239
  include SimpleMercator::GeometryMethods
288
240
  include SimpleMercator::NSurfaceMethods
289
- include Common::GeometryCollectionMethods
241
+ include ImplHelpers::BasicGeometryCollectionMethods
290
242
  include SimpleMercator::GeometryCollectionMethods
291
- include Common::MultiPolygonMethods
292
-
293
-
294
- def initialize(factory_, elements_)
295
- _set_factory(factory_)
296
- _setup(elements_)
297
- end
243
+ include ImplHelpers::BasicMultiPolygonMethods
298
244
 
299
245
 
300
246
  def _validate_geometry