rgeo 3.0.0.pre.rc.3 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -3
  3. data/ext/geos_c_impl/extconf.rb +1 -0
  4. data/ext/geos_c_impl/factory.c +43 -5
  5. data/ext/geos_c_impl/factory.h +13 -2
  6. data/ext/geos_c_impl/geometry.c +178 -122
  7. data/ext/geos_c_impl/geometry_collection.c +17 -19
  8. data/ext/geos_c_impl/line_string.c +46 -36
  9. data/ext/geos_c_impl/point.c +0 -2
  10. data/ext/geos_c_impl/polygon.c +10 -11
  11. data/ext/geos_c_impl/polygon.h +1 -1
  12. data/ext/geos_c_impl/preface.h +3 -0
  13. data/ext/geos_c_impl/ruby_more.c +7 -0
  14. data/ext/geos_c_impl/ruby_more.h +8 -0
  15. data/lib/rgeo/cartesian/analysis.rb +5 -3
  16. data/lib/rgeo/cartesian/bounding_box.rb +74 -79
  17. data/lib/rgeo/cartesian/calculations.rb +20 -26
  18. data/lib/rgeo/cartesian/factory.rb +47 -49
  19. data/lib/rgeo/cartesian/planar_graph.rb +10 -16
  20. data/lib/rgeo/cartesian/sweepline_intersector.rb +1 -3
  21. data/lib/rgeo/cartesian/valid_op.rb +1 -3
  22. data/lib/rgeo/coord_sys/cs/entities.rb +91 -101
  23. data/lib/rgeo/coord_sys/cs/factories.rb +0 -2
  24. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +70 -29
  25. data/lib/rgeo/feature/curve.rb +0 -1
  26. data/lib/rgeo/feature/factory.rb +25 -27
  27. data/lib/rgeo/feature/factory_generator.rb +3 -4
  28. data/lib/rgeo/feature/geometry.rb +41 -30
  29. data/lib/rgeo/feature/geometry_collection.rb +3 -4
  30. data/lib/rgeo/feature/line_string.rb +1 -2
  31. data/lib/rgeo/feature/linear_ring.rb +0 -1
  32. data/lib/rgeo/feature/multi_curve.rb +0 -1
  33. data/lib/rgeo/feature/multi_surface.rb +0 -1
  34. data/lib/rgeo/feature/point.rb +0 -1
  35. data/lib/rgeo/feature/polygon.rb +1 -2
  36. data/lib/rgeo/feature/surface.rb +0 -1
  37. data/lib/rgeo/feature/types.rb +69 -85
  38. data/lib/rgeo/geographic/factory.rb +87 -80
  39. data/lib/rgeo/geographic/interface.rb +44 -27
  40. data/lib/rgeo/geographic/projected_feature_methods.rb +2 -6
  41. data/lib/rgeo/geographic/projected_window.rb +35 -21
  42. data/lib/rgeo/geographic/simple_mercator_projector.rb +27 -15
  43. data/lib/rgeo/geographic/spherical_feature_methods.rb +8 -3
  44. data/lib/rgeo/geographic/spherical_math.rb +17 -20
  45. data/lib/rgeo/geos/capi_factory.rb +50 -50
  46. data/lib/rgeo/geos/ffi_factory.rb +50 -49
  47. data/lib/rgeo/geos/ffi_feature_methods.rb +72 -98
  48. data/lib/rgeo/geos/interface.rb +16 -16
  49. data/lib/rgeo/geos/utils.rb +5 -5
  50. data/lib/rgeo/geos/zm_factory.rb +50 -42
  51. data/lib/rgeo/geos/zm_feature_methods.rb +15 -9
  52. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +4 -4
  53. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +1 -2
  54. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +18 -24
  55. data/lib/rgeo/impl_helper/basic_point_methods.rb +1 -3
  56. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +15 -16
  57. data/lib/rgeo/impl_helper/utils.rb +3 -9
  58. data/lib/rgeo/impl_helper/valid_op.rb +12 -16
  59. data/lib/rgeo/version.rb +1 -1
  60. data/lib/rgeo/wkrep/wkb_generator.rb +42 -47
  61. data/lib/rgeo/wkrep/wkb_parser.rb +17 -18
  62. data/lib/rgeo/wkrep/wkt_generator.rb +23 -16
  63. data/lib/rgeo/wkrep/wkt_parser.rb +23 -13
  64. metadata +6 -6
@@ -42,7 +42,6 @@ module RGeo
42
42
  # [<tt>:default_srid</tt>]
43
43
  # A SRID to pass to the factory generator if no SRID is present in
44
44
  # the input. Defaults to nil (i.e. don't specify a SRID).
45
-
46
45
  class WKBParser
47
46
  # Create and configure a WKB parser. See the WKBParser
48
47
  # documentation for the options that can be passed.
@@ -118,9 +117,7 @@ module RGeo
118
117
  obj = parse_object(false)
119
118
  unless @ignore_extra_bytes
120
119
  bytes = bytes_remaining
121
- if bytes > 0
122
- raise Error::ParseError, "Found #{bytes} extra bytes at the end of the stream."
123
- end
120
+ raise Error::ParseError, "Found #{bytes} extra bytes at the end of the stream." if bytes > 0
124
121
  end
125
122
  ensure
126
123
  @data = nil
@@ -133,7 +130,7 @@ module RGeo
133
130
  private
134
131
 
135
132
  def parse_object(contained)
136
- endian_value = get_byte
133
+ endian_value = byte
137
134
  case endian_value
138
135
  when 0
139
136
  little_endian = false
@@ -161,14 +158,20 @@ module RGeo
161
158
  if contained != true && contained != type_code
162
159
  raise Error::ParseError, "Enclosed type=#{type_code} is different from container constraint #{contained}"
163
160
  end
161
+
164
162
  if has_z != @cur_has_z
165
163
  raise Error::ParseError, "Enclosed hasZ=#{has_z} is different from toplevel hasZ=#{@cur_has_z}"
166
164
  end
165
+
167
166
  if has_m != @cur_has_m
168
167
  raise Error::ParseError, "Enclosed hasM=#{has_m} is different from toplevel hasM=#{@cur_has_m}"
169
168
  end
169
+
170
170
  if srid && srid != @cur_srid
171
- raise Error::ParseError, "Enclosed SRID #{srid} is different from toplevel srid #{@cur_srid || '(unspecified)'}"
171
+ raise(
172
+ Error::ParseError,
173
+ "Enclosed SRID #{srid} is different from toplevel srid #{@cur_srid || '(unspecified)'}"
174
+ )
172
175
  end
173
176
  else
174
177
  @cur_has_z = has_z
@@ -176,9 +179,11 @@ module RGeo
176
179
  @cur_dims = 2 + (@cur_has_z ? 1 : 0) + (@cur_has_m ? 1 : 0)
177
180
  @cur_srid = srid
178
181
  @cur_factory = @factory_generator.call(srid: @cur_srid, has_z_coordinate: has_z, has_m_coordinate: has_m)
182
+
179
183
  if @cur_has_z && !@cur_factory.property(:has_z_coordinate)
180
184
  raise Error::ParseError, "Data has Z coordinates but the factory doesn't have Z coordinates"
181
185
  end
186
+
182
187
  if @cur_has_m && !@cur_factory.property(:has_m_coordinate)
183
188
  raise Error::ParseError, "Data has M coordinates but the factory doesn't have M coordinates"
184
189
  end
@@ -222,29 +227,23 @@ module RGeo
222
227
  @len - @pos
223
228
  end
224
229
 
225
- def get_byte
226
- if @pos + 1 > @len
227
- raise Error::ParseError, "Not enough bytes left to fulfill 1 byte"
228
- end
230
+ def byte
231
+ raise Error::ParseError, "Not enough bytes left to fulfill 1 byte" if @pos + 1 > @len
229
232
  str = @data[@pos, 1]
230
233
  @pos += 1
231
- str.unpack("C").first
234
+ str.unpack1("C")
232
235
  end
233
236
 
234
237
  def get_integer(little_endian)
235
- if @pos + 4 > @len
236
- raise Error::ParseError, "Not enough bytes left to fulfill 1 integer"
237
- end
238
+ raise Error::ParseError, "Not enough bytes left to fulfill 1 integer" if @pos + 4 > @len
238
239
  str = @data[@pos, 4]
239
240
  @pos += 4
240
- str.unpack(little_endian ? "V" : "N").first
241
+ str.unpack1(little_endian ? "V" : "N")
241
242
  end
242
243
 
243
244
  def get_doubles(little_endian, count)
244
245
  len = 8 * count
245
- if @pos + len > @len
246
- raise Error::ParseError, "Not enough bytes left to fulfill #{count} doubles"
247
- end
246
+ raise Error::ParseError, "Not enough bytes left to fulfill #{count} doubles" if @pos + len > @len
248
247
  str = @data[@pos, len]
249
248
  @pos += len
250
249
  str.unpack("#{little_endian ? 'E' : 'G'}*")
@@ -45,15 +45,16 @@ module RGeo
45
45
  # letters to lower case; or nil, indicating no case changes from
46
46
  # the default (which is not specified exactly, but is chosen by the
47
47
  # generator to emphasize readability.) Default is nil.
48
-
49
48
  class WKTGenerator
50
49
  # Create and configure a WKT generator. See the WKTGenerator
51
50
  # documentation for the options that can be passed.
52
51
 
53
52
  def initialize(opts = {})
54
53
  @tag_format = opts[:tag_format] || opts[:type_format] || :wkt11
55
- @emit_ewkt_srid = @tag_format == :ewkt ?
56
- (opts[:emit_ewkt_srid] ? true : false) : nil
54
+ @emit_ewkt_srid =
55
+ if @tag_format == :ewkt
56
+ (opts[:emit_ewkt_srid] ? true : false)
57
+ end
57
58
  @square_brackets = opts[:square_brackets] ? true : false
58
59
  @convert_case = opts[:convert_case]
59
60
  end
@@ -99,10 +100,11 @@ module RGeo
99
100
  support_z = factory.property(:has_z_coordinate)
100
101
  support_m = factory.property(:has_m_coordinate)
101
102
  end
102
- str = generate_feature(obj, support_z, support_m, true)
103
- if @convert_case == :upper
103
+ str = generate_feature(obj, support_z, support_m, toplevel: true)
104
+ case @convert_case
105
+ when :upper
104
106
  str.upcase
105
- elsif @convert_case == :lower
107
+ when :lower
106
108
  str.downcase
107
109
  else
108
110
  str
@@ -111,20 +113,22 @@ module RGeo
111
113
 
112
114
  private
113
115
 
114
- def generate_feature(obj, support_z, support_m, toplevel = false)
116
+ def generate_feature(obj, support_z, support_m, toplevel: false)
115
117
  type = obj.geometry_type
116
118
  type = Feature::LineString if type.subtype_of?(Feature::LineString)
117
119
  tag = type.type_name.dup
118
- if @tag_format == :ewkt
120
+ case @tag_format
121
+ when :ewkt
119
122
  tag << "M" if support_m && !support_z
120
123
  tag = "SRID=#{obj.srid};#{tag}" if toplevel && @emit_ewkt_srid
121
- elsif @tag_format == :wkt12
124
+ when :wkt12
122
125
  if support_z
123
- if support_m
124
- tag << " ZM"
125
- else
126
- tag << " Z"
127
- end
126
+ tag <<
127
+ if support_m
128
+ " ZM"
129
+ else
130
+ " Z"
131
+ end
128
132
  elsif support_m
129
133
  tag << " M"
130
134
  end
@@ -163,7 +167,8 @@ module RGeo
163
167
  if obj.empty?
164
168
  "EMPTY"
165
169
  else
166
- "#{@begin_bracket}#{obj.points.map { |p| generate_coords(p, support_z, support_m) }.join(', ')}#{@end_bracket}"
170
+ points = obj.points.map { |p| generate_coords(p, support_z, support_m) }
171
+ "#{@begin_bracket}#{points.join(', ')}#{@end_bracket}"
167
172
  end
168
173
  end
169
174
 
@@ -171,7 +176,9 @@ module RGeo
171
176
  if obj.empty?
172
177
  "EMPTY"
173
178
  else
174
- "#{@begin_bracket}#{([generate_line_string(obj.exterior_ring, support_z, support_m)] + obj.interior_rings.map { |r| generate_line_string(r, support_z, support_m) }).join(', ')}#{@end_bracket}"
179
+ lines = [generate_line_string(obj.exterior_ring, support_z, support_m)]
180
+ lines += obj.interior_rings.map { |r| generate_line_string(r, support_z, support_m) }
181
+ "#{@begin_bracket}#{lines.join(', ')}#{@end_bracket}"
175
182
  end
176
183
  end
177
184
 
@@ -48,7 +48,6 @@ module RGeo
48
48
  # [<tt>:default_srid</tt>]
49
49
  # A SRID to pass to the factory generator if no SRID is present in
50
50
  # the input. Defaults to nil (i.e. don't specify a SRID).
51
-
52
51
  class WKTParser
53
52
  # Create and configure a WKT parser. See the WKTParser
54
53
  # documentation for the options that can be passed.
@@ -66,7 +65,12 @@ module RGeo
66
65
  end
67
66
  @support_ewkt = opts[:support_ewkt] ? true : false
68
67
  @support_wkt12 = opts[:support_wkt12] ? true : false
69
- @strict_wkt11 = @support_ewkt || @support_wkt12 ? false : opts[:strict_wkt11] ? true : false
68
+ @strict_wkt11 =
69
+ if @support_ewkt || @support_wkt12
70
+ false
71
+ else
72
+ opts[:strict_wkt11] ? true : false
73
+ end
70
74
  @ignore_extra_tokens = opts[:ignore_extra_tokens] ? true : false
71
75
  @default_srid = opts[:default_srid]
72
76
  @mutex = Mutex.new
@@ -127,12 +131,13 @@ module RGeo
127
131
  @cur_expect_m = nil
128
132
  @cur_srid = @default_srid
129
133
  if @support_ewkt && str =~ /^srid=(\d+);/i
130
- str = $'
134
+ str = Regexp.last_match&.post_match
131
135
  @cur_srid = Regexp.last_match(1).to_i
132
136
  end
133
137
  begin
134
138
  start_scanner(str)
135
139
  obj = parse_type_tag
140
+
136
141
  if @cur_token && !@ignore_extra_tokens
137
142
  raise Error::ParseError, "Extra tokens beginning with #{@cur_token.inspect}."
138
143
  end
@@ -149,14 +154,19 @@ module RGeo
149
154
  if @cur_expect_z && !@cur_factory_support_z
150
155
  raise Error::ParseError, "Geometry calls for Z coordinate but factory doesn't support it."
151
156
  end
152
- if @cur_expect_m && !@cur_factory_support_m
153
- raise Error::ParseError, "Geometry calls for M coordinate but factory doesn't support it."
154
- end
157
+
158
+ return unless @cur_expect_m && !@cur_factory_support_m
159
+
160
+ raise Error::ParseError, "Geometry calls for M coordinate but factory doesn't support it."
155
161
  end
156
162
 
157
163
  def ensure_factory
158
164
  unless @cur_factory
159
- @cur_factory = @factory_generator.call(srid: @cur_srid, has_z_coordinate: @cur_expect_z, has_m_coordinate: @cur_expect_m)
165
+ @cur_factory = @factory_generator.call(
166
+ srid: @cur_srid,
167
+ has_z_coordinate: @cur_expect_z,
168
+ has_m_coordinate: @cur_expect_m
169
+ )
160
170
  @cur_factory_support_z = @cur_factory.property(:has_z_coordinate) ? true : false
161
171
  @cur_factory_support_m = @cur_factory.property(:has_m_coordinate) ? true : false
162
172
  check_factory_support unless @cur_expect_z.nil?
@@ -202,7 +212,7 @@ module RGeo
202
212
  end
203
213
  case type
204
214
  when "point"
205
- parse_point(true)
215
+ parse_point(convert_empty: true)
206
216
  when "linestring"
207
217
  parse_line_string
208
218
  when "polygon"
@@ -238,9 +248,11 @@ module RGeo
238
248
  num_extras -= 1 if @cur_expect_z
239
249
  @cur_expect_m = num_extras > 0 && (!@cur_factory || @cur_factory_support_m) ? true : false
240
250
  num_extras -= 1 if @cur_expect_m
251
+
241
252
  if num_extras > 0
242
253
  raise Error::ParseError, "Found #{extra.size + 2} coordinates, which is too many for this factory."
243
254
  end
255
+
244
256
  ensure_factory
245
257
  else
246
258
  val = 0
@@ -261,7 +273,7 @@ module RGeo
261
273
  @cur_factory.point(x, y, *extra)
262
274
  end
263
275
 
264
- def parse_point(convert_empty = false)
276
+ def parse_point(convert_empty: false)
265
277
  if convert_empty && @cur_token == "empty"
266
278
  point = ensure_factory.multi_point([])
267
279
  else
@@ -390,13 +402,11 @@ module RGeo
390
402
  end
391
403
 
392
404
  def expect_token_type(type)
393
- unless type === @cur_token
394
- raise Error::ParseError, "#{type.inspect} expected but #{@cur_token.inspect} found."
395
- end
405
+ raise Error::ParseError, "#{type.inspect} expected but #{@cur_token.inspect} found." unless type === @cur_token
396
406
  end
397
407
 
398
408
  def next_token
399
- if @scanner.scan_until(/\(|\)|\[|\]|,|[^\s\(\)\[\],]+/)
409
+ if @scanner.scan_until(/\(|\)|\[|\]|,|[^\s()\[\],]+/)
400
410
  token = @scanner.matched
401
411
  case token
402
412
  when /^[-+]?(\d+(\.\d*)?|\.\d+)(e[-+]?\d+)?$/
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgeo
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.pre.rc.3
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Azuma
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-10-11 00:00:00.000000000 Z
12
+ date: 2023-11-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi-geos
@@ -238,14 +238,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
238
238
  requirements:
239
239
  - - ">="
240
240
  - !ruby/object:Gem::Version
241
- version: 2.5.0
241
+ version: 2.7.7
242
242
  required_rubygems_version: !ruby/object:Gem::Requirement
243
243
  requirements:
244
- - - ">"
244
+ - - ">="
245
245
  - !ruby/object:Gem::Version
246
- version: 1.3.1
246
+ version: '0'
247
247
  requirements: []
248
- rubygems_version: 3.1.4
248
+ rubygems_version: 3.2.33
249
249
  signing_key:
250
250
  specification_version: 4
251
251
  summary: RGeo is a geospatial data library for Ruby.