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,20 +5,15 @@
5
5
  # -----------------------------------------------------------------------------
6
6
 
7
7
  module RGeo
8
-
9
-
10
- module ImplHelper # :nodoc:
8
+ module ImplHelper # :nodoc:
11
9
  end
12
-
13
-
14
10
  end
15
11
 
16
-
17
12
  # Implementation files
18
- require 'rgeo/impl_helper/utils'
19
- require 'rgeo/impl_helper/math'
20
- require 'rgeo/impl_helper/basic_geometry_methods'
21
- require 'rgeo/impl_helper/basic_geometry_collection_methods'
22
- require 'rgeo/impl_helper/basic_point_methods'
23
- require 'rgeo/impl_helper/basic_line_string_methods'
24
- require 'rgeo/impl_helper/basic_polygon_methods'
13
+ require "rgeo/impl_helper/utils"
14
+ require "rgeo/impl_helper/math"
15
+ require "rgeo/impl_helper/basic_geometry_methods"
16
+ require "rgeo/impl_helper/basic_geometry_collection_methods"
17
+ require "rgeo/impl_helper/basic_point_methods"
18
+ require "rgeo/impl_helper/basic_line_string_methods"
19
+ require "rgeo/impl_helper/basic_polygon_methods"
@@ -5,46 +5,34 @@
5
5
  # -----------------------------------------------------------------------------
6
6
 
7
7
  module RGeo
8
-
9
- module ImplHelper # :nodoc:
10
-
11
-
12
- module BasicGeometryCollectionMethods # :nodoc:
13
-
14
-
8
+ module ImplHelper # :nodoc:
9
+ module BasicGeometryCollectionMethods # :nodoc:
15
10
  def initialize(factory_, elements_)
16
11
  _set_factory(factory_)
17
12
  @elements = elements_.map do |elem_|
18
13
  elem_ = Feature.cast(elem_, factory_)
19
- unless elem_
20
- raise Error::InvalidGeometry, "Could not cast #{elem_}"
21
- end
14
+ raise Error::InvalidGeometry, "Could not cast #{elem_}" unless elem_
22
15
  elem_
23
16
  end
24
17
  _validate_geometry
25
18
  end
26
19
 
27
-
28
20
  def num_geometries
29
21
  @elements.size
30
22
  end
31
23
 
32
-
33
24
  def geometry_n(n_)
34
25
  n_ < 0 ? nil : @elements[n_]
35
26
  end
36
27
 
37
-
38
28
  def [](n_)
39
29
  @elements[n_]
40
30
  end
41
31
 
42
-
43
32
  def each(&block_)
44
33
  @elements.each(&block_)
45
34
  end
46
35
 
47
-
48
36
  def dimension
49
37
  unless defined?(@dimension)
50
38
  @dimension = -1
@@ -56,85 +44,67 @@ module RGeo
56
44
  @dimension
57
45
  end
58
46
 
59
-
60
47
  def geometry_type
61
48
  Feature::GeometryCollection
62
49
  end
63
50
 
64
-
65
51
  def is_empty?
66
52
  @elements.size == 0
67
53
  end
68
54
 
69
-
70
55
  def rep_equals?(rhs_)
71
56
  if rhs_.is_a?(self.class) && rhs_.factory.eql?(@factory) && @elements.size == rhs_.num_geometries
72
- rhs_.each_with_index{ |p_, i_| return false unless @elements[i_].rep_equals?(p_) }
57
+ rhs_.each_with_index { |p_, i_| return false unless @elements[i_].rep_equals?(p_) }
73
58
  else
74
59
  false
75
60
  end
76
61
  end
77
62
 
78
-
79
63
  def hash
80
64
  @hash ||= begin
81
65
  hash_ = [factory, geometry_type].hash
82
- @elements.inject(hash_){ |h_, g_| (1664525 * h_ + g_.hash).hash }
66
+ @elements.inject(hash_) { |h_, g_| (1_664_525 * h_ + g_.hash).hash }
83
67
  end
84
68
  end
85
69
 
86
-
87
- def _copy_state_from(obj_) # :nodoc:
70
+ def _copy_state_from(obj_) # :nodoc:
88
71
  super
89
72
  @elements = obj_._elements
90
73
  end
91
74
 
92
-
93
- def _elements # :nodoc:
75
+ def _elements # :nodoc:
94
76
  @elements
95
77
  end
96
-
97
-
98
78
  end
99
79
 
100
-
101
80
  module BasicMultiLineStringMethods # :nodoc:
102
-
103
-
104
81
  def initialize(factory_, elements_)
105
82
  _set_factory(factory_)
106
83
  @elements = elements_.map do |elem_|
107
84
  elem_ = Feature.cast(elem_, factory_, Feature::LineString, :keep_subtype)
108
- unless elem_
109
- raise Error::InvalidGeometry, "Could not cast #{elem_}"
110
- end
85
+ raise Error::InvalidGeometry, "Could not cast #{elem_}" unless elem_
111
86
  elem_
112
87
  end
113
88
  _validate_geometry
114
89
  end
115
90
 
116
-
117
91
  def geometry_type
118
92
  Feature::MultiLineString
119
93
  end
120
94
 
121
-
122
95
  def is_closed?
123
- all?{ |elem_| elem_.is_closed? }
96
+ all?(&:is_closed?)
124
97
  end
125
98
 
126
-
127
99
  def length
128
- @elements.inject(0.0){ |sum_, obj_| sum_ + obj_.length }
100
+ @elements.inject(0.0) { |sum_, obj_| sum_ + obj_.length }
129
101
  end
130
102
 
131
-
132
103
  def _add_boundary(hash_, point_) # :nodoc:
133
104
  hval_ = [point_.x, point_.y].hash
134
105
  (hash_[hval_] ||= [point_, 0])[1] += 1
135
106
  end
136
107
 
137
-
138
108
  def boundary
139
109
  hash_ = {}
140
110
  @elements.each do |line_|
@@ -144,86 +114,72 @@ module RGeo
144
114
  end
145
115
  end
146
116
  array_ = []
147
- hash_.each do |hval_, data_|
148
- array_ << data_[0] if data_[1] % 2 == 1
117
+ hash_.each do |_hval_, data_|
118
+ array_ << data_[0] if data_[1].odd?
149
119
  end
150
120
  factory.multi_point([array_])
151
121
  end
152
122
 
153
-
123
+ def coordinates
124
+ @elements.map(&:coordinates)
125
+ end
154
126
  end
155
127
 
156
-
157
- module BasicMultiPointMethods # :nodoc:
158
-
159
-
128
+ module BasicMultiPointMethods # :nodoc:
160
129
  def initialize(factory_, elements_)
161
130
  _set_factory(factory_)
162
131
  @elements = elements_.map do |elem_|
163
132
  elem_ = Feature.cast(elem_, factory_, Feature::Point, :keep_subtype)
164
- unless elem_
165
- raise Error::InvalidGeometry, "Could not cast #{elem_}"
166
- end
133
+ raise Error::InvalidGeometry, "Could not cast #{elem_}" unless elem_
167
134
  elem_
168
135
  end
169
136
  _validate_geometry
170
137
  end
171
138
 
172
-
173
139
  def geometry_type
174
140
  Feature::MultiPoint
175
141
  end
176
142
 
177
-
178
143
  def boundary
179
144
  factory.collection([])
180
145
  end
181
146
 
182
-
147
+ def coordinates
148
+ @elements.map(&:coordinates)
149
+ end
183
150
  end
184
151
 
185
-
186
- module BasicMultiPolygonMethods # :nodoc:
187
-
188
-
152
+ module BasicMultiPolygonMethods # :nodoc:
189
153
  def initialize(factory_, elements_)
190
154
  _set_factory(factory_)
191
155
  @elements = elements_.map do |elem_|
192
156
  elem_ = Feature.cast(elem_, factory_, Feature::Polygon, :keep_subtype)
193
- unless elem_
194
- raise Error::InvalidGeometry, "Could not cast #{elem_}"
195
- end
157
+ raise Error::InvalidGeometry, "Could not cast #{elem_}" unless elem_
196
158
  elem_
197
159
  end
198
160
  _validate_geometry
199
161
  end
200
162
 
201
-
202
163
  def geometry_type
203
164
  Feature::MultiPolygon
204
165
  end
205
166
 
206
-
207
167
  def area
208
- @elements.inject(0.0){ |sum_, obj_| sum_ + obj_.area }
168
+ @elements.inject(0.0) { |sum_, obj_| sum_ + obj_.area }
209
169
  end
210
170
 
211
-
212
171
  def boundary
213
172
  array_ = []
214
173
  @elements.each do |poly_|
215
- unless poly_.is_empty?
216
- array_ << poly_.exterior_ring
217
- end
174
+ array_ << poly_.exterior_ring unless poly_.is_empty?
218
175
  array_.concat(poly_.interior_rings)
219
176
  end
220
177
  factory.multi_line_string(array_)
221
178
  end
222
179
 
223
-
180
+ def coordinates
181
+ @elements.map(&:coordinates)
182
+ end
224
183
  end
225
-
226
-
227
184
  end
228
-
229
185
  end
@@ -5,54 +5,42 @@
5
5
  # -----------------------------------------------------------------------------
6
6
 
7
7
  module RGeo
8
-
9
- module ImplHelper # :nodoc:
10
-
11
-
12
- module BasicGeometryMethods # :nodoc:
13
-
8
+ module ImplHelper # :nodoc:
9
+ module BasicGeometryMethods # :nodoc:
14
10
  include Feature::Instance
15
11
 
16
-
17
- def inspect # :nodoc:
12
+ def inspect # :nodoc:
18
13
  "#<#{self.class}:0x#{object_id.to_s(16)} #{as_text.inspect}>"
19
14
  end
20
15
 
21
- def to_s # :nodoc:
16
+ def to_s # :nodoc:
22
17
  as_text
23
18
  end
24
19
 
25
-
26
- def _validate_geometry # :nodoc:
20
+ def _validate_geometry # :nodoc:
27
21
  end
28
22
 
29
-
30
23
  def _set_factory(factory_) # :nodoc:
31
24
  @factory = factory_
32
25
  end
33
26
 
34
-
35
27
  def factory
36
28
  @factory
37
29
  end
38
30
 
39
-
40
31
  def as_text
41
32
  @factory._generate_wkt(self)
42
33
  end
43
34
 
44
-
45
35
  def as_binary
46
36
  @factory._generate_wkb(self)
47
37
  end
48
38
 
49
-
50
39
  def _copy_state_from(obj_) # :nodoc:
51
40
  @factory = obj_.factory
52
41
  end
53
42
 
54
-
55
- def marshal_dump # :nodoc:
43
+ def marshal_dump # :nodoc:
56
44
  [@factory, @factory._marshal_wkb_generator.generate(self)]
57
45
  end
58
46
 
@@ -60,20 +48,14 @@ module RGeo
60
48
  _copy_state_from(data_[0]._marshal_wkb_parser.parse(data_[1]))
61
49
  end
62
50
 
63
-
64
51
  def encode_with(coder_) # :nodoc:
65
- coder_['factory'] = @factory
66
- coder_['wkt'] = @factory._psych_wkt_generator.generate(self)
52
+ coder_["factory"] = @factory
53
+ coder_["wkt"] = @factory._psych_wkt_generator.generate(self)
67
54
  end
68
55
 
69
- def init_with(coder_) # :nodoc:
70
- _copy_state_from(coder_['factory']._psych_wkt_parser.parse(coder_['wkt']))
56
+ def init_with(coder_) # :nodoc:
57
+ _copy_state_from(coder_["factory"]._psych_wkt_parser.parse(coder_["wkt"]))
71
58
  end
72
-
73
-
74
59
  end
75
-
76
-
77
60
  end
78
-
79
61
  end
@@ -5,82 +5,62 @@
5
5
  # -----------------------------------------------------------------------------
6
6
 
7
7
  module RGeo
8
-
9
- module ImplHelper # :nodoc:
10
-
11
-
12
- module BasicLineStringMethods # :nodoc:
13
-
14
-
8
+ module ImplHelper # :nodoc:
9
+ module BasicLineStringMethods # :nodoc:
15
10
  def initialize(factory_, points_)
16
11
  _set_factory(factory_)
17
12
  @points = points_.map do |elem_|
18
13
  elem_ = Feature.cast(elem_, factory_, Feature::Point)
19
- unless elem_
20
- raise Error::InvalidGeometry, "Could not cast #{elem_}"
21
- end
14
+ raise Error::InvalidGeometry, "Could not cast #{elem_}" unless elem_
22
15
  elem_
23
16
  end
24
17
  _validate_geometry
25
18
  end
26
19
 
27
-
28
20
  def _validate_geometry
29
21
  if @points.size == 1
30
- raise Error::InvalidGeometry, 'LineString cannot have 1 point'
22
+ raise Error::InvalidGeometry, "LineString cannot have 1 point"
31
23
  end
32
24
  end
33
25
 
34
-
35
26
  def num_points
36
27
  @points.size
37
28
  end
38
29
 
39
-
40
30
  def point_n(n_)
41
31
  n_ < 0 ? nil : @points[n_]
42
32
  end
43
33
 
44
-
45
34
  def points
46
35
  @points.dup
47
36
  end
48
37
 
49
-
50
38
  def dimension
51
39
  1
52
40
  end
53
41
 
54
-
55
42
  def geometry_type
56
43
  Feature::LineString
57
44
  end
58
45
 
59
-
60
46
  def is_empty?
61
47
  @points.size == 0
62
48
  end
63
49
 
64
-
65
50
  def boundary
66
51
  array_ = []
67
- if !is_empty? && !is_closed?
68
- array_ << @points.first << @points.last
69
- end
52
+ array_ << @points.first << @points.last if !is_empty? && !is_closed?
70
53
  factory.multi_point([array_])
71
54
  end
72
55
 
73
-
74
56
  def start_point
75
57
  @points.first
76
58
  end
77
59
 
78
-
79
60
  def end_point
80
61
  @points.last
81
62
  end
82
63
 
83
-
84
64
  def is_closed?
85
65
  unless defined?(@is_closed)
86
66
  @is_closed = @points.size > 2 && @points.first == @points.last
@@ -88,41 +68,36 @@ module RGeo
88
68
  @is_closed
89
69
  end
90
70
 
91
-
92
71
  def is_ring?
93
72
  is_closed? && is_simple?
94
73
  end
95
74
 
96
-
97
75
  def rep_equals?(rhs_)
98
76
  if rhs_.is_a?(self.class) && rhs_.factory.eql?(@factory) && @points.size == rhs_.num_points
99
- rhs_.points.each_with_index{ |p_, i_| return false unless @points[i_].rep_equals?(p_) }
77
+ rhs_.points.each_with_index { |p_, i_| return false unless @points[i_].rep_equals?(p_) }
100
78
  else
101
79
  false
102
80
  end
103
81
  end
104
82
 
105
-
106
83
  def hash
107
84
  @hash ||= begin
108
85
  hash_ = [factory, geometry_type].hash
109
- @points.inject(hash_){ |h_, p_| (1664525 * h_ + p_.hash).hash }
86
+ @points.inject(hash_) { |h_, p_| (1_664_525 * h_ + p_.hash).hash }
110
87
  end
111
88
  end
112
89
 
113
-
114
- def _copy_state_from(obj_) # :nodoc:
90
+ def _copy_state_from(obj_) # :nodoc:
115
91
  super
116
92
  @points = obj_.points
117
93
  end
118
94
 
119
-
95
+ def coordinates
96
+ @points.map(&:coordinates)
97
+ end
120
98
  end
121
99
 
122
-
123
- module BasicLineMethods # :nodoc:
124
-
125
-
100
+ module BasicLineMethods # :nodoc:
126
101
  def initialize(factory_, start_, end_)
127
102
  _set_factory(factory_)
128
103
  cstart_ = Feature.cast(start_, factory_, Feature::Point)
@@ -130,52 +105,41 @@ module RGeo
130
105
  raise Error::InvalidGeometry, "Could not cast start: #{start_}"
131
106
  end
132
107
  cend_ = Feature.cast(end_, factory_, Feature::Point)
133
- unless cend_
134
- raise Error::InvalidGeometry, "Could not cast end: #{end_}"
135
- end
108
+ raise Error::InvalidGeometry, "Could not cast end: #{end_}" unless cend_
136
109
  @points = [cstart_, cend_]
137
110
  _validate_geometry
138
111
  end
139
112
 
140
-
141
- def _validate_geometry # :nodoc:
113
+ def _validate_geometry # :nodoc:
142
114
  super
143
115
  if @points.size > 2
144
- raise Error::InvalidGeometry, 'Line must have 0 or 2 points'
116
+ raise Error::InvalidGeometry, "Line must have 0 or 2 points"
145
117
  end
146
118
  end
147
119
 
148
-
149
120
  def geometry_type
150
121
  Feature::Line
151
122
  end
152
123
 
153
-
124
+ def coordinates
125
+ @points.map(&:coordinates)
126
+ end
154
127
  end
155
128
 
156
-
157
- module BasicLinearRingMethods # :nodoc:
158
-
159
-
160
- def _validate_geometry # :nodoc:
129
+ module BasicLinearRingMethods # :nodoc:
130
+ def _validate_geometry # :nodoc:
161
131
  super
162
132
  if @points.size > 0
163
133
  @points << @points.first if @points.first != @points.last
164
134
  if !@factory.property(:uses_lenient_assertions) && !is_ring?
165
- raise Error::InvalidGeometry, 'LinearRing failed ring test'
135
+ raise Error::InvalidGeometry, "LinearRing failed ring test"
166
136
  end
167
137
  end
168
138
  end
169
139
 
170
-
171
140
  def geometry_type
172
141
  Feature::LinearRing
173
142
  end
174
-
175
-
176
143
  end
177
-
178
-
179
144
  end
180
-
181
145
  end