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
@@ -38,19 +38,10 @@ module RGeo
38
38
 
39
39
  module Geography
40
40
 
41
- module SimpleMercator
41
+ module SimpleMercator # :nodoc:
42
42
 
43
43
 
44
- module GeometryMethods
45
-
46
-
47
- def eql?(rhs_)
48
- if rhs_.respond_to?(:factory) && rhs_.factory.eql?(@factory)
49
- projection.eql?(rhs_.projection)
50
- else
51
- false
52
- end
53
- end
44
+ module GeometryMethods # :nodoc:
54
45
 
55
46
 
56
47
  def srid
@@ -103,52 +94,52 @@ module RGeo
103
94
 
104
95
 
105
96
  def equals?(rhs_)
106
- projection.equals?(factory.cast(rhs_).projection)
97
+ projection.equals?(Features.cast(rhs_, factory).projection)
107
98
  end
108
99
 
109
100
 
110
101
  def disjoint?(rhs_)
111
- projection.disjoint?(factory.cast(rhs_).projection)
102
+ projection.disjoint?(Features.cast(rhs_, factory).projection)
112
103
  end
113
104
 
114
105
 
115
106
  def intersects?(rhs_)
116
- projection.intersects?(factory.cast(rhs_).projection)
107
+ projection.intersects?(Features.cast(rhs_, factory).projection)
117
108
  end
118
109
 
119
110
 
120
111
  def touches?(rhs_)
121
- projection.touches?(factory.cast(rhs_).projection)
112
+ projection.touches?(Features.cast(rhs_, factory).projection)
122
113
  end
123
114
 
124
115
 
125
116
  def crosses?(rhs_)
126
- projection.crosses?(factory.cast(rhs_).projection)
117
+ projection.crosses?(Features.cast(rhs_, factory).projection)
127
118
  end
128
119
 
129
120
 
130
121
  def within?(rhs_)
131
- projection.within?(factory.cast(rhs_).projection)
122
+ projection.within?(Features.cast(rhs_, factory).projection)
132
123
  end
133
124
 
134
125
 
135
126
  def contains?(rhs_)
136
- projection.contains?(factory.cast(rhs_).projection)
127
+ projection.contains?(Features.cast(rhs_, factory).projection)
137
128
  end
138
129
 
139
130
 
140
131
  def overlaps?(rhs_)
141
- projection.overlaps?(factory.cast(rhs_).projection)
132
+ projection.overlaps?(Features.cast(rhs_, factory).projection)
142
133
  end
143
134
 
144
135
 
145
136
  def relate(rhs_, pattern_)
146
- projection.relate(factory.cast(rhs_).projection, pattern_)
137
+ projection.relate(Features.cast(rhs_, factory).projection, pattern_)
147
138
  end
148
139
 
149
140
 
150
141
  def distance(rhs_)
151
- projection.distance(factory.cast(rhs_).projection) / scaling_factor
142
+ projection.distance(Features.cast(rhs_, factory).projection) / scaling_factor
152
143
  end
153
144
 
154
145
 
@@ -163,29 +154,29 @@ module RGeo
163
154
 
164
155
 
165
156
  def intersection(rhs_)
166
- factory.unproject(projection.intersection(factory.cast(rhs_).projection))
157
+ factory.unproject(projection.intersection(Features.cast(rhs_, factory).projection))
167
158
  end
168
159
 
169
160
 
170
161
  def union(rhs_)
171
- factory.unproject(projection.union(factory.cast(rhs_).projection))
162
+ factory.unproject(projection.union(Features.cast(rhs_, factory).projection))
172
163
  end
173
164
 
174
165
 
175
166
  def difference(rhs_)
176
- factory.unproject(projection.difference(factory.cast(rhs_).projection))
167
+ factory.unproject(projection.difference(Features.cast(rhs_, factory).projection))
177
168
  end
178
169
 
179
170
 
180
171
  def sym_difference(rhs_)
181
- factory.unproject(projection.sym_difference(factory.cast(rhs_).projection))
172
+ factory.unproject(projection.sym_difference(Features.cast(rhs_, factory).projection))
182
173
  end
183
174
 
184
175
 
185
176
  end
186
177
 
187
178
 
188
- module GeometryCollectionMethods
179
+ module GeometryCollectionMethods # :nodoc:
189
180
 
190
181
 
191
182
  def scaling_factor
@@ -196,7 +187,7 @@ module RGeo
196
187
  end
197
188
 
198
189
 
199
- module NCurveMethods
190
+ module NCurveMethods # :nodoc:
200
191
 
201
192
 
202
193
  def length
@@ -207,7 +198,7 @@ module RGeo
207
198
  end
208
199
 
209
200
 
210
- module CurveMethods
201
+ module CurveMethods # :nodoc:
211
202
 
212
203
 
213
204
  def scaling_factor
@@ -218,7 +209,7 @@ module RGeo
218
209
  end
219
210
 
220
211
 
221
- module LineStringMethods
212
+ module LineStringMethods # :nodoc:
222
213
 
223
214
 
224
215
  def _validate_geometry
@@ -251,7 +242,7 @@ module RGeo
251
242
  end
252
243
 
253
244
 
254
- module NSurfaceMethods
245
+ module NSurfaceMethods # :nodoc:
255
246
 
256
247
 
257
248
  def area
@@ -273,7 +264,7 @@ module RGeo
273
264
  end
274
265
 
275
266
 
276
- module SurfaceMethods
267
+ module SurfaceMethods # :nodoc:
277
268
 
278
269
 
279
270
  def scaling_factor
@@ -38,21 +38,17 @@ module RGeo
38
38
 
39
39
  module Geography
40
40
 
41
- module SimpleMercator
41
+ module SimpleMercator # :nodoc:
42
42
 
43
43
 
44
44
  EQUATORIAL_RADIUS = 6378137.0
45
45
 
46
46
 
47
- class Projector
47
+ class Projector # :nodoc:
48
48
 
49
49
  def initialize(geography_factory_, opts_={})
50
50
  @geography_factory = geography_factory_
51
- if ::RGeo.const_defined?(:Geos) && Geos.supported?
52
- @projection_factory = Geos.factory(:srid => 3857, :buffer_resolution => opts_[:buffer_resolution], :lenient_multi_polygon_assertions => opts_[:lenient_multi_polygon_assertions])
53
- else
54
- @projection_factory = nil
55
- end
51
+ @projection_factory = Cartesian.preferred_factory(:srid => 3857, :buffer_resolution => opts_[:buffer_resolution], :lenient_multi_polygon_assertions => opts_[:lenient_multi_polygon_assertions])
56
52
  end
57
53
 
58
54
 
@@ -69,7 +65,7 @@ module RGeo
69
65
  def unproject(geometry_)
70
66
  case geometry_
71
67
  when Features::Point
72
- dpr_ = Common::Helper::DEGREES_PER_RADIAN
68
+ dpr_ = Helper::DEGREES_PER_RADIAN
73
69
  radius_ = EQUATORIAL_RADIUS
74
70
  @geography_factory.point(geometry_.x / radius_ * dpr_,
75
71
  (2.0 * ::Math.atan(::Math.exp(geometry_.y / radius_)) - ::Math::PI / 2.0) * dpr_)
@@ -38,7 +38,7 @@ module RGeo
38
38
 
39
39
  module Geography
40
40
 
41
- module SimpleSpherical
41
+ module SimpleSpherical # :nodoc:
42
42
 
43
43
 
44
44
  RADIUS = 6371007.2
@@ -55,7 +55,7 @@ module RGeo
55
55
  # This object is also used to represent a great circle, as its axis
56
56
  # of rotation.
57
57
 
58
- class PointXYZ
58
+ class PointXYZ # :nodoc:
59
59
 
60
60
  def initialize(x_, y_, z_)
61
61
  r_ = ::Math.sqrt(x_ * x_ + y_ * y_ + z_ * z_)
@@ -85,7 +85,7 @@ module RGeo
85
85
  def latlon
86
86
  lat_rad_ = ::Math.asin(@z)
87
87
  lon_rad_ = ::Math.atan2(@y, @x) rescue 0.0
88
- rpd_ = Common::Helper::RADIANS_PER_DEGREE
88
+ rpd_ = Helper::RADIANS_PER_DEGREE
89
89
  [lat_rad_ / rpd_, lon_rad_ / rpd_]
90
90
  end
91
91
 
@@ -120,7 +120,7 @@ module RGeo
120
120
 
121
121
 
122
122
  def self.from_latlon(lat_, lon_)
123
- rpd_ = Common::Helper::RADIANS_PER_DEGREE
123
+ rpd_ = Helper::RADIANS_PER_DEGREE
124
124
  lat_rad_ = rpd_ * lat_
125
125
  lon_rad_ = rpd_ * lon_
126
126
  z_ = ::Math.sin(lat_rad_)
@@ -135,7 +135,7 @@ module RGeo
135
135
 
136
136
  # Represents a finite arc on the sphere.
137
137
 
138
- class ArcXYZ
138
+ class ArcXYZ # :nodoc:
139
139
 
140
140
  def initialize(start_, end_)
141
141
  @s = start_
@@ -159,6 +159,12 @@ module RGeo
159
159
  alias_method :==, :eql?
160
160
 
161
161
 
162
+ def degenerate?
163
+ axis_ = axis
164
+ axis_.x == 0 && axis_.y == 0 && axis_.z == 0
165
+ end
166
+
167
+
162
168
  def axis
163
169
  if @axis == false
164
170
  @axis = @s % @e
@@ -193,10 +199,6 @@ module RGeo
193
199
  end
194
200
 
195
201
 
196
- module Calculations
197
- end
198
-
199
-
200
202
  end
201
203
 
202
204
  end
@@ -0,0 +1,189 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Spherical geography feature classes
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2010 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+
37
+ module RGeo
38
+
39
+ module Geography
40
+
41
+ module SimpleSpherical # :nodoc:
42
+
43
+
44
+ class PointImpl # :nodoc:
45
+
46
+
47
+ include Features::Point
48
+ include ImplHelpers::BasicGeometryMethods
49
+ include SimpleSpherical::GeometryMethods
50
+ include ImplHelpers::BasicPointMethods
51
+
52
+
53
+ def _validate_geometry
54
+ @x = @x % 360.0
55
+ @x -= 360.0 if @x >= 180.0
56
+ @y = 90.0 if @y > 90.0
57
+ @y = -90.0 if @y < -90.0
58
+ super
59
+ end
60
+
61
+
62
+ def _xyz
63
+ @xyz ||= PointXYZ.from_latlon(@y, @x)
64
+ end
65
+
66
+
67
+ def distance(rhs_)
68
+ rhs_ = Features.cast(rhs_, @factory)
69
+ case rhs_
70
+ when PointImpl
71
+ _xyz.dist_to_point(rhs_._xyz) * SimpleSpherical::RADIUS
72
+ else
73
+ super
74
+ end
75
+ end
76
+
77
+
78
+ end
79
+
80
+
81
+ class LineStringImpl # :nodoc:
82
+
83
+
84
+ include Features::LineString
85
+ include ImplHelpers::BasicGeometryMethods
86
+ include SimpleSpherical::GeometryMethods
87
+ include ImplHelpers::BasicLineStringMethods
88
+ include SimpleSpherical::LineStringMethods
89
+
90
+
91
+ end
92
+
93
+
94
+ class LineImpl # :nodoc:
95
+
96
+
97
+ include Features::Line
98
+ include ImplHelpers::BasicGeometryMethods
99
+ include SimpleSpherical::GeometryMethods
100
+ include ImplHelpers::BasicLineStringMethods
101
+ include SimpleSpherical::LineStringMethods
102
+ include ImplHelpers::BasicLineMethods
103
+
104
+
105
+ end
106
+
107
+
108
+ class LinearRingImpl # :nodoc:
109
+
110
+
111
+ include Features::Line
112
+ include ImplHelpers::BasicGeometryMethods
113
+ include SimpleSpherical::GeometryMethods
114
+ include ImplHelpers::BasicLineStringMethods
115
+ include SimpleSpherical::LineStringMethods
116
+ include ImplHelpers::BasicLinearRingMethods
117
+
118
+
119
+ end
120
+
121
+
122
+ class PolygonImpl # :nodoc:
123
+
124
+
125
+ include Features::Polygon
126
+ include ImplHelpers::BasicGeometryMethods
127
+ include SimpleSpherical::GeometryMethods
128
+ include ImplHelpers::BasicPolygonMethods
129
+
130
+
131
+ end
132
+
133
+
134
+ class GeometryCollectionImpl # :nodoc:
135
+
136
+
137
+ include Features::GeometryCollection
138
+ include ImplHelpers::BasicGeometryMethods
139
+ include SimpleSpherical::GeometryMethods
140
+ include ImplHelpers::BasicGeometryCollectionMethods
141
+
142
+
143
+ end
144
+
145
+
146
+ class MultiPointImpl # :nodoc:
147
+
148
+
149
+ include Features::GeometryCollection
150
+ include ImplHelpers::BasicGeometryMethods
151
+ include SimpleSpherical::GeometryMethods
152
+ include ImplHelpers::BasicGeometryCollectionMethods
153
+ include ImplHelpers::BasicMultiPointMethods
154
+
155
+
156
+ end
157
+
158
+
159
+ class MultiLineStringImpl # :nodoc:
160
+
161
+
162
+ include Features::GeometryCollection
163
+ include ImplHelpers::BasicGeometryMethods
164
+ include SimpleSpherical::GeometryMethods
165
+ include ImplHelpers::BasicGeometryCollectionMethods
166
+ include ImplHelpers::BasicMultiLineStringMethods
167
+
168
+
169
+ end
170
+
171
+
172
+ class MultiPolygonImpl # :nodoc:
173
+
174
+
175
+ include Features::GeometryCollection
176
+ include ImplHelpers::BasicGeometryMethods
177
+ include SimpleSpherical::GeometryMethods
178
+ include ImplHelpers::BasicGeometryCollectionMethods
179
+ include ImplHelpers::BasicMultiPolygonMethods
180
+
181
+
182
+ end
183
+
184
+
185
+ end
186
+
187
+ end
188
+
189
+ end