rgeo 1.1.2 → 2.0.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.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/ext/geos_c_impl/extconf.rb +5 -3
  3. data/ext/geos_c_impl/factory.c +4 -4
  4. data/ext/geos_c_impl/geometry.c +1 -1
  5. data/lib/rgeo.rb +2 -4
  6. data/lib/rgeo/cartesian.rb +6 -16
  7. data/lib/rgeo/cartesian/analysis.rb +22 -20
  8. data/lib/rgeo/cartesian/bounding_box.rb +83 -79
  9. data/lib/rgeo/cartesian/calculations.rb +40 -38
  10. data/lib/rgeo/cartesian/factory.rb +134 -169
  11. data/lib/rgeo/cartesian/feature_classes.rb +2 -18
  12. data/lib/rgeo/cartesian/feature_methods.rb +37 -39
  13. data/lib/rgeo/cartesian/interface.rb +11 -9
  14. data/lib/rgeo/coord_sys.rb +9 -8
  15. data/lib/rgeo/coord_sys/cs/entities.rb +345 -303
  16. data/lib/rgeo/coord_sys/cs/factories.rb +30 -28
  17. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +128 -126
  18. data/lib/rgeo/coord_sys/srs_database/{interface.rb → entry.rb} +26 -32
  19. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +19 -17
  20. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +21 -19
  21. data/lib/rgeo/error.rb +3 -1
  22. data/lib/rgeo/feature.rb +23 -34
  23. data/lib/rgeo/feature/curve.rb +2 -0
  24. data/lib/rgeo/feature/factory.rb +15 -13
  25. data/lib/rgeo/feature/factory_generator.rb +7 -5
  26. data/lib/rgeo/feature/geometry.rb +31 -29
  27. data/lib/rgeo/feature/geometry_collection.rb +6 -4
  28. data/lib/rgeo/feature/line.rb +2 -0
  29. data/lib/rgeo/feature/line_string.rb +3 -1
  30. data/lib/rgeo/feature/linear_ring.rb +2 -0
  31. data/lib/rgeo/feature/multi_curve.rb +2 -0
  32. data/lib/rgeo/feature/multi_line_string.rb +2 -0
  33. data/lib/rgeo/feature/multi_point.rb +2 -0
  34. data/lib/rgeo/feature/multi_polygon.rb +2 -0
  35. data/lib/rgeo/feature/multi_surface.rb +2 -0
  36. data/lib/rgeo/feature/point.rb +2 -0
  37. data/lib/rgeo/feature/polygon.rb +3 -1
  38. data/lib/rgeo/feature/surface.rb +2 -0
  39. data/lib/rgeo/feature/types.rb +107 -103
  40. data/lib/rgeo/geographic.rb +17 -27
  41. data/lib/rgeo/geographic/factory.rb +154 -199
  42. data/lib/rgeo/geographic/interface.rb +141 -137
  43. data/lib/rgeo/geographic/proj4_projector.rb +28 -23
  44. data/lib/rgeo/geographic/projected_feature_classes.rb +2 -18
  45. data/lib/rgeo/geographic/projected_feature_methods.rb +59 -49
  46. data/lib/rgeo/geographic/projected_window.rb +4 -2
  47. data/lib/rgeo/geographic/simple_mercator_projector.rb +41 -39
  48. data/lib/rgeo/geographic/spherical_feature_classes.rb +2 -18
  49. data/lib/rgeo/geographic/spherical_feature_methods.rb +67 -67
  50. data/lib/rgeo/geographic/spherical_math.rb +81 -87
  51. data/lib/rgeo/geos.rb +23 -34
  52. data/lib/rgeo/geos/capi_factory.rb +106 -135
  53. data/lib/rgeo/geos/capi_feature_classes.rb +19 -37
  54. data/lib/rgeo/geos/ffi_factory.rb +276 -297
  55. data/lib/rgeo/geos/ffi_feature_classes.rb +2 -20
  56. data/lib/rgeo/geos/ffi_feature_methods.rb +170 -166
  57. data/lib/rgeo/geos/interface.rb +25 -23
  58. data/lib/rgeo/geos/utils.rb +47 -39
  59. data/lib/rgeo/geos/zm_factory.rb +171 -185
  60. data/lib/rgeo/geos/zm_feature_classes.rb +2 -20
  61. data/lib/rgeo/geos/zm_feature_methods.rb +76 -72
  62. data/lib/rgeo/impl_helper.rb +1 -11
  63. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +72 -75
  64. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +21 -23
  65. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +57 -49
  66. data/lib/rgeo/impl_helper/basic_point_methods.rb +29 -25
  67. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +31 -27
  68. data/lib/rgeo/impl_helper/math.rb +2 -0
  69. data/lib/rgeo/impl_helper/utils.rb +9 -15
  70. data/lib/rgeo/version.rb +3 -1
  71. data/lib/rgeo/wkrep.rb +20 -30
  72. data/lib/rgeo/wkrep/wkb_generator.rb +87 -84
  73. data/lib/rgeo/wkrep/wkb_parser.rb +93 -93
  74. data/lib/rgeo/wkrep/wkt_generator.rb +67 -63
  75. data/lib/rgeo/wkrep/wkt_parser.rb +172 -168
  76. metadata +17 -32
  77. data/lib/rgeo/feature/mixins.rb +0 -143
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # -----------------------------------------------------------------------------
2
4
  #
3
5
  # Basic methods used by geometry objects
@@ -9,6 +11,8 @@ module RGeo
9
11
  module BasicGeometryMethods # :nodoc:
10
12
  include Feature::Instance
11
13
 
14
+ attr_accessor :factory
15
+
12
16
  def inspect # :nodoc:
13
17
  "#<#{self.class}:0x#{object_id.to_s(16)} #{as_text.inspect}>"
14
18
  end
@@ -17,44 +21,38 @@ module RGeo
17
21
  as_text
18
22
  end
19
23
 
20
- def _validate_geometry # :nodoc:
21
- end
22
-
23
- def _set_factory(factory_) # :nodoc:
24
- @factory = factory_
24
+ def as_text
25
+ @factory.generate_wkt(self)
25
26
  end
26
27
 
27
- def factory
28
- @factory
28
+ def as_binary
29
+ @factory.generate_wkb(self)
29
30
  end
30
31
 
31
- def as_text
32
- @factory._generate_wkt(self)
32
+ def marshal_dump # :nodoc:
33
+ [@factory, @factory.marshal_wkb_generator.generate(self)]
33
34
  end
34
35
 
35
- def as_binary
36
- @factory._generate_wkb(self)
36
+ def marshal_load(data) # :nodoc:
37
+ copy_state_from(data[0].marshal_wkb_parser.parse(data[1]))
37
38
  end
38
39
 
39
- def _copy_state_from(obj_) # :nodoc:
40
- @factory = obj_.factory
40
+ def encode_with(coder) # :nodoc:
41
+ coder["factory"] = @factory
42
+ coder["wkt"] = @factory.psych_wkt_generator.generate(self)
41
43
  end
42
44
 
43
- def marshal_dump # :nodoc:
44
- [@factory, @factory._marshal_wkb_generator.generate(self)]
45
+ def init_with(coder) # :nodoc:
46
+ copy_state_from(coder["factory"].psych_wkt_parser.parse(coder["wkt"]))
45
47
  end
46
48
 
47
- def marshal_load(data_) # :nodoc:
48
- _copy_state_from(data_[0]._marshal_wkb_parser.parse(data_[1]))
49
- end
49
+ private
50
50
 
51
- def encode_with(coder_) # :nodoc:
52
- coder_["factory"] = @factory
53
- coder_["wkt"] = @factory._psych_wkt_generator.generate(self)
51
+ def copy_state_from(obj)
52
+ @factory = obj.factory
54
53
  end
55
54
 
56
- def init_with(coder_) # :nodoc:
57
- _copy_state_from(coder_["factory"]._psych_wkt_parser.parse(coder_["wkt"]))
55
+ def validate_geometry
58
56
  end
59
57
  end
60
58
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # -----------------------------------------------------------------------------
2
4
  #
3
5
  # Common methods for LineString features
@@ -7,28 +9,22 @@
7
9
  module RGeo
8
10
  module ImplHelper # :nodoc:
9
11
  module BasicLineStringMethods # :nodoc:
10
- def initialize(factory_, points_)
11
- _set_factory(factory_)
12
- @points = points_.map do |elem_|
13
- elem_ = Feature.cast(elem_, factory_, Feature::Point)
14
- raise Error::InvalidGeometry, "Could not cast #{elem_}" unless elem_
15
- elem_
16
- end
17
- _validate_geometry
18
- end
19
-
20
- def _validate_geometry
21
- if @points.size == 1
22
- raise Error::InvalidGeometry, "LineString cannot have 1 point"
12
+ def initialize(factory, points)
13
+ self.factory = factory
14
+ @points = points.map do |elem|
15
+ elem = Feature.cast(elem, factory, Feature::Point)
16
+ raise Error::InvalidGeometry, "Could not cast #{elem}" unless elem
17
+ elem
23
18
  end
19
+ validate_geometry
24
20
  end
25
21
 
26
22
  def num_points
27
23
  @points.size
28
24
  end
29
25
 
30
- def point_n(n_)
31
- n_ < 0 ? nil : @points[n_]
26
+ def point_n(n)
27
+ n < 0 ? nil : @points[n]
32
28
  end
33
29
 
34
30
  def points
@@ -48,9 +44,9 @@ module RGeo
48
44
  end
49
45
 
50
46
  def boundary
51
- array_ = []
52
- array_ << @points.first << @points.last if !is_empty? && !is_closed?
53
- factory.multi_point([array_])
47
+ array = []
48
+ array << @points.first << @points.last if !is_empty? && !is_closed?
49
+ factory.multipoint([array])
54
50
  end
55
51
 
56
52
  def start_point
@@ -72,9 +68,9 @@ module RGeo
72
68
  is_closed? && is_simple?
73
69
  end
74
70
 
75
- def rep_equals?(rhs_)
76
- if rhs_.is_a?(self.class) && rhs_.factory.eql?(@factory) && @points.size == rhs_.num_points
77
- rhs_.points.each_with_index { |p_, i_| return false unless @points[i_].rep_equals?(p_) }
71
+ def rep_equals?(rhs)
72
+ if rhs.is_a?(self.class) && rhs.factory.eql?(@factory) && @points.size == rhs.num_points
73
+ rhs.points.each_with_index { |p, i| return false unless @points[i].rep_equals?(p) }
78
74
  else
79
75
  false
80
76
  end
@@ -82,39 +78,40 @@ module RGeo
82
78
 
83
79
  def hash
84
80
  @hash ||= begin
85
- hash_ = [factory, geometry_type].hash
86
- @points.inject(hash_) { |h_, p_| (1_664_525 * h_ + p_.hash).hash }
81
+ hash = [factory, geometry_type].hash
82
+ @points.inject(hash) { |h, p| (1_664_525 * h + p.hash).hash }
87
83
  end
88
84
  end
89
85
 
90
- def _copy_state_from(obj_) # :nodoc:
91
- super
92
- @points = obj_.points
93
- end
94
-
95
86
  def coordinates
96
87
  @points.map(&:coordinates)
97
88
  end
98
- end
99
89
 
100
- module BasicLineMethods # :nodoc:
101
- def initialize(factory_, start_, end_)
102
- _set_factory(factory_)
103
- cstart_ = Feature.cast(start_, factory_, Feature::Point)
104
- unless cstart_
105
- raise Error::InvalidGeometry, "Could not cast start: #{start_}"
90
+ private
91
+
92
+ def copy_state_from(obj)
93
+ super
94
+ @points = obj.points
95
+ end
96
+
97
+ def validate_geometry
98
+ if @points.size == 1
99
+ raise Error::InvalidGeometry, "LineString cannot have 1 point"
106
100
  end
107
- cend_ = Feature.cast(end_, factory_, Feature::Point)
108
- raise Error::InvalidGeometry, "Could not cast end: #{end_}" unless cend_
109
- @points = [cstart_, cend_]
110
- _validate_geometry
111
101
  end
102
+ end
112
103
 
113
- def _validate_geometry # :nodoc:
114
- super
115
- if @points.size > 2
116
- raise Error::InvalidGeometry, "Line must have 0 or 2 points"
104
+ module BasicLineMethods # :nodoc:
105
+ def initialize(factory, start, stop)
106
+ self.factory = factory
107
+ cstart = Feature.cast(start, factory, Feature::Point)
108
+ unless cstart
109
+ raise Error::InvalidGeometry, "Could not cast start: #{start}"
117
110
  end
111
+ cstop = Feature.cast(stop, factory, Feature::Point)
112
+ raise Error::InvalidGeometry, "Could not cast end: #{stop}" unless cstop
113
+ @points = [cstart, cstop]
114
+ validate_geometry
118
115
  end
119
116
 
120
117
  def geometry_type
@@ -124,23 +121,34 @@ module RGeo
124
121
  def coordinates
125
122
  @points.map(&:coordinates)
126
123
  end
124
+
125
+ private
126
+
127
+ def validate_geometry
128
+ super
129
+ if @points.size > 2
130
+ raise Error::InvalidGeometry, "Line must have 0 or 2 points"
131
+ end
132
+ end
127
133
  end
128
134
 
129
135
  module BasicLinearRingMethods # :nodoc:
130
- def _validate_geometry # :nodoc:
136
+ def geometry_type
137
+ Feature::LinearRing
138
+ end
139
+
140
+ private
141
+
142
+ def validate_geometry
131
143
  super
132
144
  if @points.size > 0
133
145
  @points << @points.first if @points.first != @points.last
134
- @points = @points.chunk {|x| x}.map(&:first)
146
+ @points = @points.chunk { |x| x }.map(&:first)
135
147
  if !@factory.property(:uses_lenient_assertions) && !is_ring?
136
148
  raise Error::InvalidGeometry, "LinearRing failed ring test"
137
149
  end
138
150
  end
139
151
  end
140
-
141
- def geometry_type
142
- Feature::LinearRing
143
- end
144
152
  end
145
153
  end
146
154
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # -----------------------------------------------------------------------------
2
4
  #
3
5
  # Common methods for Point features
@@ -7,16 +9,16 @@
7
9
  module RGeo
8
10
  module ImplHelper # :nodoc:
9
11
  module BasicPointMethods # :nodoc:
10
- def initialize(factory_, x_, y_, *extra_)
11
- _set_factory(factory_)
12
- @x = x_.to_f
13
- @y = y_.to_f
14
- @z = factory_.property(:has_z_coordinate) ? extra_.shift.to_f : nil
15
- @m = factory_.property(:has_m_coordinate) ? extra_.shift.to_f : nil
16
- if extra_.size > 0
17
- raise ::ArgumentError, "Too many arguments for point initializer"
12
+ def initialize(factory, x, y, *extra)
13
+ self.factory = factory
14
+ @x = x.to_f
15
+ @y = y.to_f
16
+ @z = factory.property(:has_z_coordinate) ? extra.shift.to_f : nil
17
+ @m = factory.property(:has_m_coordinate) ? extra.shift.to_f : nil
18
+ if extra.size > 0
19
+ raise ArgumentError, "Too many arguments for point initializer"
18
20
  end
19
- _validate_geometry
21
+ validate_geometry
20
22
  end
21
23
 
22
24
  def x
@@ -63,42 +65,44 @@ module RGeo
63
65
  self
64
66
  end
65
67
 
66
- def equals?(rhs_)
67
- return false unless rhs_.is_a?(self.class) && rhs_.factory == factory
68
- case rhs_
68
+ def equals?(rhs)
69
+ return false unless rhs.is_a?(self.class) && rhs.factory == factory
70
+ case rhs
69
71
  when Feature::Point
70
- rhs_.x == @x && rhs_.y == @y
72
+ rhs.x == @x && rhs.y == @y
71
73
  when Feature::LineString
72
- rhs_.num_points > 0 && rhs_.points.all? { |elem_| equals?(elem_) }
74
+ rhs.num_points > 0 && rhs.points.all? { |elem| equals?(elem) }
73
75
  when Feature::GeometryCollection
74
- rhs_.num_geometries > 0 && rhs_.all? { |elem_| equals?(elem_) }
76
+ rhs.num_geometries > 0 && rhs.all? { |elem| equals?(elem) }
75
77
  else
76
78
  false
77
79
  end
78
80
  end
79
81
 
80
- def rep_equals?(rhs_)
81
- rhs_.is_a?(self.class) && rhs_.factory.eql?(@factory) && @x == rhs_.x && @y == rhs_.y && @z == rhs_.z && @m == rhs_.m
82
+ def rep_equals?(rhs)
83
+ rhs.is_a?(self.class) && rhs.factory.eql?(@factory) && @x == rhs.x && @y == rhs.y && @z == rhs.z && @m == rhs.m
82
84
  end
83
85
 
84
86
  def hash
85
87
  @hash ||= [factory, geometry_type, @x, @y, @z, @m].hash
86
88
  end
87
89
 
88
- def _copy_state_from(obj_) # :nodoc:
89
- super
90
- @x = obj_.x
91
- @y = obj_.y
92
- @z = obj_.z
93
- @m = obj_.m
94
- end
95
-
96
90
  def coordinates
97
91
  [x, y].tap do |coords|
98
92
  coords << z if factory.property(:has_z_coordinate)
99
93
  coords << m if factory.property(:has_m_coordinate)
100
94
  end
101
95
  end
96
+
97
+ private
98
+
99
+ def copy_state_from(obj)
100
+ super
101
+ @x = obj.x
102
+ @y = obj.y
103
+ @z = obj.z
104
+ @m = obj.m
105
+ end
102
106
  end
103
107
  end
104
108
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # -----------------------------------------------------------------------------
2
4
  #
3
5
  # Common methods for Polygon features
@@ -7,20 +9,20 @@
7
9
  module RGeo
8
10
  module ImplHelper # :nodoc:
9
11
  module BasicPolygonMethods # :nodoc:
10
- def initialize(factory_, exterior_ring_, interior_rings_)
11
- _set_factory(factory_)
12
- @exterior_ring = Feature.cast(exterior_ring_, factory_, Feature::LinearRing)
12
+ def initialize(factory, exterior_ring, interior_rings)
13
+ self.factory = factory
14
+ @exterior_ring = Feature.cast(exterior_ring, factory, Feature::LinearRing)
13
15
  unless @exterior_ring
14
- raise Error::InvalidGeometry, "Failed to cast exterior ring #{exterior_ring_}"
16
+ raise Error::InvalidGeometry, "Failed to cast exterior ring #{exterior_ring}"
15
17
  end
16
- @interior_rings = (interior_rings_ || []).map do |elem_|
17
- elem_ = Feature.cast(elem_, factory_, Feature::LinearRing)
18
- unless elem_
19
- raise Error::InvalidGeometry, "Could not cast interior ring #{elem_}"
18
+ @interior_rings = (interior_rings || []).map do |elem|
19
+ elem = Feature.cast(elem, factory, Feature::LinearRing)
20
+ unless elem
21
+ raise Error::InvalidGeometry, "Could not cast interior ring #{elem}"
20
22
  end
21
- elem_
23
+ elem
22
24
  end
23
- _validate_geometry
25
+ validate_geometry
24
26
  end
25
27
 
26
28
  def exterior_ring
@@ -31,8 +33,8 @@ module RGeo
31
33
  @interior_rings.size
32
34
  end
33
35
 
34
- def interior_ring_n(n_)
35
- n_ < 0 ? nil : @interior_rings[n_]
36
+ def interior_ring_n(n)
37
+ n < 0 ? nil : @interior_rings[n]
36
38
  end
37
39
 
38
40
  def interior_rings
@@ -52,15 +54,15 @@ module RGeo
52
54
  end
53
55
 
54
56
  def boundary
55
- array_ = []
56
- array_ << @exterior_ring unless @exterior_ring.is_empty?
57
- array_.concat(@interior_rings)
58
- factory.multi_line_string(array_)
57
+ array = []
58
+ array << @exterior_ring unless @exterior_ring.is_empty?
59
+ array.concat(@interior_rings)
60
+ factory.multiline_string(array)
59
61
  end
60
62
 
61
- def rep_equals?(rhs_)
62
- if rhs_.is_a?(self.class) && rhs_.factory.eql?(@factory) && @exterior_ring.rep_equals?(rhs_.exterior_ring) && @interior_rings.size == rhs_.num_interior_rings
63
- rhs_.interior_rings.each_with_index { |r_, i_| return false unless @interior_rings[i_].rep_equals?(r_) }
63
+ def rep_equals?(rhs)
64
+ if rhs.is_a?(self.class) && rhs.factory.eql?(@factory) && @exterior_ring.rep_equals?(rhs.exterior_ring) && @interior_rings.size == rhs.num_interior_rings
65
+ rhs.interior_rings.each_with_index { |r, i| return false unless @interior_rings[i].rep_equals?(r) }
64
66
  else
65
67
  false
66
68
  end
@@ -68,20 +70,22 @@ module RGeo
68
70
 
69
71
  def hash
70
72
  @hash ||= begin
71
- hash_ = [geometry_type, @exterior_ring].hash
72
- @interior_rings.inject(hash_) { |h_, r_| (1_664_525 * h_ + r_.hash).hash }
73
+ hash = [geometry_type, @exterior_ring].hash
74
+ @interior_rings.inject(hash) { |h, r| (1_664_525 * h + r.hash).hash }
73
75
  end
74
76
  end
75
77
 
76
- def _copy_state_from(obj_) # :nodoc:
77
- super
78
- @exterior_ring = obj_.exterior_ring
79
- @interior_rings = obj_.interior_rings
80
- end
81
-
82
78
  def coordinates
83
79
  ([@exterior_ring] + @interior_rings).map(&:coordinates)
84
80
  end
81
+
82
+ private
83
+
84
+ def copy_state_from(obj)
85
+ super
86
+ @exterior_ring = obj.exterior_ring
87
+ @interior_rings = obj.interior_rings
88
+ end
85
89
  end
86
90
  end
87
91
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # -----------------------------------------------------------------------------
2
4
  #
3
5
  # Math constants and tools
@@ -1,28 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # -----------------------------------------------------------------------------
2
4
  #
3
- # Math constants and tools
5
+ # Utility module
4
6
  #
5
7
  # -----------------------------------------------------------------------------
6
8
 
7
9
  module RGeo
8
10
  module ImplHelper # :nodoc:
9
11
  module Utils # :nodoc:
10
- class << self
11
- def stringize_hash(hash_)
12
- nhash_ = {}
13
- hash_.each do |k_, v_|
14
- nhash_[k_.is_a?(::Symbol) ? k_.to_s : k_] = v_.is_a?(::Symbol) ? v_.to_s : v_
15
- end
16
- nhash_
17
- end
12
+ private
18
13
 
19
- def symbolize_hash(hash_)
20
- nhash_ = {}
21
- hash_.each do |k_, v_|
22
- nhash_[k_.is_a?(::String) ? k_.to_sym : k_] = v_.is_a?(::String) ? v_.to_sym : v_
23
- end
24
- nhash_
14
+ def symbolize_hash(hash)
15
+ nhash = {}
16
+ hash.each do |k, v|
17
+ nhash[k.to_sym] = v.is_a?(String) ? v.to_sym : v
25
18
  end
19
+ nhash
26
20
  end
27
21
  end
28
22
  end