rgeo 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +29 -0
- data/ext/geos_c_impl/Makefile_2.2.3 +260 -0
- data/ext/geos_c_impl/coordinates.c +65 -0
- data/ext/geos_c_impl/coordinates.h +2 -0
- data/ext/geos_c_impl/extconf.rb +19 -43
- data/ext/geos_c_impl/geometry.c +24 -0
- data/ext/geos_c_impl/geometry_collection.c +99 -1
- data/ext/geos_c_impl/geos_c_impl_2.2.3.bundle +0 -0
- data/ext/geos_c_impl/line_string.c +38 -0
- data/ext/geos_c_impl/mkmf.log +123 -0
- data/ext/geos_c_impl/point.c +27 -0
- data/ext/geos_c_impl/polygon.c +26 -0
- data/ext/proj4_c_impl/Makefile_2.2.3 +260 -0
- data/ext/proj4_c_impl/extconf.rb +32 -32
- data/ext/proj4_c_impl/mkmf.log +47 -0
- data/ext/proj4_c_impl/proj4_c_impl_2.2.3.bundle +0 -0
- data/lib/rgeo.rb +10 -11
- data/lib/rgeo/cartesian.rb +7 -12
- data/lib/rgeo/cartesian/analysis.rb +13 -26
- data/lib/rgeo/cartesian/bounding_box.rb +45 -114
- data/lib/rgeo/cartesian/calculations.rb +3 -21
- data/lib/rgeo/cartesian/factory.rb +101 -122
- data/lib/rgeo/cartesian/feature_classes.rb +9 -59
- data/lib/rgeo/cartesian/feature_methods.rb +15 -45
- data/lib/rgeo/cartesian/interface.rb +6 -17
- data/lib/rgeo/coord_sys.rb +9 -15
- data/lib/rgeo/coord_sys/cs/entities.rb +84 -330
- data/lib/rgeo/coord_sys/cs/factories.rb +2 -32
- data/lib/rgeo/coord_sys/cs/wkt_parser.rb +52 -80
- data/lib/rgeo/coord_sys/proj4.rb +28 -67
- data/lib/rgeo/coord_sys/proj4_c_impl.bundle +0 -0
- data/lib/rgeo/coord_sys/srs_database/interface.rb +4 -24
- data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +20 -38
- data/lib/rgeo/coord_sys/srs_database/sr_org.rb +6 -22
- data/lib/rgeo/coord_sys/srs_database/url_reader.rb +6 -21
- data/lib/rgeo/error.rb +0 -6
- data/lib/rgeo/feature.rb +18 -23
- data/lib/rgeo/feature/curve.rb +0 -14
- data/lib/rgeo/feature/factory.rb +13 -38
- data/lib/rgeo/feature/factory_generator.rb +4 -16
- data/lib/rgeo/feature/geometry.rb +18 -60
- data/lib/rgeo/feature/geometry_collection.rb +3 -17
- data/lib/rgeo/feature/line.rb +0 -10
- data/lib/rgeo/feature/line_string.rb +1 -13
- data/lib/rgeo/feature/linear_ring.rb +0 -9
- data/lib/rgeo/feature/mixins.rb +11 -36
- data/lib/rgeo/feature/multi_curve.rb +0 -11
- data/lib/rgeo/feature/multi_line_string.rb +0 -9
- data/lib/rgeo/feature/multi_point.rb +0 -9
- data/lib/rgeo/feature/multi_polygon.rb +0 -9
- data/lib/rgeo/feature/multi_surface.rb +0 -12
- data/lib/rgeo/feature/point.rb +0 -13
- data/lib/rgeo/feature/polygon.rb +1 -14
- data/lib/rgeo/feature/surface.rb +0 -12
- data/lib/rgeo/feature/types.rb +19 -61
- data/lib/rgeo/geographic.rb +10 -15
- data/lib/rgeo/geographic/factory.rb +126 -147
- data/lib/rgeo/geographic/interface.rb +67 -81
- data/lib/rgeo/geographic/proj4_projector.rb +13 -37
- data/lib/rgeo/geographic/projected_feature_classes.rb +7 -66
- data/lib/rgeo/geographic/projected_feature_methods.rb +15 -80
- data/lib/rgeo/geographic/projected_window.rb +15 -67
- data/lib/rgeo/geographic/simple_mercator_projector.rb +32 -56
- data/lib/rgeo/geographic/spherical_feature_classes.rb +9 -68
- data/lib/rgeo/geographic/spherical_feature_methods.rb +18 -51
- data/lib/rgeo/geographic/spherical_math.rb +26 -51
- data/lib/rgeo/geos.rb +23 -20
- data/lib/rgeo/geos/capi_factory.rb +125 -131
- data/lib/rgeo/geos/capi_feature_classes.rb +21 -88
- data/lib/rgeo/geos/ffi_factory.rb +90 -143
- data/lib/rgeo/geos/ffi_feature_classes.rb +8 -63
- data/lib/rgeo/geos/ffi_feature_methods.rb +46 -162
- data/lib/rgeo/geos/geos_c_impl.bundle +0 -0
- data/lib/rgeo/geos/interface.rb +4 -23
- data/lib/rgeo/geos/utils.rb +4 -19
- data/lib/rgeo/geos/zm_factory.rb +82 -131
- data/lib/rgeo/geos/zm_feature_classes.rb +8 -63
- data/lib/rgeo/geos/zm_feature_methods.rb +34 -107
- data/lib/rgeo/impl_helper.rb +8 -13
- data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +27 -71
- data/lib/rgeo/impl_helper/basic_geometry_methods.rb +10 -28
- data/lib/rgeo/impl_helper/basic_line_string_methods.rb +21 -57
- data/lib/rgeo/impl_helper/basic_point_methods.rb +12 -30
- data/lib/rgeo/impl_helper/basic_polygon_methods.rb +9 -28
- data/lib/rgeo/impl_helper/math.rb +4 -10
- data/lib/rgeo/impl_helper/utils.rb +2 -10
- data/lib/rgeo/version.rb +1 -1
- data/lib/rgeo/wkrep.rb +4 -9
- data/lib/rgeo/wkrep/wkb_generator.rb +22 -46
- data/lib/rgeo/wkrep/wkb_parser.rb +25 -52
- data/lib/rgeo/wkrep/wkt_generator.rb +39 -69
- data/lib/rgeo/wkrep/wkt_parser.rb +52 -89
- data/lib/rgeo/yaml.rb +1 -7
- data/test/common/factory_tests.rb +4 -19
- data/test/common/geometry_collection_tests.rb +6 -39
- data/test/common/line_string_tests.rb +10 -39
- data/test/common/multi_line_string_tests.rb +10 -30
- data/test/common/multi_point_tests.rb +15 -34
- data/test/common/multi_polygon_tests.rb +26 -28
- data/test/common/point_tests.rb +37 -59
- data/test/common/polygon_tests.rb +16 -25
- data/test/coord_sys/tc_ogc_cs.rb +151 -186
- data/test/coord_sys/tc_proj4.rb +35 -60
- data/test/coord_sys/tc_proj4_srs_data.rb +15 -24
- data/test/coord_sys/tc_sr_org.rb +11 -19
- data/test/coord_sys/tc_url_reader.rb +13 -23
- data/test/geos_capi/tc_factory.rb +7 -16
- data/test/geos_capi/tc_geometry_collection.rb +6 -14
- data/test/geos_capi/tc_line_string.rb +7 -15
- data/test/geos_capi/tc_misc.rb +26 -41
- data/test/geos_capi/tc_multi_line_string.rb +6 -14
- data/test/geos_capi/tc_multi_point.rb +7 -15
- data/test/geos_capi/tc_multi_polygon.rb +8 -18
- data/test/geos_capi/tc_parsing_unparsing.rb +11 -21
- data/test/geos_capi/tc_point.rb +12 -26
- data/test/geos_capi/tc_polygon.rb +52 -17
- data/test/geos_capi/tc_zmfactory.rb +7 -18
- data/test/geos_ffi/tc_factory.rb +7 -16
- data/test/geos_ffi/tc_geometry_collection.rb +7 -15
- data/test/geos_ffi/tc_line_string.rb +7 -15
- data/test/geos_ffi/tc_misc.rb +8 -18
- data/test/geos_ffi/tc_multi_line_string.rb +7 -15
- data/test/geos_ffi/tc_multi_point.rb +8 -16
- data/test/geos_ffi/tc_multi_polygon.rb +9 -18
- data/test/geos_ffi/tc_parsing_unparsing.rb +14 -24
- data/test/geos_ffi/tc_point.rb +13 -28
- data/test/geos_ffi/tc_polygon.rb +7 -17
- data/test/geos_ffi/tc_zmfactory.rb +8 -19
- data/test/projected_geographic/tc_factory.rb +7 -15
- data/test/projected_geographic/tc_geometry_collection.rb +7 -15
- data/test/projected_geographic/tc_line_string.rb +7 -15
- data/test/projected_geographic/tc_multi_line_string.rb +7 -16
- data/test/projected_geographic/tc_multi_point.rb +8 -17
- data/test/projected_geographic/tc_multi_polygon.rb +8 -16
- data/test/projected_geographic/tc_point.rb +11 -23
- data/test/projected_geographic/tc_polygon.rb +7 -15
- data/test/simple_cartesian/tc_calculations.rb +6 -22
- data/test/simple_cartesian/tc_factory.rb +7 -16
- data/test/simple_cartesian/tc_geometry_collection.rb +6 -15
- data/test/simple_cartesian/tc_line_string.rb +6 -15
- data/test/simple_cartesian/tc_multi_line_string.rb +6 -15
- data/test/simple_cartesian/tc_multi_point.rb +7 -16
- data/test/simple_cartesian/tc_multi_polygon.rb +7 -16
- data/test/simple_cartesian/tc_point.rb +10 -21
- data/test/simple_cartesian/tc_polygon.rb +6 -15
- data/test/simple_mercator/tc_factory.rb +6 -14
- data/test/simple_mercator/tc_geometry_collection.rb +6 -14
- data/test/simple_mercator/tc_line_string.rb +6 -14
- data/test/simple_mercator/tc_multi_line_string.rb +6 -15
- data/test/simple_mercator/tc_multi_point.rb +7 -16
- data/test/simple_mercator/tc_multi_polygon.rb +7 -15
- data/test/simple_mercator/tc_point.rb +11 -24
- data/test/simple_mercator/tc_polygon.rb +6 -14
- data/test/simple_mercator/tc_window.rb +10 -34
- data/test/spherical_geographic/tc_calculations.rb +5 -32
- data/test/spherical_geographic/tc_factory.rb +6 -15
- data/test/spherical_geographic/tc_geometry_collection.rb +6 -15
- data/test/spherical_geographic/tc_line_string.rb +6 -15
- data/test/spherical_geographic/tc_multi_line_string.rb +6 -15
- data/test/spherical_geographic/tc_multi_point.rb +7 -16
- data/test/spherical_geographic/tc_multi_polygon.rb +7 -16
- data/test/spherical_geographic/tc_point.rb +10 -22
- data/test/spherical_geographic/tc_polygon.rb +6 -15
- data/test/tc_cartesian_analysis.rb +4 -16
- data/test/tc_cartesian_bbox.rb +7 -21
- data/test/tc_mixins.rb +8 -25
- data/test/tc_oneoff.rb +5 -13
- data/test/tc_types.rb +7 -16
- data/test/wkrep/tc_wkb_generator.rb +63 -97
- data/test/wkrep/tc_wkb_parser.rb +63 -100
- data/test/wkrep/tc_wkt_generator.rb +54 -92
- data/test/wkrep/tc_wkt_parser.rb +84 -133
- metadata +39 -9
- data/lib/rgeo/coord_sys/srs_database/active_record_table.rb +0 -166
- data/test/coord_sys/tc_active_record_table.rb +0 -79
@@ -5,18 +5,12 @@
|
|
5
5
|
# -----------------------------------------------------------------------------
|
6
6
|
|
7
7
|
module RGeo
|
8
|
-
|
9
8
|
module Cartesian
|
10
|
-
|
11
|
-
|
12
9
|
# This provides includes some spatial analysis algorithms supporting
|
13
10
|
# Cartesian data.
|
14
11
|
|
15
12
|
module Analysis
|
16
|
-
|
17
13
|
class << self
|
18
|
-
|
19
|
-
|
20
14
|
# Given a LineString, which must be a ring, determine whether the
|
21
15
|
# ring proceeds clockwise or counterclockwise.
|
22
16
|
# Returns 1 for counterclockwise, or -1 for clockwise.
|
@@ -33,12 +27,12 @@ module RGeo
|
|
33
27
|
segs_ = []
|
34
28
|
size_.times do |i_|
|
35
29
|
p0_ = ring_.point_n(i_)
|
36
|
-
p1_ = ring_.point_n(i_+1)
|
30
|
+
p1_ = ring_.point_n(i_ + 1)
|
37
31
|
x_ = p1_.x - p0_.x
|
38
32
|
y_ = p1_.y - p0_.y
|
39
|
-
r_ = ::Math.sqrt(x_*x_ + y_*y_)
|
33
|
+
r_ = ::Math.sqrt(x_ * x_ + y_ * y_)
|
40
34
|
if r_ > 0.0
|
41
|
-
segs_ << x_/r_ << y_/r_
|
35
|
+
segs_ << x_ / r_ << y_ / r_
|
42
36
|
else
|
43
37
|
size_ -= 1
|
44
38
|
end
|
@@ -50,8 +44,8 @@ module RGeo
|
|
50
44
|
# have to calculate any trig functions.
|
51
45
|
angs_ = []
|
52
46
|
size_.times do |i_|
|
53
|
-
x0_, y0_, x1_, y1_ = segs_[i_*2,4]
|
54
|
-
angs_ << x0_*x1_ + y0_*y1_ << x0_*y1_ - x1_*y0_
|
47
|
+
x0_, y0_, x1_, y1_ = segs_[i_ * 2, 4]
|
48
|
+
angs_ << x0_ * x1_ + y0_ * y1_ << x0_ * y1_ - x1_ * y0_
|
55
49
|
end
|
56
50
|
|
57
51
|
# Now add the angles and count revolutions.
|
@@ -62,29 +56,22 @@ module RGeo
|
|
62
56
|
angs_.each_slice(2) do |(x_, y_)|
|
63
57
|
ready_ = y_ > 0.0 && sin_ > 0.0 || y_ < 0.0 && sin_ < 0.0
|
64
58
|
if y_ != 0.0
|
65
|
-
s_ = sin_*x_ + cos_*y_
|
66
|
-
c_ = cos_*x_ - sin_*y_
|
67
|
-
r_ = ::Math.sqrt(s_*s_ + c_*c_)
|
59
|
+
s_ = sin_ * x_ + cos_ * y_
|
60
|
+
c_ = cos_ * x_ - sin_ * y_
|
61
|
+
r_ = ::Math.sqrt(s_ * s_ + c_ * c_)
|
68
62
|
sin_ = s_ / r_
|
69
63
|
cos_ = c_ / r_
|
70
64
|
end
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
65
|
+
next unless ready_
|
66
|
+
if y_ > 0.0 && sin_ <= 0.0
|
67
|
+
revolutions_ += 1
|
68
|
+
elsif y_ < 0.0 && sin_ >= 0.0
|
69
|
+
revolutions_ -= 1
|
77
70
|
end
|
78
71
|
end
|
79
72
|
revolutions_
|
80
73
|
end
|
81
|
-
|
82
|
-
|
83
74
|
end
|
84
|
-
|
85
75
|
end
|
86
|
-
|
87
|
-
|
88
76
|
end
|
89
|
-
|
90
77
|
end
|
@@ -5,10 +5,7 @@
|
|
5
5
|
# -----------------------------------------------------------------------------
|
6
6
|
|
7
7
|
module RGeo
|
8
|
-
|
9
8
|
module Cartesian
|
10
|
-
|
11
|
-
|
12
9
|
# This is a bounding box for Cartesian data.
|
13
10
|
# The simple cartesian implementation uses this internally to compute
|
14
11
|
# envelopes. You may also use it directly to compute and represent
|
@@ -22,30 +19,26 @@ module RGeo
|
|
22
19
|
# bounding boxes.
|
23
20
|
|
24
21
|
class BoundingBox
|
25
|
-
|
26
|
-
|
27
22
|
# Create a bounding box given two corner points.
|
28
23
|
# The bounding box will be given the factory of the first point.
|
29
24
|
# You may also provide the same options available to
|
30
25
|
# BoundingBox.new.
|
31
26
|
|
32
|
-
def self.create_from_points(point1_, point2_, opts_={})
|
27
|
+
def self.create_from_points(point1_, point2_, opts_ = {})
|
33
28
|
factory_ = point1_.factory
|
34
29
|
new(factory_, opts_)._add_geometry(point1_).add(point2_)
|
35
30
|
end
|
36
31
|
|
37
|
-
|
38
32
|
# Create a bounding box given a geometry to surround.
|
39
33
|
# The bounding box will be given the factory of the geometry.
|
40
34
|
# You may also provide the same options available to
|
41
35
|
# BoundingBox.new.
|
42
36
|
|
43
|
-
def self.create_from_geometry(geom_, opts_={})
|
37
|
+
def self.create_from_geometry(geom_, opts_ = {})
|
44
38
|
factory_ = geom_.factory
|
45
39
|
new(factory_, opts_)._add_geometry(geom_)
|
46
40
|
end
|
47
41
|
|
48
|
-
|
49
42
|
# Create a new empty bounding box with the given factory.
|
50
43
|
#
|
51
44
|
# The factory defines the coordinate system for the bounding box,
|
@@ -63,7 +56,7 @@ module RGeo
|
|
63
56
|
# If true, ignore m coordinates even if the factory supports them.
|
64
57
|
# Default is false.
|
65
58
|
|
66
|
-
def initialize(factory_, opts_={})
|
59
|
+
def initialize(factory_, opts_ = {})
|
67
60
|
@factory = factory_
|
68
61
|
if (values_ = opts_[:raw])
|
69
62
|
@has_z, @has_m, @min_x, @max_x, @min_y, @max_y, @min_z, @max_z, @min_m, @max_m = values_
|
@@ -74,8 +67,7 @@ module RGeo
|
|
74
67
|
end
|
75
68
|
end
|
76
69
|
|
77
|
-
|
78
|
-
def eql?(rhs_) # :nodoc:
|
70
|
+
def eql?(rhs_) # :nodoc:
|
79
71
|
rhs_.is_a?(BoundingBox) && @factory == rhs_.factory &&
|
80
72
|
@min_x == rhs_.min_x && @max_x == rhs_.max_x &&
|
81
73
|
@min_y == rhs_.min_y && @max_y == rhs_.max_y &&
|
@@ -84,13 +76,9 @@ module RGeo
|
|
84
76
|
end
|
85
77
|
alias_method :==, :eql?
|
86
78
|
|
87
|
-
|
88
79
|
# Returns the bounding box's factory.
|
89
80
|
|
90
|
-
|
91
|
-
@factory
|
92
|
-
end
|
93
|
-
|
81
|
+
attr_reader :factory
|
94
82
|
|
95
83
|
# Returns true if this bounding box is still empty.
|
96
84
|
|
@@ -98,7 +86,6 @@ module RGeo
|
|
98
86
|
@min_x.nil?
|
99
87
|
end
|
100
88
|
|
101
|
-
|
102
89
|
# Returns true if this bounding box is degenerate. That is,
|
103
90
|
# it is nonempty but contains only a single point because both
|
104
91
|
# the X and Y spans are 0. Infinitesimal boxes are also
|
@@ -108,7 +95,6 @@ module RGeo
|
|
108
95
|
@min_x && @min_x == @max_x && @min_y == @max_y
|
109
96
|
end
|
110
97
|
|
111
|
-
|
112
98
|
# Returns true if this bounding box is degenerate. That is,
|
113
99
|
# it is nonempty but has zero area because either or both
|
114
100
|
# of the X or Y spans are 0.
|
@@ -117,34 +103,21 @@ module RGeo
|
|
117
103
|
@min_x && (@min_x == @max_x || @min_y == @max_y)
|
118
104
|
end
|
119
105
|
|
120
|
-
|
121
106
|
# Returns true if this bounding box tracks Z coordinates.
|
122
107
|
|
123
|
-
|
124
|
-
@has_z
|
125
|
-
end
|
126
|
-
|
108
|
+
attr_reader :has_z
|
127
109
|
|
128
110
|
# Returns true if this bounding box tracks M coordinates.
|
129
111
|
|
130
|
-
|
131
|
-
@has_m
|
132
|
-
end
|
133
|
-
|
112
|
+
attr_reader :has_m
|
134
113
|
|
135
114
|
# Returns the minimum X, or nil if this bounding box is empty.
|
136
115
|
|
137
|
-
|
138
|
-
@min_x
|
139
|
-
end
|
140
|
-
|
116
|
+
attr_reader :min_x
|
141
117
|
|
142
118
|
# Returns the maximum X, or nil if this bounding box is empty.
|
143
119
|
|
144
|
-
|
145
|
-
@max_x
|
146
|
-
end
|
147
|
-
|
120
|
+
attr_reader :max_x
|
148
121
|
|
149
122
|
# Returns the midpoint X, or nil if this bounding box is empty.
|
150
123
|
|
@@ -152,27 +125,19 @@ module RGeo
|
|
152
125
|
@max_x ? (@max_x + @min_x) * 0.5 : nil
|
153
126
|
end
|
154
127
|
|
155
|
-
|
156
128
|
# Returns the X span, or 0 if this bounding box is empty.
|
157
129
|
|
158
130
|
def x_span
|
159
131
|
@max_x ? @max_x - @min_x : 0
|
160
132
|
end
|
161
133
|
|
162
|
-
|
163
134
|
# Returns the minimum Y, or nil if this bounding box is empty.
|
164
135
|
|
165
|
-
|
166
|
-
@min_y
|
167
|
-
end
|
168
|
-
|
136
|
+
attr_reader :min_y
|
169
137
|
|
170
138
|
# Returns the maximum Y, or nil if this bounding box is empty.
|
171
139
|
|
172
|
-
|
173
|
-
@max_y
|
174
|
-
end
|
175
|
-
|
140
|
+
attr_reader :max_y
|
176
141
|
|
177
142
|
# Returns the midpoint Y, or nil if this bounding box is empty.
|
178
143
|
|
@@ -180,27 +145,19 @@ module RGeo
|
|
180
145
|
@max_y ? (@max_y + @min_y) * 0.5 : nil
|
181
146
|
end
|
182
147
|
|
183
|
-
|
184
148
|
# Returns the Y span, or 0 if this bounding box is empty.
|
185
149
|
|
186
150
|
def y_span
|
187
151
|
@max_y ? @max_y - @min_y : 0
|
188
152
|
end
|
189
153
|
|
190
|
-
|
191
154
|
# Returns the minimum Z, or nil if this bounding box is empty.
|
192
155
|
|
193
|
-
|
194
|
-
@min_z
|
195
|
-
end
|
196
|
-
|
156
|
+
attr_reader :min_z
|
197
157
|
|
198
158
|
# Returns the maximum Z, or nil if this bounding box is empty.
|
199
159
|
|
200
|
-
|
201
|
-
@max_z
|
202
|
-
end
|
203
|
-
|
160
|
+
attr_reader :max_z
|
204
161
|
|
205
162
|
# Returns the midpoint Z, or nil if this bounding box is empty or has no Z.
|
206
163
|
|
@@ -208,27 +165,19 @@ module RGeo
|
|
208
165
|
@max_z ? (@max_z + @min_z) * 0.5 : nil
|
209
166
|
end
|
210
167
|
|
211
|
-
|
212
168
|
# Returns the Z span, 0 if this bounding box is empty, or nil if it has no Z.
|
213
169
|
|
214
170
|
def z_span
|
215
171
|
@has_z ? (@max_z ? @max_z - @min_z : 0) : nil
|
216
172
|
end
|
217
173
|
|
218
|
-
|
219
174
|
# Returns the minimum M, or nil if this bounding box is empty.
|
220
175
|
|
221
|
-
|
222
|
-
@min_m
|
223
|
-
end
|
224
|
-
|
176
|
+
attr_reader :min_m
|
225
177
|
|
226
178
|
# Returns the maximum M, or nil if this bounding box is empty.
|
227
179
|
|
228
|
-
|
229
|
-
@max_m
|
230
|
-
end
|
231
|
-
|
180
|
+
attr_reader :max_m
|
232
181
|
|
233
182
|
# Returns the midpoint M, or nil if this bounding box is empty or has no M.
|
234
183
|
|
@@ -236,14 +185,12 @@ module RGeo
|
|
236
185
|
@max_m ? (@max_m + @min_m) * 0.5 : nil
|
237
186
|
end
|
238
187
|
|
239
|
-
|
240
188
|
# Returns the M span, 0 if this bounding box is empty, or nil if it has no M.
|
241
189
|
|
242
190
|
def m_span
|
243
191
|
@has_m ? (@max_m ? @max_m - @min_m : 0) : nil
|
244
192
|
end
|
245
193
|
|
246
|
-
|
247
194
|
# Returns a point representing the minimum extent in all dimensions,
|
248
195
|
# or nil if this bounding box is empty.
|
249
196
|
|
@@ -253,12 +200,9 @@ module RGeo
|
|
253
200
|
extras_ << @min_z if @has_z
|
254
201
|
extras_ << @min_m if @has_m
|
255
202
|
@factory.point(@min_x, @min_y, *extras_)
|
256
|
-
else
|
257
|
-
nil
|
258
203
|
end
|
259
204
|
end
|
260
205
|
|
261
|
-
|
262
206
|
# Returns a point representing the maximum extent in all dimensions,
|
263
207
|
# or nil if this bounding box is empty.
|
264
208
|
|
@@ -268,12 +212,9 @@ module RGeo
|
|
268
212
|
extras_ << @max_z if @has_z
|
269
213
|
extras_ << @max_m if @has_m
|
270
214
|
@factory.point(@max_x, @max_y, *extras_)
|
271
|
-
else
|
272
|
-
nil
|
273
215
|
end
|
274
216
|
end
|
275
217
|
|
276
|
-
|
277
218
|
# Adjusts the extents of this bounding box to encompass the given
|
278
219
|
# object, which may be a geometry or another bounding box.
|
279
220
|
# Returns self.
|
@@ -293,7 +234,6 @@ module RGeo
|
|
293
234
|
self
|
294
235
|
end
|
295
236
|
|
296
|
-
|
297
237
|
# Converts this bounding box to an envelope, which will be the
|
298
238
|
# empty collection (if the bounding box is empty), a point (if the
|
299
239
|
# bounding box is not empty but both spans are 0), a line (if only
|
@@ -316,8 +256,8 @@ module RGeo
|
|
316
256
|
@factory.line(point_min_, point_max_)
|
317
257
|
else
|
318
258
|
@factory.polygon(@factory.linear_ring([point_min_,
|
319
|
-
|
320
|
-
|
259
|
+
@factory.point(@max_x, @min_y, *extras_), point_max_,
|
260
|
+
@factory.point(@min_x, @max_y, *extras_), point_min_]))
|
321
261
|
end
|
322
262
|
end
|
323
263
|
else
|
@@ -325,7 +265,6 @@ module RGeo
|
|
325
265
|
end
|
326
266
|
end
|
327
267
|
|
328
|
-
|
329
268
|
# Returns true if this bounding box contains the given object,
|
330
269
|
# which may be a geometry or another bounding box.
|
331
270
|
#
|
@@ -338,7 +277,7 @@ module RGeo
|
|
338
277
|
# Ignore the M coordinate when testing, even if both objects
|
339
278
|
# have M. Default is false.
|
340
279
|
|
341
|
-
def contains?(rhs_, opts_={})
|
280
|
+
def contains?(rhs_, opts_ = {})
|
342
281
|
if Feature::Geometry === rhs_
|
343
282
|
contains?(BoundingBox.new(@factory).add(rhs_))
|
344
283
|
elsif rhs_.empty?
|
@@ -356,7 +295,6 @@ module RGeo
|
|
356
295
|
end
|
357
296
|
end
|
358
297
|
|
359
|
-
|
360
298
|
# Returns this bounding box subdivided, as an array of bounding boxes.
|
361
299
|
# If this bounding box is empty, returns the empty array.
|
362
300
|
# If this bounding box is a point, returns a one-element array
|
@@ -371,12 +309,12 @@ module RGeo
|
|
371
309
|
# greater than this factor, the bounding box is divided only in
|
372
310
|
# half instead of fourths.
|
373
311
|
|
374
|
-
def subdivide(opts_={})
|
312
|
+
def subdivide(opts_ = {})
|
375
313
|
return [] if empty?
|
376
314
|
if infinitesimal?
|
377
315
|
return [
|
378
|
-
BoundingBox.new(@factory, :
|
379
|
-
|
316
|
+
BoundingBox.new(@factory, raw: [@has_z, @has_m,
|
317
|
+
@min_x, @max_x, @min_y, @max_y, @min_z, @max_z, @min_m, @max_m])
|
380
318
|
]
|
381
319
|
end
|
382
320
|
factor_ = opts_[:bisect_factor]
|
@@ -384,55 +322,53 @@ module RGeo
|
|
384
322
|
if factor_
|
385
323
|
if x_span > y_span * factor_
|
386
324
|
return [
|
387
|
-
BoundingBox.new(@factory, :
|
388
|
-
|
389
|
-
BoundingBox.new(@factory, :
|
390
|
-
|
325
|
+
BoundingBox.new(@factory, raw: [@has_z, @has_m,
|
326
|
+
@min_x, center_x, @min_y, @max_y, @min_z, @max_z, @min_m, @max_m]),
|
327
|
+
BoundingBox.new(@factory, raw: [@has_z, @has_m,
|
328
|
+
center_x, @max_x, @min_y, @max_y, @min_z, @max_z, @min_m, @max_m])
|
391
329
|
]
|
392
330
|
elsif y_span > x_span * factor_
|
393
331
|
return [
|
394
|
-
BoundingBox.new(@factory, :
|
395
|
-
|
396
|
-
BoundingBox.new(@factory, :
|
397
|
-
|
332
|
+
BoundingBox.new(@factory, raw: [@has_z, @has_m,
|
333
|
+
@min_x, @max_x, @min_y, center_y, @min_z, @max_z, @min_m, @max_m]),
|
334
|
+
BoundingBox.new(@factory, raw: [@has_z, @has_m,
|
335
|
+
@min_x, @max_x, center_y, @max_y, @min_z, @max_z, @min_m, @max_m])
|
398
336
|
]
|
399
337
|
end
|
400
338
|
end
|
401
339
|
[
|
402
|
-
BoundingBox.new(@factory, :
|
403
|
-
|
404
|
-
BoundingBox.new(@factory, :
|
405
|
-
|
406
|
-
BoundingBox.new(@factory, :
|
407
|
-
|
408
|
-
BoundingBox.new(@factory, :
|
409
|
-
|
340
|
+
BoundingBox.new(@factory, raw: [@has_z, @has_m,
|
341
|
+
@min_x, center_x, @min_y, center_y, @min_z, @max_z, @min_m, @max_m]),
|
342
|
+
BoundingBox.new(@factory, raw: [@has_z, @has_m,
|
343
|
+
center_x, @max_x, @min_y, center_y, @min_z, @max_z, @min_m, @max_m]),
|
344
|
+
BoundingBox.new(@factory, raw: [@has_z, @has_m,
|
345
|
+
@min_x, center_x, center_y, @max_y, @min_z, @max_z, @min_m, @max_m]),
|
346
|
+
BoundingBox.new(@factory, raw: [@has_z, @has_m,
|
347
|
+
center_x, @max_x, center_y, @max_y, @min_z, @max_z, @min_m, @max_m])
|
410
348
|
]
|
411
349
|
end
|
412
350
|
|
413
|
-
|
414
|
-
def _add_geometry(geometry_) # :nodoc:
|
351
|
+
def _add_geometry(geometry_) # :nodoc:
|
415
352
|
case geometry_
|
416
353
|
when Feature::Point
|
417
354
|
_add_point(geometry_)
|
418
355
|
when Feature::LineString
|
419
|
-
geometry_.points.each{ |p_| _add_point(p_) }
|
356
|
+
geometry_.points.each { |p_| _add_point(p_) }
|
420
357
|
when Feature::Polygon
|
421
|
-
geometry_.exterior_ring.points.each{ |p_| _add_point(p_) }
|
358
|
+
geometry_.exterior_ring.points.each { |p_| _add_point(p_) }
|
422
359
|
when Feature::MultiPoint
|
423
|
-
geometry_.each{ |p_| _add_point(p_) }
|
360
|
+
geometry_.each { |p_| _add_point(p_) }
|
424
361
|
when Feature::MultiLineString
|
425
|
-
geometry_.each{ |line_| line_.points.each{ |p_| _add_point(p_) } }
|
362
|
+
geometry_.each { |line_| line_.points.each { |p_| _add_point(p_) } }
|
426
363
|
when Feature::MultiPolygon
|
427
|
-
geometry_.each{ |poly_| poly_.exterior_ring.points.each{ |p_| _add_point(p_) } }
|
364
|
+
geometry_.each { |poly_| poly_.exterior_ring.points.each { |p_| _add_point(p_) } }
|
428
365
|
when Feature::GeometryCollection
|
429
|
-
geometry_.each{ |g_| _add_geometry(g_) }
|
366
|
+
geometry_.each { |g_| _add_geometry(g_) }
|
430
367
|
end
|
431
368
|
self
|
432
369
|
end
|
433
370
|
|
434
|
-
|
435
|
-
def _add_point(point_) # :nodoc:
|
371
|
+
def _add_point(point_) # :nodoc:
|
436
372
|
if @min_x
|
437
373
|
x_ = point_.x
|
438
374
|
@min_x = x_ if x_ < @min_x
|
@@ -457,11 +393,6 @@ module RGeo
|
|
457
393
|
@min_m = @max_m = point_.m if @has_m
|
458
394
|
end
|
459
395
|
end
|
460
|
-
|
461
|
-
|
462
396
|
end
|
463
|
-
|
464
|
-
|
465
397
|
end
|
466
|
-
|
467
398
|
end
|