rgeo 1.1.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8472a195fa15704c94ed5074f539d815477b9d05e1354e4a47dcf7110235f5e
|
4
|
+
data.tar.gz: 81914f85026703454776fd5816c25869a35ba00f77f6509dc815205d2f35b604
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a6e0a821118e84e0052585431df5af8956a9f89882ce3314eeca72ff386617859bbe52a857b7761b8f8d8bc644a60734b5197fe209b20dd0d9fc294121735af
|
7
|
+
data.tar.gz: 2f68c55105f188e1f8c1b9c4bc1a5ae32e20b4dd630a3ade0038169a9d62fb3409cc85bad3c08bfb60bf0c73331f7c33192fb5c94622073974021e5b6447e9ae
|
data/ext/geos_c_impl/extconf.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -----------------------------------------------------------------------------
|
2
4
|
#
|
3
5
|
# Makefile builder for GEOS wrapper
|
4
6
|
#
|
5
7
|
# -----------------------------------------------------------------------------
|
6
8
|
def create_dummy_makefile
|
7
|
-
|
9
|
+
File.open("Makefile", "w") { |f_| f_.write(".PHONY: install\ninstall:\n") }
|
8
10
|
end
|
9
11
|
|
10
|
-
if
|
12
|
+
if RUBY_DESCRIPTION =~ /^jruby\s/
|
11
13
|
create_dummy_makefile
|
12
14
|
else
|
13
15
|
require "mkmf"
|
@@ -15,7 +17,7 @@ else
|
|
15
17
|
geosconfig = with_config("geos-config") || find_executable("geos-config")
|
16
18
|
|
17
19
|
if geosconfig
|
18
|
-
puts "Using GEOS compile configuration from
|
20
|
+
puts "Using GEOS compile configuration from #{geosconfig}"
|
19
21
|
$INCFLAGS << " " << `#{geosconfig} --cflags`.strip
|
20
22
|
geos_libs = `#{geosconfig} --clibs`.tr("\n", " ")
|
21
23
|
geos_libs.split(/\s+/).each do |flag|
|
data/ext/geos_c_impl/factory.c
CHANGED
@@ -623,10 +623,10 @@ RGeo_Globals* rgeo_init_geos_factory()
|
|
623
623
|
rb_define_method(geos_factory_class, "_wkb_generator", method_get_wkb_generator, 0);
|
624
624
|
rb_define_method(geos_factory_class, "_wkt_parser", method_get_wkt_parser, 0);
|
625
625
|
rb_define_method(geos_factory_class, "_wkb_parser", method_get_wkb_parser, 0);
|
626
|
-
rb_define_method(geos_factory_class, "
|
627
|
-
rb_define_method(geos_factory_class, "
|
628
|
-
rb_define_method(geos_factory_class, "
|
629
|
-
rb_define_method(geos_factory_class, "
|
626
|
+
rb_define_method(geos_factory_class, "read_for_marshal", method_factory_read_for_marshal, 1);
|
627
|
+
rb_define_method(geos_factory_class, "write_for_marshal", method_factory_write_for_marshal, 1);
|
628
|
+
rb_define_method(geos_factory_class, "read_for_psych", method_factory_read_for_psych, 1);
|
629
|
+
rb_define_method(geos_factory_class, "write_for_psych", method_factory_write_for_psych, 1);
|
630
630
|
rb_define_module_function(geos_factory_class, "_create", cmethod_factory_create, 7);
|
631
631
|
rb_define_module_function(geos_factory_class, "_geos_version", cmethod_factory_geos_version, 0);
|
632
632
|
rb_define_module_function(geos_factory_class, "_supports_unary_union?", cmethod_factory_supports_unary_union, 0);
|
data/ext/geos_c_impl/geometry.c
CHANGED
@@ -1063,7 +1063,7 @@ void rgeo_init_geos_geometry(RGeo_Globals* globals)
|
|
1063
1063
|
|
1064
1064
|
geos_geometry_methods = rb_define_module_under(globals->geos_module, "CAPIGeometryMethods");
|
1065
1065
|
|
1066
|
-
rb_define_method(geos_geometry_methods, "
|
1066
|
+
rb_define_method(geos_geometry_methods, "factory=", method_geometry_set_factory, 1);
|
1067
1067
|
rb_define_method(geos_geometry_methods, "initialize_copy", method_geometry_initialize_copy, 1);
|
1068
1068
|
rb_define_method(geos_geometry_methods, "_steal", method_geometry_steal, 1);
|
1069
1069
|
rb_define_method(geos_geometry_methods, "initialized?", method_geometry_initialized_p, 0);
|
data/lib/rgeo.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# RGeo is a spatial data library for Ruby. It focuses on the storage and
|
2
4
|
# manipulation of spatial data types such as points, lines, and polygons.
|
3
5
|
#
|
@@ -73,10 +75,6 @@
|
|
73
75
|
# database, and based on the postgresql adapter. Available as the
|
74
76
|
# activerecord-postgis-adapter gem.
|
75
77
|
|
76
|
-
module RGeo
|
77
|
-
end
|
78
|
-
|
79
|
-
# Core modules
|
80
78
|
require "rgeo/version"
|
81
79
|
require "rgeo/error"
|
82
80
|
require "rgeo/feature"
|
data/lib/rgeo/cartesian.rb
CHANGED
@@ -1,21 +1,11 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# Cartesian features for RGeo
|
4
|
-
#
|
5
|
-
# -----------------------------------------------------------------------------
|
1
|
+
# frozen_string_literal: true
|
6
2
|
|
7
|
-
module
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
# for Cartesian-specific analysis tools.
|
3
|
+
# The Cartesian module is a gateway to implementations that use the
|
4
|
+
# Cartesian (i.e. flat) coordinate system. It provides convenient
|
5
|
+
# access to Cartesian factories such as the Geos implementation and
|
6
|
+
# the simple Cartesian implementation. It also provides a namespace
|
7
|
+
# for Cartesian-specific analysis tools.
|
13
8
|
|
14
|
-
module Cartesian
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
# Implementation files.
|
19
9
|
require "rgeo/cartesian/calculations"
|
20
10
|
require "rgeo/cartesian/feature_methods"
|
21
11
|
require "rgeo/cartesian/feature_classes"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -----------------------------------------------------------------------------
|
2
4
|
#
|
3
5
|
# Cartesian geometric analysis utilities
|
@@ -19,33 +21,33 @@ module RGeo
|
|
19
21
|
# The return value is undefined if the object is not a ring, or
|
20
22
|
# is not in a Cartesian coordinate system.
|
21
23
|
|
22
|
-
def ring_direction(
|
23
|
-
|
24
|
-
return 0 if
|
24
|
+
def ring_direction(ring)
|
25
|
+
size = ring.num_points - 1
|
26
|
+
return 0 if size == 0
|
25
27
|
|
26
28
|
# Extract unit-length segments from the ring.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
if
|
35
|
-
|
29
|
+
segs = []
|
30
|
+
size.times do |i|
|
31
|
+
p0 = ring.point_n(i)
|
32
|
+
p1 = ring.point_n(i + 1)
|
33
|
+
x = p1.x - p0.x
|
34
|
+
y = p1.y - p0.y
|
35
|
+
r = Math.sqrt(x * x + y * y)
|
36
|
+
if r > 0.0
|
37
|
+
segs << x / r << y / r
|
36
38
|
else
|
37
|
-
|
39
|
+
size -= 1
|
38
40
|
end
|
39
41
|
end
|
40
|
-
|
42
|
+
segs << segs[0] << segs[1]
|
41
43
|
|
42
44
|
# Extract angles from the segments by subtracting the segments.
|
43
45
|
# Note angles are represented as cos/sin pairs so we don't
|
44
46
|
# have to calculate any trig functions.
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
angs = []
|
48
|
+
size.times do |i|
|
49
|
+
x0, y0, x1, y1 = segs[i * 2, 4]
|
50
|
+
angs << x0 * x1 + y0 * y1 << x0 * y1 - x1 * y0
|
49
51
|
end
|
50
52
|
|
51
53
|
# Now add the angles and count revolutions.
|
@@ -54,12 +56,12 @@ module RGeo
|
|
54
56
|
direction = nil
|
55
57
|
sin = 0.0
|
56
58
|
cos = 1.0
|
57
|
-
|
59
|
+
angs.each_slice(2) do |(x, y)|
|
58
60
|
ready = y > 0.0 && (sin > 0.0 || sin == 0.0 && direction == -1) || y < 0.0 && (sin < 0.0 || sin == 0.0 && direction == 1)
|
59
61
|
if y != 0.0
|
60
62
|
s = sin * x + cos * y
|
61
63
|
c = cos * x - sin * y
|
62
|
-
r =
|
64
|
+
r = Math.sqrt(s * s + c * c)
|
63
65
|
sin = s / r
|
64
66
|
cos = c / r
|
65
67
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -----------------------------------------------------------------------------
|
2
4
|
#
|
3
5
|
# Cartesian bounding box
|
@@ -24,9 +26,9 @@ module RGeo
|
|
24
26
|
# You may also provide the same options available to
|
25
27
|
# BoundingBox.new.
|
26
28
|
|
27
|
-
def self.create_from_points(
|
28
|
-
|
29
|
-
new(
|
29
|
+
def self.create_from_points(point1, point2, opts = {})
|
30
|
+
factory = point1.factory
|
31
|
+
new(factory, opts).add_geometry(point1).add(point2)
|
30
32
|
end
|
31
33
|
|
32
34
|
# Create a bounding box given a geometry to surround.
|
@@ -34,9 +36,9 @@ module RGeo
|
|
34
36
|
# You may also provide the same options available to
|
35
37
|
# BoundingBox.new.
|
36
38
|
|
37
|
-
def self.create_from_geometry(
|
38
|
-
|
39
|
-
new(
|
39
|
+
def self.create_from_geometry(geom, opts = {})
|
40
|
+
factory = geom.factory
|
41
|
+
new(factory, opts).add_geometry(geom)
|
40
42
|
end
|
41
43
|
|
42
44
|
# Create a new empty bounding box with the given factory.
|
@@ -56,23 +58,23 @@ module RGeo
|
|
56
58
|
# If true, ignore m coordinates even if the factory supports them.
|
57
59
|
# Default is false.
|
58
60
|
|
59
|
-
def initialize(
|
60
|
-
@factory =
|
61
|
-
if (
|
62
|
-
@has_z, @has_m, @min_x, @max_x, @min_y, @max_y, @min_z, @max_z, @min_m, @max_m =
|
61
|
+
def initialize(factory, opts = {})
|
62
|
+
@factory = factory
|
63
|
+
if (values = opts[:raw])
|
64
|
+
@has_z, @has_m, @min_x, @max_x, @min_y, @max_y, @min_z, @max_z, @min_m, @max_m = values
|
63
65
|
else
|
64
|
-
@has_z = !
|
65
|
-
@has_m = !
|
66
|
+
@has_z = !opts[:ignore_z] && factory.property(:has_z_coordinate) ? true : false
|
67
|
+
@has_m = !opts[:ignore_m] && factory.property(:has_m_coordinate) ? true : false
|
66
68
|
@min_x = @max_x = @min_y = @max_y = @min_z = @max_z = @min_m = @max_m = nil
|
67
69
|
end
|
68
70
|
end
|
69
71
|
|
70
|
-
def eql?(
|
71
|
-
|
72
|
-
@min_x ==
|
73
|
-
@min_y ==
|
74
|
-
@min_z ==
|
75
|
-
@min_m ==
|
72
|
+
def eql?(rhs) # :nodoc:
|
73
|
+
rhs.is_a?(BoundingBox) && @factory == rhs.factory &&
|
74
|
+
@min_x == rhs.min_x && @max_x == rhs.max_x &&
|
75
|
+
@min_y == rhs.min_y && @max_y == rhs.max_y &&
|
76
|
+
@min_z == rhs.min_z && @max_z == rhs.max_z &&
|
77
|
+
@min_m == rhs.min_m && @max_m == rhs.max_m
|
76
78
|
end
|
77
79
|
alias == eql?
|
78
80
|
|
@@ -196,10 +198,10 @@ module RGeo
|
|
196
198
|
|
197
199
|
def min_point
|
198
200
|
if @min_x
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
@factory.point(@min_x, @min_y, *
|
201
|
+
extras = []
|
202
|
+
extras << @min_z if @has_z
|
203
|
+
extras << @min_m if @has_m
|
204
|
+
@factory.point(@min_x, @min_y, *extras)
|
203
205
|
end
|
204
206
|
end
|
205
207
|
|
@@ -208,10 +210,10 @@ module RGeo
|
|
208
210
|
|
209
211
|
def max_point
|
210
212
|
if @min_x
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
@factory.point(@max_x, @max_y, *
|
213
|
+
extras = []
|
214
|
+
extras << @max_z if @has_z
|
215
|
+
extras << @max_m if @has_m
|
216
|
+
@factory.point(@max_x, @max_y, *extras)
|
215
217
|
end
|
216
218
|
end
|
217
219
|
|
@@ -219,16 +221,16 @@ module RGeo
|
|
219
221
|
# object, which may be a geometry or another bounding box.
|
220
222
|
# Returns self.
|
221
223
|
|
222
|
-
def add(
|
223
|
-
case
|
224
|
+
def add(geometry)
|
225
|
+
case geometry
|
224
226
|
when BoundingBox
|
225
|
-
add(
|
226
|
-
add(
|
227
|
+
add(geometry.min_point)
|
228
|
+
add(geometry.max_point)
|
227
229
|
when Feature::Geometry
|
228
|
-
if
|
229
|
-
|
230
|
+
if geometry.factory == @factory
|
231
|
+
add_geometry(geometry)
|
230
232
|
else
|
231
|
-
|
233
|
+
add_geometry(Feature.cast(geometry, @factory))
|
232
234
|
end
|
233
235
|
end
|
234
236
|
self
|
@@ -241,23 +243,23 @@ module RGeo
|
|
241
243
|
|
242
244
|
def to_geometry
|
243
245
|
if @min_x
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
246
|
+
extras = []
|
247
|
+
extras << @min_z if @has_z
|
248
|
+
extras << @min_m if @has_m
|
249
|
+
point_min = @factory.point(@min_x, @min_y, *extras)
|
248
250
|
if infinitesimal?
|
249
|
-
|
251
|
+
point_min
|
250
252
|
else
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
253
|
+
extras = []
|
254
|
+
extras << @max_z if @has_z
|
255
|
+
extras << @max_m if @has_m
|
256
|
+
point_max = @factory.point(@max_x, @max_y, *extras)
|
255
257
|
if degenerate?
|
256
|
-
@factory.line(
|
258
|
+
@factory.line(point_min, point_max)
|
257
259
|
else
|
258
|
-
@factory.polygon(@factory.linear_ring([
|
259
|
-
@factory.point(@max_x, @min_y, *
|
260
|
-
@factory.point(@min_x, @max_y, *
|
260
|
+
@factory.polygon(@factory.linear_ring([point_min,
|
261
|
+
@factory.point(@max_x, @min_y, *extras), point_max,
|
262
|
+
@factory.point(@min_x, @max_y, *extras), point_min]))
|
261
263
|
end
|
262
264
|
end
|
263
265
|
else
|
@@ -277,18 +279,18 @@ module RGeo
|
|
277
279
|
# Ignore the M coordinate when testing, even if both objects
|
278
280
|
# have M. Default is false.
|
279
281
|
|
280
|
-
def contains?(
|
281
|
-
if Feature::Geometry ===
|
282
|
-
contains?(BoundingBox.new(@factory).add(
|
283
|
-
elsif
|
282
|
+
def contains?(rhs, opts = {})
|
283
|
+
if Feature::Geometry === rhs
|
284
|
+
contains?(BoundingBox.new(@factory).add(rhs))
|
285
|
+
elsif rhs.empty?
|
284
286
|
true
|
285
287
|
elsif empty?
|
286
288
|
false
|
287
|
-
elsif @min_x >
|
289
|
+
elsif @min_x > rhs.min_x || @max_x < rhs.max_x || @min_y > rhs.min_y || @max_y < rhs.max_y
|
288
290
|
false
|
289
|
-
elsif @has_m &&
|
291
|
+
elsif @has_m && rhs.has_m && !opts[:ignore_m] && (@min_m > rhs.min_m || @max_m < rhs.max_m)
|
290
292
|
false
|
291
|
-
elsif @has_z &&
|
293
|
+
elsif @has_z && rhs.has_z && !opts[:ignore_z] && (@min_z > rhs.min_z || @max_z < rhs.max_z)
|
292
294
|
false
|
293
295
|
else
|
294
296
|
true
|
@@ -309,7 +311,7 @@ module RGeo
|
|
309
311
|
# greater than this factor, the bounding box is divided only in
|
310
312
|
# half instead of fourths.
|
311
313
|
|
312
|
-
def subdivide(
|
314
|
+
def subdivide(opts = {})
|
313
315
|
return [] if empty?
|
314
316
|
if infinitesimal?
|
315
317
|
return [
|
@@ -317,17 +319,17 @@ module RGeo
|
|
317
319
|
@min_x, @max_x, @min_y, @max_y, @min_z, @max_z, @min_m, @max_m])
|
318
320
|
]
|
319
321
|
end
|
320
|
-
|
321
|
-
|
322
|
-
if
|
323
|
-
if x_span > y_span *
|
322
|
+
factor = opts[:bisect_factor]
|
323
|
+
factor ||= 1 if degenerate?
|
324
|
+
if factor
|
325
|
+
if x_span > y_span * factor
|
324
326
|
return [
|
325
327
|
BoundingBox.new(@factory, raw: [@has_z, @has_m,
|
326
328
|
@min_x, center_x, @min_y, @max_y, @min_z, @max_z, @min_m, @max_m]),
|
327
329
|
BoundingBox.new(@factory, raw: [@has_z, @has_m,
|
328
330
|
center_x, @max_x, @min_y, @max_y, @min_z, @max_z, @min_m, @max_m])
|
329
331
|
]
|
330
|
-
elsif y_span > x_span *
|
332
|
+
elsif y_span > x_span * factor
|
331
333
|
return [
|
332
334
|
BoundingBox.new(@factory, raw: [@has_z, @has_m,
|
333
335
|
@min_x, @max_x, @min_y, center_y, @min_z, @max_z, @min_m, @max_m]),
|
@@ -348,49 +350,51 @@ module RGeo
|
|
348
350
|
]
|
349
351
|
end
|
350
352
|
|
351
|
-
def
|
352
|
-
case
|
353
|
+
def add_geometry(geometry)
|
354
|
+
case geometry
|
353
355
|
when Feature::Point
|
354
|
-
|
356
|
+
add_point(geometry)
|
355
357
|
when Feature::LineString
|
356
|
-
|
358
|
+
geometry.points.each { |p| add_point(p) }
|
357
359
|
when Feature::Polygon
|
358
|
-
|
360
|
+
geometry.exterior_ring.points.each { |p| add_point(p) }
|
359
361
|
when Feature::MultiPoint
|
360
|
-
|
362
|
+
geometry.each { |p| add_point(p) }
|
361
363
|
when Feature::MultiLineString
|
362
|
-
|
364
|
+
geometry.each { |line| line.points.each { |p| add_point(p) } }
|
363
365
|
when Feature::MultiPolygon
|
364
|
-
|
366
|
+
geometry.each { |poly| poly.exterior_ring.points.each { |p| add_point(p) } }
|
365
367
|
when Feature::GeometryCollection
|
366
|
-
|
368
|
+
geometry.each { |g| add_geometry(g) }
|
367
369
|
end
|
368
370
|
self
|
369
371
|
end
|
370
372
|
|
371
|
-
|
373
|
+
private
|
374
|
+
|
375
|
+
def add_point(point)
|
372
376
|
if @min_x
|
373
|
-
|
374
|
-
@min_x =
|
375
|
-
@max_x =
|
376
|
-
y_ =
|
377
|
+
x = point.x
|
378
|
+
@min_x = x if x < @min_x
|
379
|
+
@max_x = x if x > @max_x
|
380
|
+
y_ = point.y
|
377
381
|
@min_y = y_ if y_ < @min_y
|
378
382
|
@max_y = y_ if y_ > @max_y
|
379
383
|
if @has_z
|
380
|
-
z_ =
|
384
|
+
z_ = point.z
|
381
385
|
@min_z = z_ if z_ < @min_z
|
382
386
|
@max_z = z_ if z_ > @max_z
|
383
387
|
end
|
384
388
|
if @has_m
|
385
|
-
m_ =
|
389
|
+
m_ = point.m
|
386
390
|
@min_m = m_ if m_ < @min_m
|
387
391
|
@max_m = m_ if m_ > @max_m
|
388
392
|
end
|
389
393
|
else
|
390
|
-
@min_x = @max_x =
|
391
|
-
@min_y = @max_y =
|
392
|
-
@min_z = @max_z =
|
393
|
-
@min_m = @max_m =
|
394
|
+
@min_x = @max_x = point.x
|
395
|
+
@min_y = @max_y = point.y
|
396
|
+
@min_z = @max_z = point.z if @has_z
|
397
|
+
@min_m = @max_m = point.m if @has_m
|
394
398
|
end
|
395
399
|
end
|
396
400
|
end
|