rgeo 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +29 -0
  3. data/ext/geos_c_impl/Makefile_2.2.3 +260 -0
  4. data/ext/geos_c_impl/coordinates.c +65 -0
  5. data/ext/geos_c_impl/coordinates.h +2 -0
  6. data/ext/geos_c_impl/extconf.rb +19 -43
  7. data/ext/geos_c_impl/geometry.c +24 -0
  8. data/ext/geos_c_impl/geometry_collection.c +99 -1
  9. data/ext/geos_c_impl/geos_c_impl_2.2.3.bundle +0 -0
  10. data/ext/geos_c_impl/line_string.c +38 -0
  11. data/ext/geos_c_impl/mkmf.log +123 -0
  12. data/ext/geos_c_impl/point.c +27 -0
  13. data/ext/geos_c_impl/polygon.c +26 -0
  14. data/ext/proj4_c_impl/Makefile_2.2.3 +260 -0
  15. data/ext/proj4_c_impl/extconf.rb +32 -32
  16. data/ext/proj4_c_impl/mkmf.log +47 -0
  17. data/ext/proj4_c_impl/proj4_c_impl_2.2.3.bundle +0 -0
  18. data/lib/rgeo.rb +10 -11
  19. data/lib/rgeo/cartesian.rb +7 -12
  20. data/lib/rgeo/cartesian/analysis.rb +13 -26
  21. data/lib/rgeo/cartesian/bounding_box.rb +45 -114
  22. data/lib/rgeo/cartesian/calculations.rb +3 -21
  23. data/lib/rgeo/cartesian/factory.rb +101 -122
  24. data/lib/rgeo/cartesian/feature_classes.rb +9 -59
  25. data/lib/rgeo/cartesian/feature_methods.rb +15 -45
  26. data/lib/rgeo/cartesian/interface.rb +6 -17
  27. data/lib/rgeo/coord_sys.rb +9 -15
  28. data/lib/rgeo/coord_sys/cs/entities.rb +84 -330
  29. data/lib/rgeo/coord_sys/cs/factories.rb +2 -32
  30. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +52 -80
  31. data/lib/rgeo/coord_sys/proj4.rb +28 -67
  32. data/lib/rgeo/coord_sys/proj4_c_impl.bundle +0 -0
  33. data/lib/rgeo/coord_sys/srs_database/interface.rb +4 -24
  34. data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +20 -38
  35. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +6 -22
  36. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +6 -21
  37. data/lib/rgeo/error.rb +0 -6
  38. data/lib/rgeo/feature.rb +18 -23
  39. data/lib/rgeo/feature/curve.rb +0 -14
  40. data/lib/rgeo/feature/factory.rb +13 -38
  41. data/lib/rgeo/feature/factory_generator.rb +4 -16
  42. data/lib/rgeo/feature/geometry.rb +18 -60
  43. data/lib/rgeo/feature/geometry_collection.rb +3 -17
  44. data/lib/rgeo/feature/line.rb +0 -10
  45. data/lib/rgeo/feature/line_string.rb +1 -13
  46. data/lib/rgeo/feature/linear_ring.rb +0 -9
  47. data/lib/rgeo/feature/mixins.rb +11 -36
  48. data/lib/rgeo/feature/multi_curve.rb +0 -11
  49. data/lib/rgeo/feature/multi_line_string.rb +0 -9
  50. data/lib/rgeo/feature/multi_point.rb +0 -9
  51. data/lib/rgeo/feature/multi_polygon.rb +0 -9
  52. data/lib/rgeo/feature/multi_surface.rb +0 -12
  53. data/lib/rgeo/feature/point.rb +0 -13
  54. data/lib/rgeo/feature/polygon.rb +1 -14
  55. data/lib/rgeo/feature/surface.rb +0 -12
  56. data/lib/rgeo/feature/types.rb +19 -61
  57. data/lib/rgeo/geographic.rb +10 -15
  58. data/lib/rgeo/geographic/factory.rb +126 -147
  59. data/lib/rgeo/geographic/interface.rb +67 -81
  60. data/lib/rgeo/geographic/proj4_projector.rb +13 -37
  61. data/lib/rgeo/geographic/projected_feature_classes.rb +7 -66
  62. data/lib/rgeo/geographic/projected_feature_methods.rb +15 -80
  63. data/lib/rgeo/geographic/projected_window.rb +15 -67
  64. data/lib/rgeo/geographic/simple_mercator_projector.rb +32 -56
  65. data/lib/rgeo/geographic/spherical_feature_classes.rb +9 -68
  66. data/lib/rgeo/geographic/spherical_feature_methods.rb +18 -51
  67. data/lib/rgeo/geographic/spherical_math.rb +26 -51
  68. data/lib/rgeo/geos.rb +23 -20
  69. data/lib/rgeo/geos/capi_factory.rb +125 -131
  70. data/lib/rgeo/geos/capi_feature_classes.rb +21 -88
  71. data/lib/rgeo/geos/ffi_factory.rb +90 -143
  72. data/lib/rgeo/geos/ffi_feature_classes.rb +8 -63
  73. data/lib/rgeo/geos/ffi_feature_methods.rb +46 -162
  74. data/lib/rgeo/geos/geos_c_impl.bundle +0 -0
  75. data/lib/rgeo/geos/interface.rb +4 -23
  76. data/lib/rgeo/geos/utils.rb +4 -19
  77. data/lib/rgeo/geos/zm_factory.rb +82 -131
  78. data/lib/rgeo/geos/zm_feature_classes.rb +8 -63
  79. data/lib/rgeo/geos/zm_feature_methods.rb +34 -107
  80. data/lib/rgeo/impl_helper.rb +8 -13
  81. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +27 -71
  82. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +10 -28
  83. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +21 -57
  84. data/lib/rgeo/impl_helper/basic_point_methods.rb +12 -30
  85. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +9 -28
  86. data/lib/rgeo/impl_helper/math.rb +4 -10
  87. data/lib/rgeo/impl_helper/utils.rb +2 -10
  88. data/lib/rgeo/version.rb +1 -1
  89. data/lib/rgeo/wkrep.rb +4 -9
  90. data/lib/rgeo/wkrep/wkb_generator.rb +22 -46
  91. data/lib/rgeo/wkrep/wkb_parser.rb +25 -52
  92. data/lib/rgeo/wkrep/wkt_generator.rb +39 -69
  93. data/lib/rgeo/wkrep/wkt_parser.rb +52 -89
  94. data/lib/rgeo/yaml.rb +1 -7
  95. data/test/common/factory_tests.rb +4 -19
  96. data/test/common/geometry_collection_tests.rb +6 -39
  97. data/test/common/line_string_tests.rb +10 -39
  98. data/test/common/multi_line_string_tests.rb +10 -30
  99. data/test/common/multi_point_tests.rb +15 -34
  100. data/test/common/multi_polygon_tests.rb +26 -28
  101. data/test/common/point_tests.rb +37 -59
  102. data/test/common/polygon_tests.rb +16 -25
  103. data/test/coord_sys/tc_ogc_cs.rb +151 -186
  104. data/test/coord_sys/tc_proj4.rb +35 -60
  105. data/test/coord_sys/tc_proj4_srs_data.rb +15 -24
  106. data/test/coord_sys/tc_sr_org.rb +11 -19
  107. data/test/coord_sys/tc_url_reader.rb +13 -23
  108. data/test/geos_capi/tc_factory.rb +7 -16
  109. data/test/geos_capi/tc_geometry_collection.rb +6 -14
  110. data/test/geos_capi/tc_line_string.rb +7 -15
  111. data/test/geos_capi/tc_misc.rb +26 -41
  112. data/test/geos_capi/tc_multi_line_string.rb +6 -14
  113. data/test/geos_capi/tc_multi_point.rb +7 -15
  114. data/test/geos_capi/tc_multi_polygon.rb +8 -18
  115. data/test/geos_capi/tc_parsing_unparsing.rb +11 -21
  116. data/test/geos_capi/tc_point.rb +12 -26
  117. data/test/geos_capi/tc_polygon.rb +52 -17
  118. data/test/geos_capi/tc_zmfactory.rb +7 -18
  119. data/test/geos_ffi/tc_factory.rb +7 -16
  120. data/test/geos_ffi/tc_geometry_collection.rb +7 -15
  121. data/test/geos_ffi/tc_line_string.rb +7 -15
  122. data/test/geos_ffi/tc_misc.rb +8 -18
  123. data/test/geos_ffi/tc_multi_line_string.rb +7 -15
  124. data/test/geos_ffi/tc_multi_point.rb +8 -16
  125. data/test/geos_ffi/tc_multi_polygon.rb +9 -18
  126. data/test/geos_ffi/tc_parsing_unparsing.rb +14 -24
  127. data/test/geos_ffi/tc_point.rb +13 -28
  128. data/test/geos_ffi/tc_polygon.rb +7 -17
  129. data/test/geos_ffi/tc_zmfactory.rb +8 -19
  130. data/test/projected_geographic/tc_factory.rb +7 -15
  131. data/test/projected_geographic/tc_geometry_collection.rb +7 -15
  132. data/test/projected_geographic/tc_line_string.rb +7 -15
  133. data/test/projected_geographic/tc_multi_line_string.rb +7 -16
  134. data/test/projected_geographic/tc_multi_point.rb +8 -17
  135. data/test/projected_geographic/tc_multi_polygon.rb +8 -16
  136. data/test/projected_geographic/tc_point.rb +11 -23
  137. data/test/projected_geographic/tc_polygon.rb +7 -15
  138. data/test/simple_cartesian/tc_calculations.rb +6 -22
  139. data/test/simple_cartesian/tc_factory.rb +7 -16
  140. data/test/simple_cartesian/tc_geometry_collection.rb +6 -15
  141. data/test/simple_cartesian/tc_line_string.rb +6 -15
  142. data/test/simple_cartesian/tc_multi_line_string.rb +6 -15
  143. data/test/simple_cartesian/tc_multi_point.rb +7 -16
  144. data/test/simple_cartesian/tc_multi_polygon.rb +7 -16
  145. data/test/simple_cartesian/tc_point.rb +10 -21
  146. data/test/simple_cartesian/tc_polygon.rb +6 -15
  147. data/test/simple_mercator/tc_factory.rb +6 -14
  148. data/test/simple_mercator/tc_geometry_collection.rb +6 -14
  149. data/test/simple_mercator/tc_line_string.rb +6 -14
  150. data/test/simple_mercator/tc_multi_line_string.rb +6 -15
  151. data/test/simple_mercator/tc_multi_point.rb +7 -16
  152. data/test/simple_mercator/tc_multi_polygon.rb +7 -15
  153. data/test/simple_mercator/tc_point.rb +11 -24
  154. data/test/simple_mercator/tc_polygon.rb +6 -14
  155. data/test/simple_mercator/tc_window.rb +10 -34
  156. data/test/spherical_geographic/tc_calculations.rb +5 -32
  157. data/test/spherical_geographic/tc_factory.rb +6 -15
  158. data/test/spherical_geographic/tc_geometry_collection.rb +6 -15
  159. data/test/spherical_geographic/tc_line_string.rb +6 -15
  160. data/test/spherical_geographic/tc_multi_line_string.rb +6 -15
  161. data/test/spherical_geographic/tc_multi_point.rb +7 -16
  162. data/test/spherical_geographic/tc_multi_polygon.rb +7 -16
  163. data/test/spherical_geographic/tc_point.rb +10 -22
  164. data/test/spherical_geographic/tc_polygon.rb +6 -15
  165. data/test/tc_cartesian_analysis.rb +4 -16
  166. data/test/tc_cartesian_bbox.rb +7 -21
  167. data/test/tc_mixins.rb +8 -25
  168. data/test/tc_oneoff.rb +5 -13
  169. data/test/tc_types.rb +7 -16
  170. data/test/wkrep/tc_wkb_generator.rb +63 -97
  171. data/test/wkrep/tc_wkb_parser.rb +63 -100
  172. data/test/wkrep/tc_wkt_generator.rb +54 -92
  173. data/test/wkrep/tc_wkt_parser.rb +84 -133
  174. metadata +39 -9
  175. data/lib/rgeo/coord_sys/srs_database/active_record_table.rb +0 -166
  176. data/test/coord_sys/tc_active_record_table.rb +0 -79
@@ -5,134 +5,79 @@
5
5
  # -----------------------------------------------------------------------------
6
6
 
7
7
  module RGeo
8
-
9
8
  module Geos
10
-
11
-
12
- class FFIGeometryImpl # :nodoc:
13
-
14
-
9
+ class FFIGeometryImpl # :nodoc:
15
10
  include FFIGeometryMethods
16
11
 
17
12
  Feature::MixinCollection::GLOBAL.for_type(Feature::Geometry).include_in_class(self, true)
18
-
19
-
20
13
  end
21
14
 
22
-
23
- class FFIPointImpl # :nodoc:
24
-
25
-
15
+ class FFIPointImpl # :nodoc:
26
16
  include FFIGeometryMethods
27
17
  include FFIPointMethods
28
18
 
29
19
  Feature::MixinCollection::GLOBAL.for_type(Feature::Point).include_in_class(self, true)
30
-
31
-
32
20
  end
33
21
 
34
-
35
22
  class FFILineStringImpl # :nodoc:
36
-
37
-
38
23
  include FFIGeometryMethods
39
24
  include FFILineStringMethods
40
25
 
41
26
  Feature::MixinCollection::GLOBAL.for_type(Feature::LineString).include_in_class(self, true)
42
-
43
-
44
27
  end
45
28
 
46
-
47
29
  class FFILinearRingImpl # :nodoc:
48
-
49
-
50
30
  include FFIGeometryMethods
51
31
  include FFILineStringMethods
52
32
  include FFILinearRingMethods
53
33
 
54
34
  Feature::MixinCollection::GLOBAL.for_type(Feature::LinearRing).include_in_class(self, true)
55
-
56
-
57
35
  end
58
36
 
59
-
60
- class FFILineImpl # :nodoc:
61
-
62
-
37
+ class FFILineImpl # :nodoc:
63
38
  include FFIGeometryMethods
64
39
  include FFILineStringMethods
65
40
  include FFILineMethods
66
41
 
67
42
  Feature::MixinCollection::GLOBAL.for_type(Feature::Line).include_in_class(self, true)
68
-
69
-
70
43
  end
71
44
 
72
-
73
- class FFIPolygonImpl # :nodoc:
74
-
75
-
45
+ class FFIPolygonImpl # :nodoc:
76
46
  include FFIGeometryMethods
77
47
  include FFIPolygonMethods
78
48
 
79
49
  Feature::MixinCollection::GLOBAL.for_type(Feature::Polygon).include_in_class(self, true)
80
-
81
-
82
50
  end
83
51
 
84
-
85
- class FFIGeometryCollectionImpl # :nodoc:
86
-
87
-
52
+ class FFIGeometryCollectionImpl # :nodoc:
88
53
  include FFIGeometryMethods
89
54
  include FFIGeometryCollectionMethods
90
55
 
91
56
  Feature::MixinCollection::GLOBAL.for_type(Feature::GeometryCollection).include_in_class(self, true)
92
-
93
-
94
57
  end
95
58
 
96
-
97
- class FFIMultiPointImpl # :nodoc:
98
-
99
-
59
+ class FFIMultiPointImpl # :nodoc:
100
60
  include FFIGeometryMethods
101
61
  include FFIGeometryCollectionMethods
102
62
  include FFIMultiPointMethods
103
63
 
104
64
  Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPoint).include_in_class(self, true)
105
-
106
-
107
65
  end
108
66
 
109
-
110
- class FFIMultiLineStringImpl # :nodoc:
111
-
112
-
67
+ class FFIMultiLineStringImpl # :nodoc:
113
68
  include FFIGeometryMethods
114
69
  include FFIGeometryCollectionMethods
115
70
  include FFIMultiLineStringMethods
116
71
 
117
72
  Feature::MixinCollection::GLOBAL.for_type(Feature::MultiLineString).include_in_class(self, true)
118
-
119
-
120
73
  end
121
74
 
122
-
123
- class FFIMultiPolygonImpl # :nodoc:
124
-
125
-
75
+ class FFIMultiPolygonImpl # :nodoc:
126
76
  include FFIGeometryMethods
127
77
  include FFIGeometryCollectionMethods
128
78
  include FFIMultiPolygonMethods
129
79
 
130
80
  Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPolygon).include_in_class(self, true)
131
-
132
-
133
81
  end
134
-
135
-
136
82
  end
137
-
138
83
  end
@@ -5,15 +5,10 @@
5
5
  # -----------------------------------------------------------------------------
6
6
 
7
7
  module RGeo
8
-
9
8
  module Geos
10
-
11
-
12
- module FFIGeometryMethods # :nodoc:
13
-
9
+ module FFIGeometryMethods # :nodoc:
14
10
  include Feature::Instance
15
11
 
16
-
17
12
  def initialize(factory_, fg_geom_, klasses_)
18
13
  @factory = factory_
19
14
  @fg_geom = fg_geom_
@@ -22,19 +17,17 @@ module RGeo
22
17
  fg_geom_.srid = factory_.srid
23
18
  end
24
19
 
25
-
26
20
  def inspect
27
21
  "#<#{self.class}:0x#{object_id.to_s(16)} #{as_text.inspect}>"
28
22
  end
29
23
 
30
-
31
24
  # Marshal support
32
25
 
33
- def marshal_dump # :nodoc:
26
+ def marshal_dump # :nodoc:
34
27
  [@factory, @factory._write_for_marshal(self)]
35
28
  end
36
29
 
37
- def marshal_load(data_) # :nodoc:
30
+ def marshal_load(data_) # :nodoc:
38
31
  @factory = data_[0]
39
32
  @fg_geom = @factory._read_for_marshal(data_[1])
40
33
  @fg_geom.srid = @factory.srid
@@ -42,31 +35,28 @@ module RGeo
42
35
  @_klasses = nil
43
36
  end
44
37
 
45
-
46
38
  # Psych support
47
39
 
48
- def encode_with(coder_) # :nodoc:
49
- coder_['factory'] = @factory
40
+ def encode_with(coder_) # :nodoc:
41
+ coder_["factory"] = @factory
50
42
  str_ = @factory._write_for_psych(self)
51
- str_ = str_.encode('US-ASCII') if str_.respond_to?(:encode)
52
- coder_['wkt'] = str_
43
+ str_ = str_.encode("US-ASCII") if str_.respond_to?(:encode)
44
+ coder_["wkt"] = str_
53
45
  end
54
46
 
55
47
  def init_with(coder_) # :nodoc:
56
- @factory = coder_['factory']
57
- @fg_geom = @factory._read_for_psych(coder_['wkt'])
48
+ @factory = coder_["factory"]
49
+ @fg_geom = @factory._read_for_psych(coder_["wkt"])
58
50
  @fg_geom.srid = @factory.srid
59
51
  @_fg_prep = @factory._auto_prepare ? 1 : 0
60
52
  @_klasses = nil
61
53
  end
62
54
 
63
-
64
55
  attr_reader :factory
65
56
  attr_reader :fg_geom
66
57
 
67
58
  attr_reader :_klasses # :nodoc:
68
59
 
69
-
70
60
  def initialize_copy(orig_)
71
61
  @factory = orig_.factory
72
62
  @fg_geom = orig_.fg_geom.clone
@@ -75,27 +65,22 @@ module RGeo
75
65
  @_klasses = orig_._klasses
76
66
  end
77
67
 
78
-
79
68
  def srid
80
69
  @fg_geom.srid
81
70
  end
82
71
 
83
-
84
72
  def dimension
85
73
  Utils.ffi_compute_dimension(@fg_geom)
86
74
  end
87
75
 
88
-
89
76
  def geometry_type
90
77
  Feature::Geometry
91
78
  end
92
79
 
93
-
94
80
  def prepared?
95
81
  !@_fg_prep.is_a?(::Integer)
96
82
  end
97
83
 
98
-
99
84
  def prepare!
100
85
  if @_fg_prep.is_a?(::Integer)
101
86
  @_fg_prep = ::Geos::PreparedGeometry.new(@fg_geom)
@@ -103,12 +88,10 @@ module RGeo
103
88
  self
104
89
  end
105
90
 
106
-
107
91
  def envelope
108
92
  @factory._wrap_fg_geom(@fg_geom.envelope, nil)
109
93
  end
110
94
 
111
-
112
95
  def boundary
113
96
  if self.class == FFIGeometryCollectionImpl
114
97
  nil
@@ -117,32 +100,27 @@ module RGeo
117
100
  end
118
101
  end
119
102
 
120
-
121
103
  def as_text
122
104
  str_ = @factory._generate_wkt(self)
123
- str_.force_encoding('US-ASCII') if str_.respond_to?(:force_encoding)
105
+ str_.force_encoding("US-ASCII") if str_.respond_to?(:force_encoding)
124
106
  str_
125
107
  end
126
108
  alias_method :to_s, :as_text
127
109
 
128
-
129
110
  def as_binary
130
111
  @factory._generate_wkb(self)
131
112
  end
132
113
 
133
-
134
114
  def is_empty?
135
115
  @fg_geom.empty?
136
116
  end
137
117
 
138
-
139
118
  def is_simple?
140
119
  @fg_geom.simple?
141
120
  end
142
121
 
143
-
144
122
  def equals?(rhs_)
145
- return false unless rhs_.kind_of?(::RGeo::Feature::Instance)
123
+ return false unless rhs_.is_a?(::RGeo::Feature::Instance)
146
124
  fg_ = factory._convert_to_fg_geometry(rhs_)
147
125
  if !fg_
148
126
  false
@@ -156,7 +134,6 @@ module RGeo
156
134
  end
157
135
  alias_method :==, :equals?
158
136
 
159
-
160
137
  def disjoint?(rhs_)
161
138
  fg_ = factory._convert_to_fg_geometry(rhs_)
162
139
  if fg_
@@ -167,7 +144,6 @@ module RGeo
167
144
  end
168
145
  end
169
146
 
170
-
171
147
  def intersects?(rhs_)
172
148
  fg_ = factory._convert_to_fg_geometry(rhs_)
173
149
  if fg_
@@ -178,7 +154,6 @@ module RGeo
178
154
  end
179
155
  end
180
156
 
181
-
182
157
  def touches?(rhs_)
183
158
  fg_ = factory._convert_to_fg_geometry(rhs_)
184
159
  if fg_
@@ -189,7 +164,6 @@ module RGeo
189
164
  end
190
165
  end
191
166
 
192
-
193
167
  def crosses?(rhs_)
194
168
  fg_ = factory._convert_to_fg_geometry(rhs_)
195
169
  if fg_
@@ -200,7 +174,6 @@ module RGeo
200
174
  end
201
175
  end
202
176
 
203
-
204
177
  def within?(rhs_)
205
178
  fg_ = factory._convert_to_fg_geometry(rhs_)
206
179
  if fg_
@@ -211,7 +184,6 @@ module RGeo
211
184
  end
212
185
  end
213
186
 
214
-
215
187
  def contains?(rhs_)
216
188
  fg_ = factory._convert_to_fg_geometry(rhs_)
217
189
  if fg_
@@ -222,7 +194,6 @@ module RGeo
222
194
  end
223
195
  end
224
196
 
225
-
226
197
  def overlaps?(rhs_)
227
198
  fg_ = factory._convert_to_fg_geometry(rhs_)
228
199
  if fg_
@@ -233,30 +204,25 @@ module RGeo
233
204
  end
234
205
  end
235
206
 
236
-
237
207
  def relate?(rhs_, pattern_)
238
208
  fg_ = factory._convert_to_fg_geometry(rhs_)
239
209
  fg_ ? @fg_geom.relate_pattern(fg_, pattern_) : nil
240
210
  end
241
- alias_method :relate, :relate? # DEPRECATED
242
-
211
+ alias_method :relate, :relate? # DEPRECATED
243
212
 
244
213
  def distance(rhs_)
245
214
  fg_ = factory._convert_to_fg_geometry(rhs_)
246
215
  fg_ ? @fg_geom.distance(fg_) : nil
247
216
  end
248
217
 
249
-
250
218
  def buffer(distance_)
251
219
  @factory._wrap_fg_geom(@fg_geom.buffer(distance_, @factory.buffer_resolution), nil)
252
220
  end
253
221
 
254
-
255
222
  def convex_hull
256
223
  @factory._wrap_fg_geom(@fg_geom.convex_hull, nil)
257
224
  end
258
225
 
259
-
260
226
  def intersection(rhs_)
261
227
  fg_ = factory._convert_to_fg_geometry(rhs_)
262
228
  fg_ ? @factory._wrap_fg_geom(@fg_geom.intersection(fg_), nil) : nil
@@ -264,7 +230,6 @@ module RGeo
264
230
 
265
231
  alias_method :*, :intersection
266
232
 
267
-
268
233
  def union(rhs_)
269
234
  fg_ = factory._convert_to_fg_geometry(rhs_)
270
235
  fg_ ? @factory._wrap_fg_geom(@fg_geom.union(fg_), nil) : nil
@@ -272,7 +237,6 @@ module RGeo
272
237
 
273
238
  alias_method :+, :union
274
239
 
275
-
276
240
  def difference(rhs_)
277
241
  fg_ = factory._convert_to_fg_geometry(rhs_)
278
242
  fg_ ? @factory._wrap_fg_geom(@fg_geom.difference(fg_), nil) : nil
@@ -280,26 +244,22 @@ module RGeo
280
244
 
281
245
  alias_method :-, :difference
282
246
 
283
-
284
247
  def sym_difference(rhs_)
285
248
  fg_ = factory._convert_to_fg_geometry(rhs_)
286
249
  fg_ ? @factory._wrap_fg_geom(@fg_geom.sym_difference(fg_), nil) : nil
287
250
  end
288
251
 
289
-
290
252
  def eql?(rhs_)
291
253
  rep_equals?(rhs_)
292
254
  end
293
255
 
294
-
295
- def _detach_fg_geom # :nodoc:
256
+ def _detach_fg_geom # :nodoc:
296
257
  fg_ = @fg_geom
297
258
  @fg_geom = nil
298
259
  fg_
299
260
  end
300
261
 
301
-
302
- def _request_prepared # :nodoc:
262
+ def _request_prepared # :nodoc:
303
263
  case @_fg_prep
304
264
  when 0
305
265
  nil
@@ -312,79 +272,59 @@ module RGeo
312
272
  @_fg_prep
313
273
  end
314
274
  end
315
-
316
-
317
275
  end
318
276
 
319
-
320
- module FFIPointMethods # :nodoc:
321
-
322
-
277
+ module FFIPointMethods # :nodoc:
323
278
  def x
324
279
  @fg_geom.coord_seq.get_x(0)
325
280
  end
326
281
 
327
-
328
282
  def y
329
283
  @fg_geom.coord_seq.get_y(0)
330
284
  end
331
285
 
332
-
333
286
  def z
334
- if @factory.property(:has_z_coordinate)
335
- @fg_geom.coord_seq.get_z(0)
336
- else
337
- nil
338
- end
287
+ @fg_geom.coord_seq.get_z(0) if @factory.property(:has_z_coordinate)
339
288
  end
340
289
 
341
-
342
290
  def m
343
- if @factory.property(:has_m_coordinate)
344
- @fg_geom.coord_seq.get_z(0)
345
- else
346
- nil
347
- end
291
+ @fg_geom.coord_seq.get_z(0) if @factory.property(:has_m_coordinate)
348
292
  end
349
293
 
350
-
351
294
  def geometry_type
352
295
  Feature::Point
353
296
  end
354
297
 
355
-
356
298
  def rep_equals?(rhs_)
357
299
  rhs_.class == self.class && rhs_.factory.eql?(@factory) &&
358
300
  Utils.ffi_coord_seqs_equal?(rhs_.fg_geom.coord_seq, @fg_geom.coord_seq, @factory._has_3d)
359
301
  end
360
302
 
361
-
362
303
  def hash
363
304
  @hash ||= Utils.ffi_coord_seq_hash(@fg_geom.coord_seq, [@factory, geometry_type].hash)
364
305
  end
365
306
 
366
-
307
+ def coordinates
308
+ [x, y].tap do |coords|
309
+ coords << z if @factory.property(:has_z_coordinate)
310
+ coords << m if @factory.property(:has_m_coordinate)
311
+ end
312
+ end
367
313
  end
368
314
 
369
-
370
315
  module FFILineStringMethods # :nodoc:
371
-
372
-
373
316
  def geometry_type
374
317
  Feature::LineString
375
318
  end
376
319
 
377
-
378
320
  def length
379
321
  @fg_geom.length
380
322
  end
381
323
 
382
-
383
324
  def num_points
384
325
  @fg_geom.num_points
385
326
  end
386
327
 
387
-
388
328
  def point_n(n_)
389
329
  if n_ >= 0 && n_ < @fg_geom.num_points
390
330
  coord_seq_ = @fg_geom.coord_seq
@@ -392,22 +332,17 @@ module RGeo
392
332
  y_ = coord_seq_.get_y(n_)
393
333
  extra_ = @factory._has_3d ? [coord_seq_.get_z(n_)] : []
394
334
  @factory.point(x_, y_, *extra_)
395
- else
396
- nil
397
335
  end
398
336
  end
399
337
 
400
-
401
338
  def start_point
402
339
  point_n(0)
403
340
  end
404
341
 
405
-
406
342
  def end_point
407
343
  point_n(@fg_geom.num_points - 1)
408
344
  end
409
345
 
410
-
411
346
  def points
412
347
  coord_seq_ = @fg_geom.coord_seq
413
348
  has_3d_ = @factory._has_3d
@@ -419,106 +354,80 @@ module RGeo
419
354
  end
420
355
  end
421
356
 
422
-
423
357
  def is_closed?
424
358
  @fg_geom.closed?
425
359
  end
426
360
 
427
-
428
361
  def is_ring?
429
362
  @fg_geom.ring?
430
363
  end
431
364
 
432
-
433
365
  def rep_equals?(rhs_)
434
366
  rhs_.class == self.class && rhs_.factory.eql?(@factory) &&
435
367
  Utils.ffi_coord_seqs_equal?(rhs_.fg_geom.coord_seq, @fg_geom.coord_seq, @factory._has_3d)
436
368
  end
437
369
 
438
-
439
370
  def hash
440
371
  @hash ||= Utils.ffi_coord_seq_hash(@fg_geom.coord_seq, [@factory, geometry_type].hash)
441
372
  end
442
373
 
443
-
374
+ def coordinates
375
+ points.map(&:coordinates)
376
+ end
444
377
  end
445
378
 
446
-
447
379
  module FFILinearRingMethods # :nodoc:
448
-
449
-
450
380
  def geometry_type
451
381
  Feature::LinearRing
452
382
  end
453
-
454
-
455
383
  end
456
384
 
457
-
458
- module FFILineMethods # :nodoc:
459
-
460
-
385
+ module FFILineMethods # :nodoc:
461
386
  def geometry_type
462
387
  Feature::Line
463
388
  end
464
-
465
-
466
389
  end
467
390
 
468
-
469
- module FFIPolygonMethods # :nodoc:
470
-
471
-
391
+ module FFIPolygonMethods # :nodoc:
472
392
  def geometry_type
473
393
  Feature::Polygon
474
394
  end
475
395
 
476
-
477
396
  def area
478
397
  @fg_geom.area
479
398
  end
480
399
 
481
-
482
400
  def centroid
483
401
  @factory._wrap_fg_geom(@fg_geom.centroid, FFIPointImpl)
484
402
  end
485
403
 
486
-
487
404
  def point_on_surface
488
405
  @factory._wrap_fg_geom(@fg_geom.point_on_surface, FFIPointImpl)
489
406
  end
490
407
 
491
-
492
408
  def exterior_ring
493
409
  @factory._wrap_fg_geom(@fg_geom.exterior_ring, FFILinearRingImpl)
494
410
  end
495
411
 
496
-
497
412
  def num_interior_rings
498
413
  @fg_geom.num_interior_rings
499
414
  end
500
415
 
501
-
502
416
  def interior_ring_n(n_)
503
417
  if n_ >= 0 && n_ < @fg_geom.num_interior_rings
504
418
  @factory._wrap_fg_geom(@fg_geom.interior_ring_n(n_), FFILinearRingImpl)
505
- else
506
- nil
507
419
  end
508
420
  end
509
421
 
510
-
511
422
  def interior_rings
512
423
  ::Array.new(@fg_geom.num_interior_rings) do |n_|
513
424
  @factory._wrap_fg_geom(@fg_geom.interior_ring_n(n_), FFILinearRingImpl)
514
425
  end
515
426
  end
516
427
 
517
-
518
428
  def rep_equals?(rhs_)
519
429
  if rhs_.class == self.class && rhs_.factory.eql?(@factory) &&
520
- rhs_.exterior_ring.rep_equals?(self.exterior_ring)
521
- then
430
+ rhs_.exterior_ring.rep_equals?(exterior_ring)
522
431
  sn_ = @fg_geom.num_interior_rings
523
432
  rn_ = rhs_.num_interior_rings
524
433
  if sn_ == rn_
@@ -531,7 +440,6 @@ module RGeo
531
440
  false
532
441
  end
533
442
 
534
-
535
443
  def hash
536
444
  @hash ||= begin
537
445
  hash_ = Utils.ffi_coord_seq_hash(@fg_geom.exterior_ring.coord_seq,
@@ -542,18 +450,16 @@ module RGeo
542
450
  end
543
451
  end
544
452
 
545
-
453
+ def coordinates
454
+ ([exterior_ring] + interior_rings).map(&:coordinates)
455
+ end
546
456
  end
547
457
 
548
-
549
- module FFIGeometryCollectionMethods # :nodoc:
550
-
551
-
458
+ module FFIGeometryCollectionMethods # :nodoc:
552
459
  def geometry_type
553
460
  Feature::GeometryCollection
554
461
  end
555
462
 
556
-
557
463
  def rep_equals?(rhs_)
558
464
  if rhs_.class == self.class && rhs_.factory.eql?(@factory)
559
465
  size_ = @fg_geom.num_geometries
@@ -567,44 +473,35 @@ module RGeo
567
473
  false
568
474
  end
569
475
 
570
-
571
476
  def num_geometries
572
477
  @fg_geom.num_geometries
573
478
  end
574
479
  alias_method :size, :num_geometries
575
480
 
576
-
577
481
  def geometry_n(n_)
578
482
  if n_ >= 0 && n_ < @fg_geom.num_geometries
579
483
  @factory._wrap_fg_geom(@fg_geom.get_geometry_n(n_),
580
484
  @_klasses ? @_klasses[n_] : nil)
581
- else
582
- nil
583
485
  end
584
486
  end
585
487
 
586
-
587
488
  def [](n_)
588
489
  n_ += @fg_geom.num_geometries if n_ < 0
589
490
  if n_ >= 0 && n_ < @fg_geom.num_geometries
590
491
  @factory._wrap_fg_geom(@fg_geom.get_geometry_n(n_),
591
492
  @_klasses ? @_klasses[n_] : nil)
592
- else
593
- nil
594
493
  end
595
494
  end
596
495
 
597
-
598
496
  def hash
599
497
  @hash ||= begin
600
498
  hash_ = [@factory, geometry_type].hash
601
499
  (0...num_geometries).inject(hash_) do |h_, i_|
602
- (1664525 * h_ + geometry_n(i_).hash).hash
500
+ (1_664_525 * h_ + geometry_n(i_).hash).hash
603
501
  end
604
502
  end
605
503
  end
606
504
 
607
-
608
505
  def each
609
506
  if block_given?
610
507
  @fg_geom.num_geometries.times do |n_|
@@ -618,35 +515,27 @@ module RGeo
618
515
  end
619
516
 
620
517
  include ::Enumerable
621
-
622
-
623
518
  end
624
519
 
625
-
626
- module FFIMultiPointMethods # :nodoc:
627
-
628
-
520
+ module FFIMultiPointMethods # :nodoc:
629
521
  def geometry_type
630
522
  Feature::MultiPoint
631
523
  end
632
524
 
633
-
525
+ def coordinates
526
+ each.map(&:coordinates)
527
+ end
634
528
  end
635
529
 
636
-
637
- module FFIMultiLineStringMethods # :nodoc:
638
-
639
-
530
+ module FFIMultiLineStringMethods # :nodoc:
640
531
  def geometry_type
641
532
  Feature::MultiLineString
642
533
  end
643
534
 
644
-
645
535
  def length
646
536
  @fg_geom.length
647
537
  end
648
538
 
649
-
650
539
  def is_closed?
651
540
  size_ = num_geometries
652
541
  size_.times do |n_|
@@ -655,36 +544,31 @@ module RGeo
655
544
  true
656
545
  end
657
546
 
658
-
547
+ def coordinates
548
+ each.map(&:coordinates)
549
+ end
659
550
  end
660
551
 
661
-
662
- module FFIMultiPolygonMethods # :nodoc:
663
-
664
-
552
+ module FFIMultiPolygonMethods # :nodoc:
665
553
  def geometry_type
666
554
  Feature::MultiPolygon
667
555
  end
668
556
 
669
-
670
557
  def area
671
558
  @fg_geom.area
672
559
  end
673
560
 
674
-
675
561
  def centroid
676
562
  @factory._wrap_fg_geom(@fg_geom.centroid, FFIPointImpl)
677
563
  end
678
564
 
679
-
680
565
  def point_on_surface
681
566
  @factory._wrap_fg_geom(@fg_geom.point_on_surface, FFIPointImpl)
682
567
  end
683
568
 
684
-
569
+ def coordinates
570
+ each.map(&:coordinates)
571
+ end
685
572
  end
686
-
687
-
688
573
  end
689
-
690
574
  end