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
@@ -1,6 +1,6 @@
1
1
  # -----------------------------------------------------------------------------
2
2
  #
3
- # Spherical LineString implementation
3
+ # Spherical geometry common methods
4
4
  #
5
5
  # -----------------------------------------------------------------------------
6
6
  # Copyright 2010 Daniel Azuma
@@ -38,10 +38,21 @@ module RGeo
38
38
 
39
39
  module Geography
40
40
 
41
- module SimpleSpherical
41
+ module SimpleSpherical # :nodoc:
42
42
 
43
43
 
44
- module LineStringMethods
44
+ module GeometryMethods # :nodoc:
45
+
46
+
47
+ def srid
48
+ 4326
49
+ end
50
+
51
+
52
+ end
53
+
54
+
55
+ module LineStringMethods # :nodoc:
45
56
 
46
57
 
47
58
  def _arcs
@@ -57,9 +68,9 @@ module RGeo
57
68
  def is_simple?
58
69
  arcs_ = _arcs
59
70
  len_ = arcs_.length
60
- return false if arcs_.any?{ |a_| a_.nil? }
71
+ return false if arcs_.any?{ |a_| a_.degenerate? }
61
72
  return true if len_ == 1
62
- return arcs_[0].start != arcs_[1].end if len_ == 2
73
+ return arcs_[0].s != arcs_[1].e if len_ == 2
63
74
  arcs_.each_with_index do |arc_, index_|
64
75
  nindex_ = index_ + 1
65
76
  nindex_ = nil if nindex_ == len_
@@ -83,65 +94,6 @@ module RGeo
83
94
  end
84
95
 
85
96
 
86
- class LineStringImpl
87
-
88
-
89
- include Features::LineString
90
- include Common::GeometryMethods
91
- include SimpleSpherical::GeometryMethods
92
- include Common::LineStringMethods
93
- include SimpleSpherical::LineStringMethods
94
-
95
-
96
- def initialize(factory_, points_)
97
- _set_factory(factory_)
98
- _setup(points_)
99
- end
100
-
101
-
102
- end
103
-
104
-
105
- class LineImpl
106
-
107
-
108
- include Features::Line
109
- include Common::GeometryMethods
110
- include SimpleSpherical::GeometryMethods
111
- include Common::LineStringMethods
112
- include SimpleSpherical::LineStringMethods
113
- include Common::LineMethods
114
-
115
-
116
- def initialize(factory_, start_, end_)
117
- _set_factory(factory_)
118
- _setup([start_, end_])
119
- end
120
-
121
-
122
- end
123
-
124
-
125
- class LinearRingImpl
126
-
127
-
128
- include Features::Line
129
- include Common::GeometryMethods
130
- include SimpleSpherical::GeometryMethods
131
- include Common::LineStringMethods
132
- include SimpleSpherical::LineStringMethods
133
- include Common::LinearRingMethods
134
-
135
-
136
- def initialize(factory_, points_)
137
- _set_factory(factory_)
138
- _setup(points_)
139
- end
140
-
141
-
142
- end
143
-
144
-
145
97
  end
146
98
 
147
99
  end
@@ -43,7 +43,7 @@ module RGeo
43
43
 
44
44
  class Factory
45
45
 
46
- include Features::Factory
46
+ include Features::Factory::Instance
47
47
 
48
48
 
49
49
  class << self
@@ -103,12 +103,12 @@ module RGeo
103
103
 
104
104
  # Returns true if this factory is lenient with MultiPolygon assertions
105
105
 
106
- def lenient_multi_polygons?
106
+ def lenient_multi_polygon_assertions?
107
107
  _flags & 0x1 != 0
108
108
  end
109
109
 
110
110
 
111
- # Equivalence test.
111
+ # Factory equivalence test.
112
112
 
113
113
  def eql?(rhs_)
114
114
  rhs_.is_a?(Factory) && rhs_.srid == _srid && rhs_._buffer_resolution == _buffer_resolution && rhs_._flags == _flags
@@ -156,9 +156,6 @@ module RGeo
156
156
 
157
157
  def linear_ring(points_)
158
158
  points_ = points_.to_a unless points_.kind_of?(::Array)
159
- if points_.size > 1 && points_.first != points_.last
160
- points_ << points_.first
161
- end
162
159
  LinearRingImpl.create(self, points_) rescue nil
163
160
  end
164
161
 
@@ -203,46 +200,35 @@ module RGeo
203
200
  end
204
201
 
205
202
 
206
- # See ::RGeo::Features::Factory#cast
203
+ # See ::RGeo::Features::Factory#override_cast
207
204
 
208
- def cast(original_, force_new_=false)
205
+ def override_cast(original_, ntype_, keep_subtype_, force_new_)
209
206
  return nil unless Geos.supported?
210
- case original_
211
- when GeometryImpl
212
- if original_.factory != self
207
+ type_ = original_.geometry_type
208
+ ntype_ = type_ if keep_subtype_ && type_.include?(ntype_)
209
+ if original_.factory != self && ntype_ == type_
210
+ if GeometryImpl === original_
213
211
  result_ = original_.dup
214
- result_.instance_variable_set(:@_factory, self)
215
- result_
216
- elsif force_new_
217
- original_.dup
218
- else
219
- original_
212
+ result_._set_factory(self)
213
+ return result_
214
+ end
215
+ if type_ == Features::Point && original_.respond_to?(:z)
216
+ z_ = original_.z
217
+ return PointImpl.create(self, original_.x, original_.y, z_) if z_
220
218
  end
221
- when Features::Point
222
- if original_.respond_to?(:z)
223
- PointImpl.create(self, original_.x, original_.y, original_.z)
224
- else
225
- PointImpl.create(self, original_.x, original_.y)
219
+ end
220
+ if GeometryImpl === original_ && (original_.factory != self || ntype_ != type_) &&
221
+ (type_ == Features::LineString || type_ == Features::Line || type_ == Features::LinearRing)
222
+ then
223
+ if ntype_ == Features::LineString
224
+ return LineStringImpl._copy_from(self, original_)
225
+ elsif ntype_ == Features::Line
226
+ return LineImpl._copy_from(self, original_)
227
+ elsif ntype_ == Features::LinearRing
228
+ return LinearRingImpl._copy_from(self, original_)
226
229
  end
227
- when Features::Line
228
- LineImpl.create(self, cast(original_.start_point), cast(original_.end_point))
229
- when Features::LinearRing
230
- LinearRingImpl.create(self, original_.points.map{ |g_| cast(g_) })
231
- when Features::LineString
232
- LineStringImpl.create(self, original_.points.map{ |g_| cast(g_) })
233
- when Features::Polygon
234
- PolygonImpl.create(self, cast(original_.exterior_ring), original_.interior_rings.map{ |g_| cast(g_) })
235
- when Features::MultiPoint
236
- MultiPointImpl.create(self, original_.to_a.map{ |g_| cast(g_) })
237
- when Features::MultiLineString
238
- MultiLineStringImpl.create(self, original_.to_a.map{ |g_| cast(g_) })
239
- when Features::MultiPolygon
240
- MultiPolygonImpl.create(self, original_.to_a.map{ |g_| cast(g_) })
241
- when Features::GeometryCollection
242
- GeometryCollectionImpl.create(self, original_.to_a.map{ |g_| cast(g_) })
243
- else
244
- nil
245
230
  end
231
+ false
246
232
  end
247
233
 
248
234
 
@@ -34,14 +34,14 @@
34
34
  ;
35
35
 
36
36
 
37
- # :stopdoc:
38
-
39
37
  module RGeo
40
38
 
41
39
  module Geos
42
40
 
43
41
 
44
- class GeometryImpl
42
+ class GeometryImpl # :nodoc:
43
+
44
+ include ::RGeo::Features::Type::Instance
45
45
 
46
46
  def inspect
47
47
  "#<#{self.class}:0x#{object_id.to_s(16)} #{as_text.inspect}>"
@@ -53,5 +53,3 @@ module RGeo
53
53
  end
54
54
 
55
55
  end
56
-
57
- # :startdoc:
@@ -1,6 +1,6 @@
1
1
  # -----------------------------------------------------------------------------
2
2
  #
3
- # Spherical Polygon implementation
3
+ # Implementation helpers namespace for RGeo
4
4
  #
5
5
  # -----------------------------------------------------------------------------
6
6
  # Copyright 2010 Daniel Azuma
@@ -36,31 +36,21 @@
36
36
 
37
37
  module RGeo
38
38
 
39
- module Geography
40
-
41
- module SimpleSpherical
42
-
43
-
44
- class PolygonImpl
45
-
46
-
47
- include Features::Polygon
48
- include Common::GeometryMethods
49
- include GeometryMethods
50
- include Common::PolygonMethods
51
-
52
-
53
- def initialize(factory_, exterior_ring_, interior_rings_)
54
- _set_factory(factory_)
55
- _setup(exterior_ring_, interior_rings_)
56
- end
57
-
58
-
59
- end
60
-
61
-
62
- end
63
-
39
+
40
+ module ImplHelpers # :nodoc:
64
41
  end
65
42
 
43
+
66
44
  end
45
+
46
+
47
+ # Dependency source files.
48
+ paths_ = [
49
+ 'impl_helpers/basic_geometry_methods',
50
+ 'impl_helpers/basic_geometry_collection_methods',
51
+ 'impl_helpers/basic_point_methods',
52
+ 'impl_helpers/basic_line_string_methods',
53
+ 'impl_helpers/basic_polygon_methods',
54
+ 'impl_helpers/serialization',
55
+ ]
56
+ paths_.each{ |path_| require "rgeo/#{path_}" }
@@ -0,0 +1,186 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Common methods for GeometryCollection features
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 ImplHelpers # :nodoc:
40
+
41
+
42
+ module BasicGeometryCollectionMethods # :nodoc:
43
+
44
+
45
+ def initialize(factory_, elements_)
46
+ _set_factory(factory_)
47
+ @elements = elements_.map do |elem_|
48
+ elem_ = Features.cast(elem_, factory_)
49
+ unless elem_
50
+ raise Errors::InvalidGeometry, "Could not cast #{elem_}"
51
+ end
52
+ elem_
53
+ end
54
+ _validate_geometry
55
+ end
56
+
57
+
58
+ def eql?(rhs_)
59
+ if rhs_.is_a?(self.class) && rhs_.factory.eql?(@factory) && @elements.size == rhs_.num_geometries
60
+ rhs_.each_with_index{ |p_, i_| return false unless @elements[i_].eql?(p_) }
61
+ else
62
+ false
63
+ end
64
+ end
65
+
66
+
67
+ def num_geometries
68
+ @elements.size
69
+ end
70
+
71
+
72
+ def geometry_n(n_)
73
+ @elements[n_]
74
+ end
75
+
76
+
77
+ def each(&block_)
78
+ @elements.each(&block_)
79
+ end
80
+
81
+
82
+ def dimension
83
+ unless @dimension
84
+ @dimension = -1
85
+ @elements.each do |elem_|
86
+ dim_ = elem_.dimension
87
+ @dimension = dim_ if @dimension < dim_
88
+ end
89
+ end
90
+ @dimension
91
+ end
92
+
93
+
94
+ def geometry_type
95
+ Features::GeometryCollection
96
+ end
97
+
98
+
99
+ def is_empty?
100
+ @elements.size == 0
101
+ end
102
+
103
+
104
+ end
105
+
106
+
107
+ module BasicMultiLineStringMethods # :nodoc:
108
+
109
+
110
+ def initialize(factory_, elements_)
111
+ _set_factory(factory_)
112
+ @elements = elements_.map do |elem_|
113
+ elem_ = Features.cast(elem_, factory_, Features::LineString, :keep_subtype)
114
+ unless elem_
115
+ raise Errors::InvalidGeometry, "Could not cast #{elem_}"
116
+ end
117
+ elem_
118
+ end
119
+ _validate_geometry
120
+ end
121
+
122
+
123
+ def geometry_type
124
+ Features::MultiLineString
125
+ end
126
+
127
+
128
+ def is_closed?
129
+ all?{ |elem_| elem_.is_closed? }
130
+ end
131
+
132
+
133
+ end
134
+
135
+
136
+ module BasicMultiPointMethods # :nodoc:
137
+
138
+
139
+ def initialize(factory_, elements_)
140
+ _set_factory(factory_)
141
+ @elements = elements_.map do |elem_|
142
+ elem_ = Features.cast(elem_, factory_, Features::Point, :keep_subtype)
143
+ unless elem_
144
+ raise Errors::InvalidGeometry, "Could not cast #{elem_}"
145
+ end
146
+ elem_
147
+ end
148
+ _validate_geometry
149
+ end
150
+
151
+
152
+ def geometry_type
153
+ Features::MultiPoint
154
+ end
155
+
156
+
157
+ end
158
+
159
+
160
+ module BasicMultiPolygonMethods # :nodoc:
161
+
162
+
163
+ def initialize(factory_, elements_)
164
+ _set_factory(factory_)
165
+ @elements = elements_.map do |elem_|
166
+ elem_ = Features.cast(elem_, factory_, Features::Polygon, :keep_subtype)
167
+ unless elem_
168
+ raise Errors::InvalidGeometry, "Could not cast #{elem_}"
169
+ end
170
+ elem_
171
+ end
172
+ _validate_geometry
173
+ end
174
+
175
+
176
+ def geometry_type
177
+ Features::MultiPolygon
178
+ end
179
+
180
+
181
+ end
182
+
183
+
184
+ end
185
+
186
+ end