rgeo 2.0.0 → 2.3.0

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.
@@ -174,7 +174,6 @@ module RGeo
174
174
  # operation that would benefit from it is called. The latter
175
175
  # never automatically generates a prepared geometry (unless you
176
176
  # generate one explicitly using the <tt>prepare!</tt> method).
177
-
178
177
  def factory(opts = {})
179
178
  if supported?
180
179
  native_interface = opts[:native_interface] || Geos.preferred_native_interface
@@ -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"
@@ -9,6 +9,8 @@
9
9
  module RGeo
10
10
  module ImplHelper # :nodoc:
11
11
  module BasicGeometryCollectionMethods # :nodoc:
12
+ include Enumerable
13
+
12
14
  attr_reader :elements
13
15
 
14
16
  def initialize(factory, elements)
@@ -37,6 +39,10 @@ module RGeo
37
39
  @elements.each(&block)
38
40
  end
39
41
 
42
+ def geometries
43
+ @elements
44
+ end
45
+
40
46
  def dimension
41
47
  @dimension ||= @elements.map(&:dimension).max || -1
42
48
  end
@@ -114,6 +120,12 @@ module RGeo
114
120
  @elements.map(&:coordinates)
115
121
  end
116
122
 
123
+ def contains?(rhs)
124
+ return super unless Feature::Point === rhs
125
+
126
+ @elements.any? { |line| line.contains?(rhs) }
127
+ end
128
+
117
129
  private
118
130
 
119
131
  def add_boundary(hash, point)
@@ -171,12 +183,18 @@ module RGeo
171
183
  array << poly.exterior_ring unless poly.is_empty?
172
184
  array.concat(poly.interior_rings)
173
185
  end
174
- factory.multilinestring(array)
186
+ factory.multi_line_string(array)
175
187
  end
176
188
 
177
189
  def coordinates
178
190
  @elements.map(&:coordinates)
179
191
  end
192
+
193
+ def contains?(rhs)
194
+ return super unless Feature::Point === rhs
195
+
196
+ @elements.any? { |poly| poly.contains?(rhs) }
197
+ end
180
198
  end
181
199
  end
182
200
  end
@@ -87,8 +87,43 @@ module RGeo
87
87
  @points.map(&:coordinates)
88
88
  end
89
89
 
90
+ def contains?(rhs)
91
+ if Feature::Point === rhs
92
+ contains_point?(rhs)
93
+ else
94
+ raise(Error::UnsupportedOperation,
95
+ "Method LineString#contains? is only defined for Point")
96
+ end
97
+ end
98
+
90
99
  private
91
100
 
101
+ def contains_point?(point)
102
+ @points.each_cons(2) do |start_point, end_point|
103
+ return true if point_intersect_segment?(point, start_point, end_point)
104
+ end
105
+ false
106
+ end
107
+
108
+ def point_intersect_segment?(point, start_point, end_point)
109
+ return false unless point_collinear?(point, start_point, end_point)
110
+
111
+ if start_point.x != end_point.x
112
+ between_coordinate?(point.x, start_point.x, end_point.x)
113
+ else
114
+ between_coordinate?(point.y, start_point.y, end_point.y)
115
+ end
116
+ end
117
+
118
+ def point_collinear?(a, b, c)
119
+ (b.x - a.x) * (c.y - a.y) == (c.x - a.x) * (b.y - a.y)
120
+ end
121
+
122
+ def between_coordinate?(coord, start_coord, end_coord)
123
+ end_coord >= coord && coord >= start_coord ||
124
+ start_coord >= coord && coord >= end_coord
125
+ end
126
+
92
127
  def copy_state_from(obj)
93
128
  super
94
129
  @points = obj.points
@@ -137,6 +172,10 @@ module RGeo
137
172
  Feature::LinearRing
138
173
  end
139
174
 
175
+ def ccw?
176
+ RGeo::Cartesian::Analysis.ccw?(self)
177
+ end
178
+
140
179
  private
141
180
 
142
181
  def validate_geometry
@@ -57,7 +57,7 @@ module RGeo
57
57
  array = []
58
58
  array << @exterior_ring unless @exterior_ring.is_empty?
59
59
  array.concat(@interior_rings)
60
- factory.multiline_string(array)
60
+ factory.multi_line_string(array)
61
61
  end
62
62
 
63
63
  def rep_equals?(rhs)
@@ -79,8 +79,45 @@ module RGeo
79
79
  ([@exterior_ring] + @interior_rings).map(&:coordinates)
80
80
  end
81
81
 
82
+ def contains?(rhs)
83
+ if Feature::Point === rhs
84
+ contains_point?(rhs)
85
+ else
86
+ raise(Error::UnsupportedOperation,
87
+ "Method Polygon#contains? is only defined for Point"
88
+ )
89
+ end
90
+ end
91
+
82
92
  private
83
93
 
94
+ def contains_point?(point)
95
+ ring_encloses_point?(@exterior_ring, point) &&
96
+ !@interior_rings.any? do |exclusion|
97
+ ring_encloses_point?(exclusion, point, on_border_return: true)
98
+ end
99
+ end
100
+
101
+ def ring_encloses_point?(ring, point, on_border_return: false)
102
+ # This is an implementation of the ray casting algorithm, greatly inspired
103
+ # by https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html
104
+ # Since this algorithm does not handle point on edge, we check first if
105
+ # the ring is on the border.
106
+ # on_border_return is used for exclusion ring
107
+ return on_border_return if ring.contains?(point)
108
+ encloses_point = false
109
+ ring.points.each_cons(2) do |start_point, end_point|
110
+ next unless (point.y < end_point.y) != (point.y < start_point.y)
111
+
112
+ if point.x < (end_point.x - start_point.x) * (point.y - start_point.y) /
113
+ (end_point.y - start_point.y) + start_point.x
114
+ encloses_point = !encloses_point
115
+ end
116
+ end
117
+ encloses_point
118
+ end
119
+
120
+
84
121
  def copy_state_from(obj)
85
122
  super
86
123
  @exterior_ring = obj.exterior_ring
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.0.0"
4
+ VERSION = "2.3.0"
5
5
  end
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"
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.0.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - Daniel Azuma, Tee Parham
7
+ - Daniel Azuma
8
+ - Tee Parham
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2018-11-28 00:00:00.000000000 Z
12
+ date: 2021-04-16 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: ffi-geos
@@ -25,75 +26,83 @@ dependencies:
25
26
  - !ruby/object:Gem::Version
26
27
  version: '1.2'
27
28
  - !ruby/object:Gem::Dependency
28
- name: rake
29
+ name: minitest
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
32
  - - "~>"
32
33
  - !ruby/object:Gem::Version
33
- version: '12.0'
34
+ version: '5.11'
34
35
  type: :development
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
39
  - - "~>"
39
40
  - !ruby/object:Gem::Version
40
- version: '12.0'
41
+ version: '5.11'
41
42
  - !ruby/object:Gem::Dependency
42
- name: rake-compiler
43
+ name: rake
43
44
  requirement: !ruby/object:Gem::Requirement
44
45
  requirements:
45
46
  - - "~>"
46
47
  - !ruby/object:Gem::Version
47
- version: '1.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: '1.0'
55
+ version: '13.0'
55
56
  - !ruby/object:Gem::Dependency
56
- name: rubocop
57
+ name: rake-compiler
57
58
  requirement: !ruby/object:Gem::Requirement
58
59
  requirements:
59
60
  - - "~>"
60
61
  - !ruby/object:Gem::Version
61
- version: '0.51'
62
+ version: '1.0'
62
63
  type: :development
63
64
  prerelease: false
64
65
  version_requirements: !ruby/object:Gem::Requirement
65
66
  requirements:
66
67
  - - "~>"
67
68
  - !ruby/object:Gem::Version
68
- version: '0.51'
69
+ version: '1.0'
69
70
  - !ruby/object:Gem::Dependency
70
- name: test-unit
71
+ name: rubocop
71
72
  requirement: !ruby/object:Gem::Requirement
72
73
  requirements:
73
74
  - - "~>"
74
75
  - !ruby/object:Gem::Version
75
- version: '3.0'
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: '3.0'
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
@@ -181,7 +190,8 @@ files:
181
190
  - lib/rgeo/wkrep/wkt_generator.rb
182
191
  - lib/rgeo/wkrep/wkt_parser.rb
183
192
  homepage: https://github.com/rgeo/rgeo
184
- licenses: []
193
+ licenses:
194
+ - BSD-3-Clause
185
195
  metadata: {}
186
196
  post_install_message:
187
197
  rdoc_options: []
@@ -191,15 +201,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
191
201
  requirements:
192
202
  - - ">="
193
203
  - !ruby/object:Gem::Version
194
- version: 2.3.0
204
+ version: 2.5.0
195
205
  required_rubygems_version: !ruby/object:Gem::Requirement
196
206
  requirements:
197
207
  - - ">="
198
208
  - !ruby/object:Gem::Version
199
209
  version: '0'
200
210
  requirements: []
201
- rubyforge_project:
202
- rubygems_version: 2.7.8
211
+ rubygems_version: 3.2.3
203
212
  signing_key:
204
213
  specification_version: 4
205
214
  summary: RGeo is a geospatial data library for Ruby.