rgeo 2.1.1 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +160 -0
  3. data/ext/geos_c_impl/analysis.c +80 -0
  4. data/ext/geos_c_impl/analysis.h +40 -0
  5. data/ext/geos_c_impl/errors.c +35 -0
  6. data/ext/geos_c_impl/errors.h +22 -0
  7. data/ext/geos_c_impl/extconf.rb +2 -0
  8. data/ext/geos_c_impl/factory.c +179 -174
  9. data/ext/geos_c_impl/factory.h +20 -49
  10. data/ext/geos_c_impl/geometry.c +17 -16
  11. data/ext/geos_c_impl/geometry.h +1 -3
  12. data/ext/geos_c_impl/geometry_collection.c +39 -44
  13. data/ext/geos_c_impl/geometry_collection.h +1 -3
  14. data/ext/geos_c_impl/globals.c +91 -0
  15. data/ext/geos_c_impl/globals.h +45 -0
  16. data/ext/geos_c_impl/line_string.c +27 -28
  17. data/ext/geos_c_impl/line_string.h +1 -3
  18. data/ext/geos_c_impl/main.c +14 -10
  19. data/ext/geos_c_impl/point.c +8 -7
  20. data/ext/geos_c_impl/point.h +1 -3
  21. data/ext/geos_c_impl/polygon.c +14 -14
  22. data/ext/geos_c_impl/polygon.h +1 -3
  23. data/ext/geos_c_impl/preface.h +8 -0
  24. data/lib/rgeo/cartesian/analysis.rb +22 -0
  25. data/lib/rgeo/cartesian/feature_methods.rb +6 -1
  26. data/lib/rgeo/cartesian.rb +7 -7
  27. data/lib/rgeo/coord_sys.rb +6 -6
  28. data/lib/rgeo/error.rb +4 -0
  29. data/lib/rgeo/feature/curve.rb +12 -2
  30. data/lib/rgeo/feature/geometry.rb +12 -2
  31. data/lib/rgeo/feature/linear_ring.rb +10 -0
  32. data/lib/rgeo/feature/multi_curve.rb +6 -1
  33. data/lib/rgeo/feature.rb +17 -17
  34. data/lib/rgeo/geographic/interface.rb +2 -1
  35. data/lib/rgeo/geographic/projected_feature_methods.rb +12 -2
  36. data/lib/rgeo/geographic/spherical_feature_classes.rb +1 -0
  37. data/lib/rgeo/geographic/spherical_feature_methods.rb +29 -1
  38. data/lib/rgeo/geographic.rb +10 -10
  39. data/lib/rgeo/geos/capi_factory.rb +3 -3
  40. data/lib/rgeo/geos/capi_feature_classes.rb +33 -0
  41. data/lib/rgeo/geos/ffi_feature_methods.rb +34 -5
  42. data/lib/rgeo/geos/interface.rb +18 -4
  43. data/lib/rgeo/geos/zm_feature_methods.rb +30 -5
  44. data/lib/rgeo/geos.rb +11 -11
  45. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +33 -5
  46. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +62 -8
  47. data/lib/rgeo/impl_helper/basic_point_methods.rb +12 -2
  48. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +44 -2
  49. data/lib/rgeo/impl_helper.rb +7 -7
  50. data/lib/rgeo/version.rb +1 -1
  51. data/lib/rgeo/wkrep/wkb_generator.rb +1 -1
  52. data/lib/rgeo/wkrep/wkt_generator.rb +6 -6
  53. data/lib/rgeo/wkrep.rb +4 -4
  54. data/lib/rgeo.rb +9 -9
  55. metadata +26 -14
@@ -39,13 +39,18 @@ module RGeo
39
39
  Feature::LineString
40
40
  end
41
41
 
42
- def is_empty?
42
+ def empty?
43
43
  @points.size == 0
44
44
  end
45
45
 
46
+ def is_empty?
47
+ warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
48
+ empty?
49
+ end
50
+
46
51
  def boundary
47
52
  array = []
48
- array << @points.first << @points.last if !is_empty? && !is_closed?
53
+ array << @points.first << @points.last if !empty? && !closed?
49
54
  factory.multipoint([array])
50
55
  end
51
56
 
@@ -57,15 +62,25 @@ module RGeo
57
62
  @points.last
58
63
  end
59
64
 
60
- def is_closed?
61
- unless defined?(@is_closed)
62
- @is_closed = @points.size > 2 && @points.first == @points.last
65
+ def closed?
66
+ unless defined?(@closed)
67
+ @closed = @points.size > 2 && @points.first == @points.last
63
68
  end
64
- @is_closed
69
+ @closed
70
+ end
71
+
72
+ def is_closed?
73
+ warn "The is_closed? method is deprecated, please use the closed? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
74
+ closed?
75
+ end
76
+
77
+ def ring?
78
+ closed? && simple?
65
79
  end
66
80
 
67
81
  def is_ring?
68
- is_closed? && is_simple?
82
+ warn "The is_ring? method is deprecated, please use the ring? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
83
+ ring?
69
84
  end
70
85
 
71
86
  def rep_equals?(rhs)
@@ -87,8 +102,43 @@ module RGeo
87
102
  @points.map(&:coordinates)
88
103
  end
89
104
 
105
+ def contains?(rhs)
106
+ if Feature::Point === rhs
107
+ contains_point?(rhs)
108
+ else
109
+ raise(Error::UnsupportedOperation,
110
+ "Method LineString#contains? is only defined for Point")
111
+ end
112
+ end
113
+
90
114
  private
91
115
 
116
+ def contains_point?(point)
117
+ @points.each_cons(2) do |start_point, end_point|
118
+ return true if point_intersect_segment?(point, start_point, end_point)
119
+ end
120
+ false
121
+ end
122
+
123
+ def point_intersect_segment?(point, start_point, end_point)
124
+ return false unless point_collinear?(point, start_point, end_point)
125
+
126
+ if start_point.x != end_point.x
127
+ between_coordinate?(point.x, start_point.x, end_point.x)
128
+ else
129
+ between_coordinate?(point.y, start_point.y, end_point.y)
130
+ end
131
+ end
132
+
133
+ def point_collinear?(a, b, c)
134
+ (b.x - a.x) * (c.y - a.y) == (c.x - a.x) * (b.y - a.y)
135
+ end
136
+
137
+ def between_coordinate?(coord, start_coord, end_coord)
138
+ end_coord >= coord && coord >= start_coord ||
139
+ start_coord >= coord && coord >= end_coord
140
+ end
141
+
92
142
  def copy_state_from(obj)
93
143
  super
94
144
  @points = obj.points
@@ -137,6 +187,10 @@ module RGeo
137
187
  Feature::LinearRing
138
188
  end
139
189
 
190
+ def ccw?
191
+ RGeo::Cartesian::Analysis.ccw?(self)
192
+ end
193
+
140
194
  private
141
195
 
142
196
  def validate_geometry
@@ -144,7 +198,7 @@ module RGeo
144
198
  if @points.size > 0
145
199
  @points << @points.first if @points.first != @points.last
146
200
  @points = @points.chunk { |x| x }.map(&:first)
147
- if !@factory.property(:uses_lenient_assertions) && !is_ring?
201
+ if !@factory.property(:uses_lenient_assertions) && !ring?
148
202
  raise Error::InvalidGeometry, "LinearRing failed ring test"
149
203
  end
150
204
  end
@@ -45,14 +45,24 @@ module RGeo
45
45
  Feature::Point
46
46
  end
47
47
 
48
- def is_empty?
48
+ def empty?
49
49
  false
50
50
  end
51
51
 
52
- def is_simple?
52
+ def is_empty?
53
+ warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
54
+ empty?
55
+ end
56
+
57
+ def simple?
53
58
  true
54
59
  end
55
60
 
61
+ def is_simple?
62
+ warn "The is_simple? method is deprecated, please use the simple? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
63
+ simple?
64
+ end
65
+
56
66
  def envelope
57
67
  self
58
68
  end
@@ -49,13 +49,18 @@ module RGeo
49
49
  Feature::Polygon
50
50
  end
51
51
 
52
+ def empty?
53
+ @exterior_ring.empty?
54
+ end
55
+
52
56
  def is_empty?
53
- @exterior_ring.is_empty?
57
+ warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
58
+ empty?
54
59
  end
55
60
 
56
61
  def boundary
57
62
  array = []
58
- array << @exterior_ring unless @exterior_ring.is_empty?
63
+ array << @exterior_ring unless @exterior_ring.empty?
59
64
  array.concat(@interior_rings)
60
65
  factory.multi_line_string(array)
61
66
  end
@@ -79,8 +84,45 @@ module RGeo
79
84
  ([@exterior_ring] + @interior_rings).map(&:coordinates)
80
85
  end
81
86
 
87
+ def contains?(rhs)
88
+ if Feature::Point === rhs
89
+ contains_point?(rhs)
90
+ else
91
+ raise(Error::UnsupportedOperation,
92
+ "Method Polygon#contains? is only defined for Point"
93
+ )
94
+ end
95
+ end
96
+
82
97
  private
83
98
 
99
+ def contains_point?(point)
100
+ ring_encloses_point?(@exterior_ring, point) &&
101
+ !@interior_rings.any? do |exclusion|
102
+ ring_encloses_point?(exclusion, point, on_border_return: true)
103
+ end
104
+ end
105
+
106
+ def ring_encloses_point?(ring, point, on_border_return: false)
107
+ # This is an implementation of the ray casting algorithm, greatly inspired
108
+ # by https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html
109
+ # Since this algorithm does not handle point on edge, we check first if
110
+ # the ring is on the border.
111
+ # on_border_return is used for exclusion ring
112
+ return on_border_return if ring.contains?(point)
113
+ encloses_point = false
114
+ ring.points.each_cons(2) do |start_point, end_point|
115
+ next unless (point.y < end_point.y) != (point.y < start_point.y)
116
+
117
+ if point.x < (end_point.x - start_point.x) * (point.y - start_point.y) /
118
+ (end_point.y - start_point.y) + start_point.x
119
+ encloses_point = !encloses_point
120
+ end
121
+ end
122
+ encloses_point
123
+ end
124
+
125
+
84
126
  def copy_state_from(obj)
85
127
  super
86
128
  @exterior_ring = obj.exterior_ring
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rgeo/impl_helper/utils"
4
- require "rgeo/impl_helper/math"
5
- require "rgeo/impl_helper/basic_geometry_methods"
6
- require "rgeo/impl_helper/basic_geometry_collection_methods"
7
- require "rgeo/impl_helper/basic_point_methods"
8
- require "rgeo/impl_helper/basic_line_string_methods"
9
- require "rgeo/impl_helper/basic_polygon_methods"
3
+ require_relative "impl_helper/utils"
4
+ require_relative "impl_helper/math"
5
+ require_relative "impl_helper/basic_geometry_methods"
6
+ require_relative "impl_helper/basic_geometry_collection_methods"
7
+ require_relative "impl_helper/basic_point_methods"
8
+ require_relative "impl_helper/basic_line_string_methods"
9
+ require_relative "impl_helper/basic_polygon_methods"
data/lib/rgeo/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RGeo
4
- VERSION = "2.1.1"
4
+ VERSION = "2.4.0"
5
5
  end
@@ -178,7 +178,7 @@ module RGeo
178
178
  emit_line_string_coords(obj)
179
179
  elsif type == Feature::Polygon
180
180
  exterior_ring = obj.exterior_ring
181
- if exterior_ring.is_empty?
181
+ if exterior_ring.empty?
182
182
  emit_integer(0)
183
183
  else
184
184
  emit_integer(1 + obj.num_interior_rings)
@@ -160,7 +160,7 @@ module RGeo
160
160
  end
161
161
 
162
162
  def generate_line_string(obj)
163
- if obj.is_empty?
163
+ if obj.empty?
164
164
  "EMPTY"
165
165
  else
166
166
  "#{@begin_bracket}#{obj.points.map { |p| generate_coords(p) }.join(', ')}#{@end_bracket}"
@@ -168,7 +168,7 @@ module RGeo
168
168
  end
169
169
 
170
170
  def generate_polygon(obj)
171
- if obj.is_empty?
171
+ if obj.empty?
172
172
  "EMPTY"
173
173
  else
174
174
  "#{@begin_bracket}#{([generate_line_string(obj.exterior_ring)] + obj.interior_rings.map { |r| generate_line_string(r) }).join(', ')}#{@end_bracket}"
@@ -176,7 +176,7 @@ module RGeo
176
176
  end
177
177
 
178
178
  def generate_geometry_collection(obj)
179
- if obj.is_empty?
179
+ if obj.empty?
180
180
  "EMPTY"
181
181
  else
182
182
  "#{@begin_bracket}#{obj.map { |f| generate_feature(f) }.join(', ')}#{@end_bracket}"
@@ -184,7 +184,7 @@ module RGeo
184
184
  end
185
185
 
186
186
  def generate_multi_point(obj)
187
- if obj.is_empty?
187
+ if obj.empty?
188
188
  "EMPTY"
189
189
  else
190
190
  "#{@begin_bracket}#{obj.map { |f| generate_point(f) }.join(', ')}#{@end_bracket}"
@@ -192,7 +192,7 @@ module RGeo
192
192
  end
193
193
 
194
194
  def generate_multi_line_string(obj)
195
- if obj.is_empty?
195
+ if obj.empty?
196
196
  "EMPTY"
197
197
  else
198
198
  "#{@begin_bracket}#{obj.map { |f| generate_line_string(f) }.join(', ')}#{@end_bracket}"
@@ -200,7 +200,7 @@ module RGeo
200
200
  end
201
201
 
202
202
  def generate_multi_polygon(obj)
203
- if obj.is_empty?
203
+ if obj.empty?
204
204
  "EMPTY"
205
205
  else
206
206
  "#{@begin_bracket}#{obj.map { |f| generate_polygon(f) }.join(', ')}#{@end_bracket}"
data/lib/rgeo/wkrep.rb CHANGED
@@ -21,7 +21,7 @@
21
21
  # To parse a byte string in WKB (well-known binary) format back into a
22
22
  # geometry object, use the WKRep::WKBParser class.
23
23
 
24
- require "rgeo/wkrep/wkt_parser"
25
- require "rgeo/wkrep/wkt_generator"
26
- require "rgeo/wkrep/wkb_parser"
27
- require "rgeo/wkrep/wkb_generator"
24
+ require_relative "wkrep/wkt_parser"
25
+ require_relative "wkrep/wkt_generator"
26
+ require_relative "wkrep/wkb_parser"
27
+ require_relative "wkrep/wkb_generator"
data/lib/rgeo.rb CHANGED
@@ -75,12 +75,12 @@
75
75
  # database, and based on the postgresql adapter. Available as the
76
76
  # activerecord-postgis-adapter gem.
77
77
 
78
- require "rgeo/version"
79
- require "rgeo/error"
80
- require "rgeo/feature"
81
- require "rgeo/coord_sys"
82
- require "rgeo/impl_helper"
83
- require "rgeo/wkrep"
84
- require "rgeo/geos"
85
- require "rgeo/cartesian"
86
- require "rgeo/geographic"
78
+ require_relative "rgeo/version"
79
+ require_relative "rgeo/error"
80
+ require_relative "rgeo/feature"
81
+ require_relative "rgeo/coord_sys"
82
+ require_relative "rgeo/impl_helper"
83
+ require_relative "rgeo/wkrep"
84
+ require_relative "rgeo/geos"
85
+ require_relative "rgeo/cartesian"
86
+ require_relative "rgeo/geographic"
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgeo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
- - Daniel Azuma, Tee Parham
8
- autorequire:
7
+ - Daniel Azuma
8
+ - Tee Parham
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2019-08-26 00:00:00.000000000 Z
12
+ date: 2022-01-19 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: ffi-geos
@@ -44,14 +45,14 @@ dependencies:
44
45
  requirements:
45
46
  - - "~>"
46
47
  - !ruby/object:Gem::Version
47
- version: '12.0'
48
+ version: '13.0'
48
49
  type: :development
49
50
  prerelease: false
50
51
  version_requirements: !ruby/object:Gem::Requirement
51
52
  requirements:
52
53
  - - "~>"
53
54
  - !ruby/object:Gem::Version
54
- version: '12.0'
55
+ version: '13.0'
55
56
  - !ruby/object:Gem::Dependency
56
57
  name: rake-compiler
57
58
  requirement: !ruby/object:Gem::Requirement
@@ -72,28 +73,36 @@ dependencies:
72
73
  requirements:
73
74
  - - "~>"
74
75
  - !ruby/object:Gem::Version
75
- version: '0.51'
76
+ version: 1.8.1
76
77
  type: :development
77
78
  prerelease: false
78
79
  version_requirements: !ruby/object:Gem::Requirement
79
80
  requirements:
80
81
  - - "~>"
81
82
  - !ruby/object:Gem::Version
82
- version: '0.51'
83
+ version: 1.8.1
83
84
  description: RGeo is a geospatial data library for Ruby. It provides an implementation
84
85
  of the Open Geospatial Consortium's Simple Features Specification, used by most
85
86
  standard spatial/geographic data storage systems such as PostGIS. A number of add-on
86
87
  modules are also available to help with writing location-based applications using
87
88
  Ruby-based frameworks such as Ruby On Rails.
88
- email: dazuma@gmail.com, parhameter@gmail.com
89
+ email:
90
+ - dazuma@gmail.com
91
+ - parhameter@gmail.com
92
+ - kfdoggett@gmail.com
89
93
  executables: []
90
94
  extensions:
91
95
  - ext/geos_c_impl/extconf.rb
92
96
  extra_rdoc_files: []
93
97
  files:
94
98
  - LICENSE.txt
99
+ - README.md
100
+ - ext/geos_c_impl/analysis.c
101
+ - ext/geos_c_impl/analysis.h
95
102
  - ext/geos_c_impl/coordinates.c
96
103
  - ext/geos_c_impl/coordinates.h
104
+ - ext/geos_c_impl/errors.c
105
+ - ext/geos_c_impl/errors.h
97
106
  - ext/geos_c_impl/extconf.rb
98
107
  - ext/geos_c_impl/factory.c
99
108
  - ext/geos_c_impl/factory.h
@@ -101,6 +110,8 @@ files:
101
110
  - ext/geos_c_impl/geometry.h
102
111
  - ext/geos_c_impl/geometry_collection.c
103
112
  - ext/geos_c_impl/geometry_collection.h
113
+ - ext/geos_c_impl/globals.c
114
+ - ext/geos_c_impl/globals.h
104
115
  - ext/geos_c_impl/line_string.c
105
116
  - ext/geos_c_impl/line_string.h
106
117
  - ext/geos_c_impl/main.c
@@ -181,9 +192,10 @@ files:
181
192
  - lib/rgeo/wkrep/wkt_generator.rb
182
193
  - lib/rgeo/wkrep/wkt_parser.rb
183
194
  homepage: https://github.com/rgeo/rgeo
184
- licenses: []
195
+ licenses:
196
+ - BSD-3-Clause
185
197
  metadata: {}
186
- post_install_message:
198
+ post_install_message:
187
199
  rdoc_options: []
188
200
  require_paths:
189
201
  - lib
@@ -191,15 +203,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
191
203
  requirements:
192
204
  - - ">="
193
205
  - !ruby/object:Gem::Version
194
- version: 2.3.0
206
+ version: 2.5.0
195
207
  required_rubygems_version: !ruby/object:Gem::Requirement
196
208
  requirements:
197
209
  - - ">="
198
210
  - !ruby/object:Gem::Version
199
211
  version: '0'
200
212
  requirements: []
201
- rubygems_version: 3.0.6
202
- signing_key:
213
+ rubygems_version: 3.1.6
214
+ signing_key:
203
215
  specification_version: 4
204
216
  summary: RGeo is a geospatial data library for Ruby.
205
217
  test_files: []