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.
- checksums.yaml +4 -4
- data/ext/geos_c_impl/extconf.rb +5 -3
- data/ext/geos_c_impl/factory.c +4 -4
- data/ext/geos_c_impl/geometry.c +1 -1
- data/lib/rgeo.rb +2 -4
- data/lib/rgeo/cartesian.rb +6 -16
- data/lib/rgeo/cartesian/analysis.rb +22 -20
- data/lib/rgeo/cartesian/bounding_box.rb +83 -79
- data/lib/rgeo/cartesian/calculations.rb +40 -38
- data/lib/rgeo/cartesian/factory.rb +134 -169
- data/lib/rgeo/cartesian/feature_classes.rb +2 -18
- data/lib/rgeo/cartesian/feature_methods.rb +37 -39
- data/lib/rgeo/cartesian/interface.rb +11 -9
- data/lib/rgeo/coord_sys.rb +9 -8
- data/lib/rgeo/coord_sys/cs/entities.rb +345 -303
- data/lib/rgeo/coord_sys/cs/factories.rb +30 -28
- data/lib/rgeo/coord_sys/cs/wkt_parser.rb +128 -126
- data/lib/rgeo/coord_sys/srs_database/{interface.rb → entry.rb} +26 -32
- data/lib/rgeo/coord_sys/srs_database/sr_org.rb +19 -17
- data/lib/rgeo/coord_sys/srs_database/url_reader.rb +21 -19
- data/lib/rgeo/error.rb +3 -1
- data/lib/rgeo/feature.rb +23 -34
- data/lib/rgeo/feature/curve.rb +2 -0
- data/lib/rgeo/feature/factory.rb +15 -13
- data/lib/rgeo/feature/factory_generator.rb +7 -5
- data/lib/rgeo/feature/geometry.rb +31 -29
- data/lib/rgeo/feature/geometry_collection.rb +6 -4
- data/lib/rgeo/feature/line.rb +2 -0
- data/lib/rgeo/feature/line_string.rb +3 -1
- data/lib/rgeo/feature/linear_ring.rb +2 -0
- data/lib/rgeo/feature/multi_curve.rb +2 -0
- data/lib/rgeo/feature/multi_line_string.rb +2 -0
- data/lib/rgeo/feature/multi_point.rb +2 -0
- data/lib/rgeo/feature/multi_polygon.rb +2 -0
- data/lib/rgeo/feature/multi_surface.rb +2 -0
- data/lib/rgeo/feature/point.rb +2 -0
- data/lib/rgeo/feature/polygon.rb +3 -1
- data/lib/rgeo/feature/surface.rb +2 -0
- data/lib/rgeo/feature/types.rb +107 -103
- data/lib/rgeo/geographic.rb +17 -27
- data/lib/rgeo/geographic/factory.rb +154 -199
- data/lib/rgeo/geographic/interface.rb +141 -137
- data/lib/rgeo/geographic/proj4_projector.rb +28 -23
- data/lib/rgeo/geographic/projected_feature_classes.rb +2 -18
- data/lib/rgeo/geographic/projected_feature_methods.rb +59 -49
- data/lib/rgeo/geographic/projected_window.rb +4 -2
- data/lib/rgeo/geographic/simple_mercator_projector.rb +41 -39
- data/lib/rgeo/geographic/spherical_feature_classes.rb +2 -18
- data/lib/rgeo/geographic/spherical_feature_methods.rb +67 -67
- data/lib/rgeo/geographic/spherical_math.rb +81 -87
- data/lib/rgeo/geos.rb +23 -34
- data/lib/rgeo/geos/capi_factory.rb +106 -135
- data/lib/rgeo/geos/capi_feature_classes.rb +19 -37
- data/lib/rgeo/geos/ffi_factory.rb +276 -297
- data/lib/rgeo/geos/ffi_feature_classes.rb +2 -20
- data/lib/rgeo/geos/ffi_feature_methods.rb +170 -166
- data/lib/rgeo/geos/interface.rb +25 -23
- data/lib/rgeo/geos/utils.rb +47 -39
- data/lib/rgeo/geos/zm_factory.rb +171 -185
- data/lib/rgeo/geos/zm_feature_classes.rb +2 -20
- data/lib/rgeo/geos/zm_feature_methods.rb +76 -72
- data/lib/rgeo/impl_helper.rb +1 -11
- data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +72 -75
- data/lib/rgeo/impl_helper/basic_geometry_methods.rb +21 -23
- data/lib/rgeo/impl_helper/basic_line_string_methods.rb +57 -49
- data/lib/rgeo/impl_helper/basic_point_methods.rb +29 -25
- data/lib/rgeo/impl_helper/basic_polygon_methods.rb +31 -27
- data/lib/rgeo/impl_helper/math.rb +2 -0
- data/lib/rgeo/impl_helper/utils.rb +9 -15
- data/lib/rgeo/version.rb +3 -1
- data/lib/rgeo/wkrep.rb +20 -30
- data/lib/rgeo/wkrep/wkb_generator.rb +87 -84
- data/lib/rgeo/wkrep/wkb_parser.rb +93 -93
- data/lib/rgeo/wkrep/wkt_generator.rb +67 -63
- data/lib/rgeo/wkrep/wkt_parser.rb +172 -168
- metadata +17 -32
- 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
|
21
|
-
|
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
|
28
|
-
@factory
|
28
|
+
def as_binary
|
29
|
+
@factory.generate_wkb(self)
|
29
30
|
end
|
30
31
|
|
31
|
-
def
|
32
|
-
@factory.
|
32
|
+
def marshal_dump # :nodoc:
|
33
|
+
[@factory, @factory.marshal_wkb_generator.generate(self)]
|
33
34
|
end
|
34
35
|
|
35
|
-
def
|
36
|
-
|
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
|
40
|
-
|
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
|
44
|
-
[
|
45
|
+
def init_with(coder) # :nodoc:
|
46
|
+
copy_state_from(coder["factory"].psych_wkt_parser.parse(coder["wkt"]))
|
45
47
|
end
|
46
48
|
|
47
|
-
|
48
|
-
_copy_state_from(data_[0]._marshal_wkb_parser.parse(data_[1]))
|
49
|
-
end
|
49
|
+
private
|
50
50
|
|
51
|
-
def
|
52
|
-
|
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
|
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(
|
11
|
-
|
12
|
-
@points =
|
13
|
-
|
14
|
-
raise Error::InvalidGeometry, "Could not cast #{
|
15
|
-
|
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(
|
31
|
-
|
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
|
-
|
52
|
-
|
53
|
-
factory.
|
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?(
|
76
|
-
if
|
77
|
-
|
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
|
-
|
86
|
-
@points.inject(
|
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
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
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(
|
11
|
-
|
12
|
-
@x =
|
13
|
-
@y =
|
14
|
-
@z =
|
15
|
-
@m =
|
16
|
-
if
|
17
|
-
raise
|
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
|
-
|
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?(
|
67
|
-
return false unless
|
68
|
-
case
|
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
|
-
|
72
|
+
rhs.x == @x && rhs.y == @y
|
71
73
|
when Feature::LineString
|
72
|
-
|
74
|
+
rhs.num_points > 0 && rhs.points.all? { |elem| equals?(elem) }
|
73
75
|
when Feature::GeometryCollection
|
74
|
-
|
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?(
|
81
|
-
|
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(
|
11
|
-
|
12
|
-
@exterior_ring = Feature.cast(
|
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 #{
|
16
|
+
raise Error::InvalidGeometry, "Failed to cast exterior ring #{exterior_ring}"
|
15
17
|
end
|
16
|
-
@interior_rings = (
|
17
|
-
|
18
|
-
unless
|
19
|
-
raise Error::InvalidGeometry, "Could not cast interior ring #{
|
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
|
-
|
23
|
+
elem
|
22
24
|
end
|
23
|
-
|
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(
|
35
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
factory.
|
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?(
|
62
|
-
if
|
63
|
-
|
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
|
-
|
72
|
-
@interior_rings.inject(
|
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,28 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -----------------------------------------------------------------------------
|
2
4
|
#
|
3
|
-
#
|
5
|
+
# Utility module
|
4
6
|
#
|
5
7
|
# -----------------------------------------------------------------------------
|
6
8
|
|
7
9
|
module RGeo
|
8
10
|
module ImplHelper # :nodoc:
|
9
11
|
module Utils # :nodoc:
|
10
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|