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
|
# Projected geographic common method definitions
|
@@ -29,94 +31,88 @@ module RGeo
|
|
29
31
|
end
|
30
32
|
|
31
33
|
def boundary
|
32
|
-
|
33
|
-
|
34
|
+
boundary = projection.boundary
|
35
|
+
boundary ? factory.unproject(boundary) : nil
|
34
36
|
end
|
35
37
|
|
36
|
-
def equals?(
|
37
|
-
projection.equals?(Feature.cast(
|
38
|
+
def equals?(rhs)
|
39
|
+
projection.equals?(Feature.cast(rhs, factory).projection)
|
38
40
|
end
|
39
41
|
|
40
|
-
def disjoint?(
|
41
|
-
projection.disjoint?(Feature.cast(
|
42
|
+
def disjoint?(rhs)
|
43
|
+
projection.disjoint?(Feature.cast(rhs, factory).projection)
|
42
44
|
end
|
43
45
|
|
44
|
-
def intersects?(
|
45
|
-
projection.intersects?(Feature.cast(
|
46
|
+
def intersects?(rhs)
|
47
|
+
projection.intersects?(Feature.cast(rhs, factory).projection)
|
46
48
|
end
|
47
49
|
|
48
|
-
def touches?(
|
49
|
-
projection.touches?(Feature.cast(
|
50
|
+
def touches?(rhs)
|
51
|
+
projection.touches?(Feature.cast(rhs, factory).projection)
|
50
52
|
end
|
51
53
|
|
52
|
-
def crosses?(
|
53
|
-
projection.crosses?(Feature.cast(
|
54
|
+
def crosses?(rhs)
|
55
|
+
projection.crosses?(Feature.cast(rhs, factory).projection)
|
54
56
|
end
|
55
57
|
|
56
|
-
def within?(
|
57
|
-
projection.within?(Feature.cast(
|
58
|
+
def within?(rhs)
|
59
|
+
projection.within?(Feature.cast(rhs, factory).projection)
|
58
60
|
end
|
59
61
|
|
60
|
-
def contains?(
|
61
|
-
projection.contains?(Feature.cast(
|
62
|
+
def contains?(rhs)
|
63
|
+
projection.contains?(Feature.cast(rhs, factory).projection)
|
62
64
|
end
|
63
65
|
|
64
|
-
def overlaps?(
|
65
|
-
projection.overlaps?(Feature.cast(
|
66
|
+
def overlaps?(rhs)
|
67
|
+
projection.overlaps?(Feature.cast(rhs, factory).projection)
|
66
68
|
end
|
67
69
|
|
68
|
-
def relate(
|
69
|
-
projection.relate(Feature.cast(
|
70
|
+
def relate(rhs, pattern_)
|
71
|
+
projection.relate(Feature.cast(rhs, factory).projection, pattern_)
|
70
72
|
end
|
71
73
|
|
72
|
-
def distance(
|
73
|
-
projection.distance(Feature.cast(
|
74
|
+
def distance(rhs)
|
75
|
+
projection.distance(Feature.cast(rhs, factory).projection)
|
74
76
|
end
|
75
77
|
|
76
|
-
def buffer(
|
77
|
-
factory.unproject(projection.buffer(
|
78
|
+
def buffer(distance)
|
79
|
+
factory.unproject(projection.buffer(distance))
|
78
80
|
end
|
79
81
|
|
80
|
-
def buffer_with_style(
|
81
|
-
factory.unproject(projection.buffer_with_style(
|
82
|
+
def buffer_with_style(distance, end_cap_style, join_style, mitre_limit)
|
83
|
+
factory.unproject(projection.buffer_with_style(distance, end_cap_style, join_style, mitre_limit))
|
82
84
|
end
|
83
85
|
|
84
|
-
def simplify(
|
85
|
-
factory.unproject(projection.simplify(
|
86
|
+
def simplify(tolerance)
|
87
|
+
factory.unproject(projection.simplify(tolerance))
|
86
88
|
end
|
87
89
|
|
88
|
-
def simplify_preserve_topology(
|
89
|
-
factory.unproject(projection.simplify_preserve_topology(
|
90
|
+
def simplify_preserve_topology(tolerance)
|
91
|
+
factory.unproject(projection.simplify_preserve_topology(tolerance))
|
90
92
|
end
|
91
93
|
|
92
94
|
def convex_hull
|
93
95
|
factory.unproject(projection.convex_hull)
|
94
96
|
end
|
95
97
|
|
96
|
-
def intersection(
|
97
|
-
factory.unproject(projection.intersection(Feature.cast(
|
98
|
+
def intersection(rhs)
|
99
|
+
factory.unproject(projection.intersection(Feature.cast(rhs, factory).projection))
|
98
100
|
end
|
99
101
|
|
100
|
-
def union(
|
101
|
-
factory.unproject(projection.union(Feature.cast(
|
102
|
+
def union(rhs)
|
103
|
+
factory.unproject(projection.union(Feature.cast(rhs, factory).projection))
|
102
104
|
end
|
103
105
|
|
104
|
-
def difference(
|
105
|
-
factory.unproject(projection.difference(Feature.cast(
|
106
|
+
def difference(rhs)
|
107
|
+
factory.unproject(projection.difference(Feature.cast(rhs, factory).projection))
|
106
108
|
end
|
107
109
|
|
108
|
-
def sym_difference(
|
109
|
-
factory.unproject(projection.sym_difference(Feature.cast(
|
110
|
+
def sym_difference(rhs)
|
111
|
+
factory.unproject(projection.sym_difference(Feature.cast(rhs, factory).projection))
|
110
112
|
end
|
111
113
|
end
|
112
114
|
|
113
115
|
module ProjectedPointMethods # :nodoc:
|
114
|
-
def _validate_geometry
|
115
|
-
@y = 85.0511287 if @y > 85.0511287
|
116
|
-
@y = -85.0511287 if @y < -85.0511287
|
117
|
-
super
|
118
|
-
end
|
119
|
-
|
120
116
|
def canonical_x
|
121
117
|
x_ = @x % 360.0
|
122
118
|
x_ -= 360.0 if x_ > 180.0
|
@@ -133,14 +129,22 @@ module RGeo
|
|
133
129
|
end
|
134
130
|
end
|
135
131
|
|
136
|
-
def self.included(
|
137
|
-
|
132
|
+
def self.included(klass)
|
133
|
+
klass.module_eval do
|
138
134
|
alias_method :longitude, :x
|
139
135
|
alias_method :lon, :x
|
140
136
|
alias_method :latitude, :y
|
141
137
|
alias_method :lat, :y
|
142
138
|
end
|
143
139
|
end
|
140
|
+
|
141
|
+
private
|
142
|
+
|
143
|
+
def validate_geometry
|
144
|
+
@y = 85.0511287 if @y > 85.0511287
|
145
|
+
@y = -85.0511287 if @y < -85.0511287
|
146
|
+
super
|
147
|
+
end
|
144
148
|
end
|
145
149
|
|
146
150
|
module ProjectedNCurveMethods # :nodoc:
|
@@ -150,7 +154,9 @@ module RGeo
|
|
150
154
|
end
|
151
155
|
|
152
156
|
module ProjectedLineStringMethods # :nodoc:
|
153
|
-
|
157
|
+
private
|
158
|
+
|
159
|
+
def validate_geometry
|
154
160
|
@points = @points.map(&:canonical_point)
|
155
161
|
super
|
156
162
|
end
|
@@ -171,7 +177,9 @@ module RGeo
|
|
171
177
|
end
|
172
178
|
|
173
179
|
module ProjectedPolygonMethods # :nodoc:
|
174
|
-
|
180
|
+
private
|
181
|
+
|
182
|
+
def validate_geometry
|
175
183
|
super
|
176
184
|
unless projection
|
177
185
|
raise Error::InvalidGeometry, "Polygon failed assertions"
|
@@ -180,7 +188,9 @@ module RGeo
|
|
180
188
|
end
|
181
189
|
|
182
190
|
module ProjectedMultiPolygonMethods # :nodoc:
|
183
|
-
|
191
|
+
private
|
192
|
+
|
193
|
+
def validate_geometry
|
184
194
|
super
|
185
195
|
unless projection
|
186
196
|
raise Error::InvalidGeometry, "MultiPolygon failed assertions"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -----------------------------------------------------------------------------
|
2
4
|
#
|
3
5
|
# A projected window in a geography implementation
|
@@ -212,7 +214,7 @@ module RGeo
|
|
212
214
|
# this window.
|
213
215
|
|
214
216
|
def contains_window?(window_)
|
215
|
-
return
|
217
|
+
return if window_.factory != @factory
|
216
218
|
if window_.y_max <= @y_max && window_.y_min >= @y_min
|
217
219
|
if (@x_max < @x_min) == window_.crosses_seam?
|
218
220
|
window_.x_max <= @x_max && window_.x_min >= @x_min
|
@@ -354,7 +356,7 @@ module RGeo
|
|
354
356
|
y_max_ = y_ if !y_max_ || y_max_ < y_
|
355
357
|
y_min_ = y_ if !y_min_ || y_min_ > y_
|
356
358
|
end
|
357
|
-
return
|
359
|
+
return unless factory_
|
358
360
|
if x_array_
|
359
361
|
x_array_.sort!
|
360
362
|
largest_span_ = nil
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -----------------------------------------------------------------------------
|
2
4
|
#
|
3
5
|
# Simple mercator projection
|
@@ -9,76 +11,76 @@ module RGeo
|
|
9
11
|
class SimpleMercatorProjector # :nodoc:
|
10
12
|
EQUATORIAL_RADIUS = 6_378_137.0
|
11
13
|
|
12
|
-
def initialize(
|
13
|
-
@geography_factory =
|
14
|
+
def initialize(geography_factory, opts = {})
|
15
|
+
@geography_factory = geography_factory
|
14
16
|
@projection_factory = Cartesian.preferred_factory(srid: 3857,
|
15
17
|
proj4: SimpleMercatorProjector._proj4_3857,
|
16
18
|
coord_sys: SimpleMercatorProjector._coordsys_3857,
|
17
|
-
buffer_resolution:
|
18
|
-
lenient_multi_polygon_assertions:
|
19
|
-
uses_lenient_assertions:
|
20
|
-
has_z_coordinate:
|
21
|
-
has_m_coordinate:
|
19
|
+
buffer_resolution: opts[:buffer_resolution],
|
20
|
+
lenient_multi_polygon_assertions: opts[:lenient_multi_polygon_assertions],
|
21
|
+
uses_lenient_assertions: opts[:uses_lenient_assertions],
|
22
|
+
has_z_coordinate: opts[:has_z_coordinate],
|
23
|
+
has_m_coordinate: opts[:has_m_coordinate])
|
22
24
|
end
|
23
25
|
|
24
|
-
def
|
25
|
-
@geography_factory =
|
26
|
-
@projection_factory =
|
26
|
+
def set_factories(geography_factory, projection_factory)
|
27
|
+
@geography_factory = geography_factory
|
28
|
+
@projection_factory = projection_factory
|
27
29
|
end
|
28
30
|
|
29
31
|
attr_reader :projection_factory
|
30
32
|
|
31
|
-
def project(
|
32
|
-
case
|
33
|
+
def project(geometry)
|
34
|
+
case geometry
|
33
35
|
when Feature::Point
|
34
36
|
rpd_ = ImplHelper::Math::RADIANS_PER_DEGREE
|
35
|
-
|
36
|
-
@projection_factory.point(
|
37
|
-
|
37
|
+
radius = EQUATORIAL_RADIUS
|
38
|
+
@projection_factory.point(geometry.x * rpd_ * radius,
|
39
|
+
Math.log(Math.tan(Math::PI / 4.0 + geometry.y * rpd_ / 2.0)) * radius)
|
38
40
|
when Feature::Line
|
39
|
-
@projection_factory.line(project(
|
41
|
+
@projection_factory.line(project(geometry.start_point), project(geometry.end_point))
|
40
42
|
when Feature::LinearRing
|
41
|
-
@projection_factory.linear_ring(
|
43
|
+
@projection_factory.linear_ring(geometry.points.map { |p| project(p) })
|
42
44
|
when Feature::LineString
|
43
|
-
@projection_factory.line_string(
|
45
|
+
@projection_factory.line_string(geometry.points.map { |p| project(p) })
|
44
46
|
when Feature::Polygon
|
45
|
-
@projection_factory.polygon(project(
|
46
|
-
|
47
|
+
@projection_factory.polygon(project(geometry.exterior_ring),
|
48
|
+
geometry.interior_rings.map { |p| project(p) })
|
47
49
|
when Feature::MultiPoint
|
48
|
-
@projection_factory.multi_point(
|
50
|
+
@projection_factory.multi_point(geometry.map { |p| project(p) })
|
49
51
|
when Feature::MultiLineString
|
50
|
-
@projection_factory.multi_line_string(
|
52
|
+
@projection_factory.multi_line_string(geometry.map { |p| project(p) })
|
51
53
|
when Feature::MultiPolygon
|
52
|
-
@projection_factory.multi_polygon(
|
54
|
+
@projection_factory.multi_polygon(geometry.map { |p| project(p) })
|
53
55
|
when Feature::GeometryCollection
|
54
|
-
@projection_factory.collection(
|
56
|
+
@projection_factory.collection(geometry.map { |p| project(p) })
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
58
|
-
def unproject(
|
59
|
-
case
|
60
|
+
def unproject(geometry)
|
61
|
+
case geometry
|
60
62
|
when Feature::Point
|
61
|
-
|
62
|
-
|
63
|
-
@geography_factory.point(
|
64
|
-
(2.0 *
|
63
|
+
dpr = ImplHelper::Math::DEGREES_PER_RADIAN
|
64
|
+
radius = EQUATORIAL_RADIUS
|
65
|
+
@geography_factory.point(geometry.x / radius * dpr,
|
66
|
+
(2.0 * Math.atan(Math.exp(geometry.y / radius)) - Math::PI / 2.0) * dpr)
|
65
67
|
when Feature::Line
|
66
|
-
@geography_factory.line(unproject(
|
68
|
+
@geography_factory.line(unproject(geometry.start_point), unproject(geometry.end_point))
|
67
69
|
when Feature::LinearRing
|
68
|
-
@geography_factory.linear_ring(
|
70
|
+
@geography_factory.linear_ring(geometry.points.map { |p| unproject(p) })
|
69
71
|
when Feature::LineString
|
70
|
-
@geography_factory.line_string(
|
72
|
+
@geography_factory.line_string(geometry.points.map { |p| unproject(p) })
|
71
73
|
when Feature::Polygon
|
72
|
-
@geography_factory.polygon(unproject(
|
73
|
-
|
74
|
+
@geography_factory.polygon(unproject(geometry.exterior_ring),
|
75
|
+
geometry.interior_rings.map { |p| unproject(p) })
|
74
76
|
when Feature::MultiPoint
|
75
|
-
@geography_factory.multi_point(
|
77
|
+
@geography_factory.multi_point(geometry.map { |p| unproject(p) })
|
76
78
|
when Feature::MultiLineString
|
77
|
-
@geography_factory.multi_line_string(
|
79
|
+
@geography_factory.multi_line_string(geometry.map { |p| unproject(p) })
|
78
80
|
when Feature::MultiPolygon
|
79
|
-
@geography_factory.multi_polygon(
|
81
|
+
@geography_factory.multi_polygon(geometry.map { |p| unproject(p) })
|
80
82
|
when Feature::GeometryCollection
|
81
|
-
@geography_factory.collection(
|
83
|
+
@geography_factory.collection(geometry.map { |p| unproject(p) })
|
82
84
|
end
|
83
85
|
end
|
84
86
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -----------------------------------------------------------------------------
|
2
4
|
#
|
3
5
|
# Spherical geographic feature classes
|
@@ -12,8 +14,6 @@ module RGeo
|
|
12
14
|
include ImplHelper::BasicPointMethods
|
13
15
|
include SphericalGeometryMethods
|
14
16
|
include SphericalPointMethods
|
15
|
-
|
16
|
-
Feature::MixinCollection::GLOBAL.for_type(Feature::Point).include_in_class(self, true)
|
17
17
|
end
|
18
18
|
|
19
19
|
class SphericalLineStringImpl # :nodoc:
|
@@ -22,8 +22,6 @@ module RGeo
|
|
22
22
|
include ImplHelper::BasicLineStringMethods
|
23
23
|
include SphericalGeometryMethods
|
24
24
|
include SphericalLineStringMethods
|
25
|
-
|
26
|
-
Feature::MixinCollection::GLOBAL.for_type(Feature::LineString).include_in_class(self, true)
|
27
25
|
end
|
28
26
|
|
29
27
|
class SphericalLineImpl # :nodoc:
|
@@ -33,8 +31,6 @@ module RGeo
|
|
33
31
|
include ImplHelper::BasicLineMethods
|
34
32
|
include SphericalGeometryMethods
|
35
33
|
include SphericalLineStringMethods
|
36
|
-
|
37
|
-
Feature::MixinCollection::GLOBAL.for_type(Feature::Line).include_in_class(self, true)
|
38
34
|
end
|
39
35
|
|
40
36
|
class SphericalLinearRingImpl # :nodoc:
|
@@ -44,8 +40,6 @@ module RGeo
|
|
44
40
|
include ImplHelper::BasicLinearRingMethods
|
45
41
|
include SphericalGeometryMethods
|
46
42
|
include SphericalLineStringMethods
|
47
|
-
|
48
|
-
Feature::MixinCollection::GLOBAL.for_type(Feature::LinearRing).include_in_class(self, true)
|
49
43
|
end
|
50
44
|
|
51
45
|
class SphericalPolygonImpl # :nodoc:
|
@@ -53,8 +47,6 @@ module RGeo
|
|
53
47
|
include ImplHelper::BasicGeometryMethods
|
54
48
|
include ImplHelper::BasicPolygonMethods
|
55
49
|
include SphericalGeometryMethods
|
56
|
-
|
57
|
-
Feature::MixinCollection::GLOBAL.for_type(Feature::Polygon).include_in_class(self, true)
|
58
50
|
end
|
59
51
|
|
60
52
|
class SphericalGeometryCollectionImpl # :nodoc:
|
@@ -62,8 +54,6 @@ module RGeo
|
|
62
54
|
include ImplHelper::BasicGeometryMethods
|
63
55
|
include ImplHelper::BasicGeometryCollectionMethods
|
64
56
|
include SphericalGeometryMethods
|
65
|
-
|
66
|
-
Feature::MixinCollection::GLOBAL.for_type(Feature::GeometryCollection).include_in_class(self, true)
|
67
57
|
end
|
68
58
|
|
69
59
|
class SphericalMultiPointImpl # :nodoc:
|
@@ -72,8 +62,6 @@ module RGeo
|
|
72
62
|
include ImplHelper::BasicGeometryCollectionMethods
|
73
63
|
include ImplHelper::BasicMultiPointMethods
|
74
64
|
include SphericalGeometryMethods
|
75
|
-
|
76
|
-
Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPoint).include_in_class(self, true)
|
77
65
|
end
|
78
66
|
|
79
67
|
class SphericalMultiLineStringImpl # :nodoc:
|
@@ -83,8 +71,6 @@ module RGeo
|
|
83
71
|
include ImplHelper::BasicMultiLineStringMethods
|
84
72
|
include SphericalGeometryMethods
|
85
73
|
include SphericalMultiLineStringMethods
|
86
|
-
|
87
|
-
Feature::MixinCollection::GLOBAL.for_type(Feature::MultiLineString).include_in_class(self, true)
|
88
74
|
end
|
89
75
|
|
90
76
|
class SphericalMultiPolygonImpl # :nodoc:
|
@@ -93,8 +79,6 @@ module RGeo
|
|
93
79
|
include ImplHelper::BasicGeometryCollectionMethods
|
94
80
|
include ImplHelper::BasicMultiPolygonMethods
|
95
81
|
include SphericalGeometryMethods
|
96
|
-
|
97
|
-
Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPolygon).include_in_class(self, true)
|
98
82
|
end
|
99
83
|
end
|
100
84
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -----------------------------------------------------------------------------
|
2
4
|
#
|
3
5
|
# Spherical geographic common methods
|
@@ -13,121 +15,119 @@ module RGeo
|
|
13
15
|
end
|
14
16
|
|
15
17
|
module SphericalPointMethods # :nodoc:
|
16
|
-
def
|
17
|
-
if @x < -180.0 || @x > 180.0
|
18
|
-
@x = @x % 360.0
|
19
|
-
@x -= 360.0 if @x > 180.0
|
20
|
-
end
|
21
|
-
@y = 90.0 if @y > 90.0
|
22
|
-
@y = -90.0 if @y < -90.0
|
23
|
-
super
|
24
|
-
end
|
25
|
-
|
26
|
-
def _xyz
|
18
|
+
def xyz
|
27
19
|
@xyz ||= SphericalMath::PointXYZ.from_latlon(@y, @x)
|
28
20
|
end
|
29
21
|
|
30
|
-
def distance(
|
31
|
-
|
32
|
-
case
|
22
|
+
def distance(rhs)
|
23
|
+
rhs = Feature.cast(rhs, @factory)
|
24
|
+
case rhs
|
33
25
|
when SphericalPointImpl
|
34
|
-
|
26
|
+
xyz.dist_to_point(rhs.xyz) * SphericalMath::RADIUS
|
35
27
|
else
|
36
28
|
super
|
37
29
|
end
|
38
30
|
end
|
39
31
|
|
40
|
-
def equals?(
|
41
|
-
return false unless
|
42
|
-
case
|
32
|
+
def equals?(rhs)
|
33
|
+
return false unless rhs.is_a?(self.class) && rhs.factory == factory
|
34
|
+
case rhs
|
43
35
|
when Feature::Point
|
44
36
|
if @y == 90
|
45
|
-
|
37
|
+
rhs.y == 90
|
46
38
|
elsif @y == -90
|
47
|
-
|
39
|
+
rhs.y == -90
|
48
40
|
else
|
49
|
-
|
41
|
+
rhs.x == @x && rhs.y == @y
|
50
42
|
end
|
51
43
|
when Feature::LineString
|
52
|
-
|
44
|
+
rhs.num_points > 0 && rhs.points.all? { |elem| equals?(elem) }
|
53
45
|
when Feature::GeometryCollection
|
54
|
-
|
46
|
+
rhs.num_geometries > 0 && rhs.all? { |elem| equals?(elem) }
|
55
47
|
else
|
56
48
|
false
|
57
49
|
end
|
58
50
|
end
|
59
51
|
|
60
|
-
def buffer(
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
factory.point(*
|
52
|
+
def buffer(distance)
|
53
|
+
radius = distance / SphericalMath::RADIUS
|
54
|
+
radius = 1.5 if radius > 1.5
|
55
|
+
cos = Math.cos(radius)
|
56
|
+
sin = Math.sin(radius)
|
57
|
+
point_count = factory.property(:buffer_resolution) * 4
|
58
|
+
p0 = xyz
|
59
|
+
p1 = p0.create_perpendicular
|
60
|
+
p2 = p1 % p0
|
61
|
+
angle = Math::PI * 2.0 / point_count
|
62
|
+
points = (0...point_count).map do |i|
|
63
|
+
r = angle * i
|
64
|
+
pi = SphericalMath::PointXYZ.weighted_combination(p1, Math.cos(r), p2, Math.sin(r))
|
65
|
+
p = SphericalMath::PointXYZ.weighted_combination(p0, cos, pi, sin)
|
66
|
+
factory.point(*p.lonlat)
|
75
67
|
end
|
76
|
-
factory.polygon(factory.linear_ring(
|
68
|
+
factory.polygon(factory.linear_ring(points))
|
77
69
|
end
|
78
70
|
|
79
|
-
def self.included(
|
80
|
-
|
71
|
+
def self.included(klass)
|
72
|
+
klass.module_eval do
|
81
73
|
alias_method :longitude, :x
|
82
74
|
alias_method :lon, :x
|
83
75
|
alias_method :latitude, :y
|
84
76
|
alias_method :lat, :y
|
85
77
|
end
|
86
78
|
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def validate_geometry
|
83
|
+
if @x < -180.0 || @x > 180.0
|
84
|
+
@x = @x % 360.0
|
85
|
+
@x -= 360.0 if @x > 180.0
|
86
|
+
end
|
87
|
+
@y = 90.0 if @y > 90.0
|
88
|
+
@y = -90.0 if @y < -90.0
|
89
|
+
super
|
90
|
+
end
|
87
91
|
end
|
88
92
|
|
89
93
|
module SphericalLineStringMethods # :nodoc:
|
90
|
-
def
|
91
|
-
|
92
|
-
|
93
|
-
SphericalMath::ArcXYZ.new(point_n(i_)._xyz, point_n(i_ + 1)._xyz)
|
94
|
-
end
|
94
|
+
def arcs
|
95
|
+
@arcs ||= (0..num_points - 2).map do |i|
|
96
|
+
SphericalMath::ArcXYZ.new(point_n(i).xyz, point_n(i + 1).xyz)
|
95
97
|
end
|
96
|
-
@arcs
|
97
98
|
end
|
98
99
|
|
99
100
|
def is_simple?
|
100
|
-
|
101
|
-
|
102
|
-
return
|
103
|
-
return
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
oindex_ += 1
|
101
|
+
len = arcs.length
|
102
|
+
return false if arcs.any?(&:degenerate?)
|
103
|
+
return true if len == 1
|
104
|
+
return arcs[0].s != arcs[1].e if len == 2
|
105
|
+
arcs.each_with_index do |arc, index|
|
106
|
+
nindex = index + 1
|
107
|
+
nindex = nil if nindex == len
|
108
|
+
return false if nindex && arc.contains_point?(arcs[nindex].e)
|
109
|
+
pindex = index - 1
|
110
|
+
pindex = nil if pindex < 0
|
111
|
+
return false if pindex && arc.contains_point?(arcs[pindex].s)
|
112
|
+
next unless nindex
|
113
|
+
oindex = nindex + 1
|
114
|
+
while oindex < len
|
115
|
+
oarc = arcs[oindex]
|
116
|
+
return false if !(index == 0 && oindex == len - 1 && arc.s == oarc.e) && arc.intersects_arc?(oarc)
|
117
|
+
oindex += 1
|
118
118
|
end
|
119
119
|
end
|
120
120
|
true
|
121
121
|
end
|
122
122
|
|
123
123
|
def length
|
124
|
-
|
124
|
+
arcs.inject(0.0) { |sum, arc| sum + arc.length } * SphericalMath::RADIUS
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
128
|
module SphericalMultiLineStringMethods # :nodoc:
|
129
129
|
def length
|
130
|
-
inject(0.0) { |
|
130
|
+
inject(0.0) { |sum, geom| sum + geom.length }
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|