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,14 +5,9 @@
|
|
5
5
|
# -----------------------------------------------------------------------------
|
6
6
|
|
7
7
|
module RGeo
|
8
|
-
|
9
8
|
module Geographic
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
RADIUS = 6378137.0
|
15
|
-
|
9
|
+
module SphericalMath # :nodoc:
|
10
|
+
RADIUS = 6_378_137.0
|
16
11
|
|
17
12
|
# Represents a point on the unit sphere in (x,y,z) coordinates
|
18
13
|
# instead of lat-lon. This form is often faster, more convenient,
|
@@ -25,8 +20,7 @@ module RGeo
|
|
25
20
|
# This object is also used to represent a great circle, as its axis
|
26
21
|
# of rotation.
|
27
22
|
|
28
|
-
class PointXYZ
|
29
|
-
|
23
|
+
class PointXYZ # :nodoc:
|
30
24
|
def initialize(x_, y_, z_)
|
31
25
|
r_ = ::Math.sqrt(x_ * x_ + y_ * y_ + z_ * z_)
|
32
26
|
@x = (x_ / r_).to_f
|
@@ -35,39 +29,41 @@ module RGeo
|
|
35
29
|
raise "Not a number" if @x.nan? || @y.nan? || @z.nan?
|
36
30
|
end
|
37
31
|
|
38
|
-
|
39
32
|
def to_s
|
40
33
|
"(#{@x}, #{@y}, #{@z})"
|
41
34
|
end
|
42
35
|
|
43
|
-
|
44
36
|
attr_reader :x
|
45
37
|
attr_reader :y
|
46
38
|
attr_reader :z
|
47
39
|
|
48
|
-
|
49
40
|
def eql?(rhs_)
|
50
|
-
rhs_.
|
41
|
+
rhs_.is_a?(PointXYZ) && @x == rhs_.x && @y == rhs_.y && @z == rhs_.z
|
51
42
|
end
|
52
43
|
alias_method :==, :eql?
|
53
44
|
|
54
|
-
|
55
45
|
def latlon
|
56
46
|
lat_rad_ = ::Math.asin(@z)
|
57
|
-
lon_rad_ =
|
47
|
+
lon_rad_ = begin
|
48
|
+
::Math.atan2(@y, @x)
|
49
|
+
rescue
|
50
|
+
0.0
|
51
|
+
end
|
58
52
|
rpd_ = ImplHelper::Math::RADIANS_PER_DEGREE
|
59
53
|
[lat_rad_ / rpd_, lon_rad_ / rpd_]
|
60
54
|
end
|
61
55
|
|
62
|
-
|
63
56
|
def lonlat
|
64
57
|
lat_rad_ = ::Math.asin(@z)
|
65
|
-
lon_rad_ =
|
58
|
+
lon_rad_ = begin
|
59
|
+
::Math.atan2(@y, @x)
|
60
|
+
rescue
|
61
|
+
0.0
|
62
|
+
end
|
66
63
|
rpd_ = ImplHelper::Math::RADIANS_PER_DEGREE
|
67
64
|
[lon_rad_ / rpd_, lat_rad_ / rpd_]
|
68
65
|
end
|
69
66
|
|
70
|
-
|
71
67
|
def *(rhs_)
|
72
68
|
val_ = @x * rhs_.x + @y * rhs_.y + @z * rhs_.z
|
73
69
|
val_ = 1.0 if val_ > 1.0
|
@@ -75,15 +71,17 @@ module RGeo
|
|
75
71
|
val_
|
76
72
|
end
|
77
73
|
|
78
|
-
|
79
74
|
def %(rhs_)
|
80
75
|
rx_ = rhs_.x
|
81
76
|
ry_ = rhs_.y
|
82
77
|
rz_ = rhs_.z
|
83
|
-
|
78
|
+
begin
|
79
|
+
PointXYZ.new(@y * rz_ - @z * ry_, @z * rx_ - @x * rz_, @x * ry_ - @y * rx_)
|
80
|
+
rescue
|
81
|
+
nil
|
82
|
+
end
|
84
83
|
end
|
85
84
|
|
86
|
-
|
87
85
|
def dist_to_point(rhs_)
|
88
86
|
rx_ = rhs_.x
|
89
87
|
ry_ = rhs_.y
|
@@ -92,15 +90,14 @@ module RGeo
|
|
92
90
|
if dot_ > -0.8 && dot_ < 0.8
|
93
91
|
::Math.acos(dot_)
|
94
92
|
else
|
95
|
-
x_ = @y*rz_
|
96
|
-
y_ = @z*rx_
|
97
|
-
z_ = @x*ry_
|
98
|
-
as_ = ::Math.asin(::Math.sqrt(x_*x_ + y_*y_ + z_*z_))
|
93
|
+
x_ = @y * rz_ - @z * ry_
|
94
|
+
y_ = @z * rx_ - @x * rz_
|
95
|
+
z_ = @x * ry_ - @y * rx_
|
96
|
+
as_ = ::Math.asin(::Math.sqrt(x_ * x_ + y_ * y_ + z_ * z_))
|
99
97
|
dot_ > 0.0 ? as_ : ::Math::PI - as_
|
100
98
|
end
|
101
99
|
end
|
102
100
|
|
103
|
-
|
104
101
|
# Creates some point that is perpendicular to this point
|
105
102
|
|
106
103
|
def create_perpendicular
|
@@ -111,7 +108,6 @@ module RGeo
|
|
111
108
|
p1dot_ < p2dot_ ? (self % P1) : (self % P2)
|
112
109
|
end
|
113
110
|
|
114
|
-
|
115
111
|
def self.from_latlon(lat_, lon_)
|
116
112
|
rpd_ = ImplHelper::Math::RADIANS_PER_DEGREE
|
117
113
|
lat_rad_ = rpd_ * lat_
|
@@ -123,58 +119,45 @@ module RGeo
|
|
123
119
|
new(x_, y_, z_)
|
124
120
|
end
|
125
121
|
|
126
|
-
|
127
122
|
def self.weighted_combination(p1_, w1_, p2_, w2_)
|
128
123
|
new(p1_.x * w1_ + p2_.x * w2_, p1_.y * w1_ + p2_.y * w2_, p1_.z * w1_ + p2_.z * w2_)
|
129
124
|
end
|
130
125
|
|
131
|
-
|
132
126
|
P1 = new(1, 0, 0)
|
133
127
|
P2 = new(0, 1, 0)
|
134
|
-
|
135
128
|
end
|
136
129
|
|
137
|
-
|
138
130
|
# Represents a finite arc on the sphere.
|
139
131
|
|
140
|
-
class ArcXYZ
|
141
|
-
|
132
|
+
class ArcXYZ # :nodoc:
|
142
133
|
def initialize(start_, end_)
|
143
134
|
@s = start_
|
144
135
|
@e = end_
|
145
136
|
@axis = false
|
146
137
|
end
|
147
138
|
|
148
|
-
|
149
139
|
attr_reader :s
|
150
140
|
attr_reader :e
|
151
141
|
|
152
|
-
|
153
142
|
def to_s
|
154
143
|
"#{@s} - #{@e}"
|
155
144
|
end
|
156
145
|
|
157
|
-
|
158
146
|
def eql?(rhs_)
|
159
|
-
rhs_.
|
147
|
+
rhs_.is_a?(ArcXYZ) && @s == rhs_.s && @e == rhs_.e
|
160
148
|
end
|
161
149
|
alias_method :==, :eql?
|
162
150
|
|
163
|
-
|
164
151
|
def degenerate?
|
165
152
|
axis_ = axis
|
166
153
|
axis_.x == 0 && axis_.y == 0 && axis_.z == 0
|
167
154
|
end
|
168
155
|
|
169
|
-
|
170
156
|
def axis
|
171
|
-
if @axis == false
|
172
|
-
@axis = @s % @e
|
173
|
-
end
|
157
|
+
@axis = @s % @e if @axis == false
|
174
158
|
@axis
|
175
159
|
end
|
176
160
|
|
177
|
-
|
178
161
|
def contains_point?(obj_)
|
179
162
|
axis_ = axis
|
180
163
|
saxis_ = ArcXYZ.new(@s, obj_).axis
|
@@ -182,7 +165,6 @@ module RGeo
|
|
182
165
|
!saxis_ || !eaxis_ || obj_ * axis_ == 0.0 && saxis_ * axis_ > 0 && eaxis_ * axis_ > 0
|
183
166
|
end
|
184
167
|
|
185
|
-
|
186
168
|
def intersects_arc?(obj_)
|
187
169
|
my_axis_ = axis
|
188
170
|
dot1_ = my_axis_ * obj_.s
|
@@ -197,17 +179,10 @@ module RGeo
|
|
197
179
|
end
|
198
180
|
end
|
199
181
|
|
200
|
-
|
201
182
|
def length
|
202
183
|
@s.dist_to_point(@e)
|
203
184
|
end
|
204
|
-
|
205
|
-
|
206
185
|
end
|
207
|
-
|
208
|
-
|
209
186
|
end
|
210
|
-
|
211
187
|
end
|
212
|
-
|
213
188
|
end
|
data/lib/rgeo/geos.rb
CHANGED
@@ -5,8 +5,6 @@
|
|
5
5
|
# -----------------------------------------------------------------------------
|
6
6
|
|
7
7
|
module RGeo
|
8
|
-
|
9
|
-
|
10
8
|
# The Geos module provides general tools for creating and manipulating
|
11
9
|
# a GEOS-backed implementation of the SFS. This is a full implementation
|
12
10
|
# of the SFS using a Cartesian coordinate system. It uses the GEOS C++
|
@@ -26,40 +24,36 @@ module RGeo
|
|
26
24
|
|
27
25
|
module Geos
|
28
26
|
end
|
29
|
-
|
30
|
-
|
31
27
|
end
|
32
28
|
|
33
|
-
|
34
29
|
# :stopdoc:
|
35
30
|
|
36
31
|
module RGeo
|
37
32
|
module Geos
|
38
|
-
|
39
33
|
# Implementation files
|
40
|
-
require
|
41
|
-
require
|
34
|
+
require "rgeo/geos/utils"
|
35
|
+
require "rgeo/geos/interface"
|
42
36
|
begin
|
43
|
-
require
|
37
|
+
require "rgeo/geos/geos_c_impl"
|
44
38
|
rescue ::LoadError; end
|
45
39
|
CAPI_SUPPORTED = ::RGeo::Geos.const_defined?(:CAPIGeometryMethods)
|
46
40
|
if CAPI_SUPPORTED
|
47
|
-
require
|
48
|
-
require
|
41
|
+
require "rgeo/geos/capi_feature_classes"
|
42
|
+
require "rgeo/geos/capi_factory"
|
49
43
|
end
|
50
|
-
require
|
51
|
-
require
|
52
|
-
require
|
53
|
-
require
|
54
|
-
require
|
55
|
-
require
|
44
|
+
require "rgeo/geos/ffi_feature_methods"
|
45
|
+
require "rgeo/geos/ffi_feature_classes"
|
46
|
+
require "rgeo/geos/ffi_factory"
|
47
|
+
require "rgeo/geos/zm_feature_methods"
|
48
|
+
require "rgeo/geos/zm_feature_classes"
|
49
|
+
require "rgeo/geos/zm_factory"
|
56
50
|
|
57
51
|
# Determine ffi support.
|
58
52
|
begin
|
59
|
-
require
|
53
|
+
require "ffi-geos"
|
60
54
|
# An additional check to make sure FFI loaded okay. This can fail on
|
61
55
|
# some versions of ffi-geos and some versions of Rubinius.
|
62
|
-
raise
|
56
|
+
raise "Problem loading FFI" unless ::FFI::AutoPointer
|
63
57
|
FFI_SUPPORTED = true
|
64
58
|
FFI_SUPPORT_EXCEPTION = nil
|
65
59
|
rescue ::LoadError => ex_
|
@@ -77,9 +71,18 @@ module RGeo
|
|
77
71
|
self.preferred_native_interface = :ffi
|
78
72
|
end
|
79
73
|
|
74
|
+
# There is some trouble with END_CAP in GEOS
|
75
|
+
# In docs CAP_ROUND = 1, but it's work properly with 0
|
76
|
+
CAP_ROUND = 0
|
77
|
+
CAP_FLAT = 1
|
78
|
+
CAP_SQUARE = 2
|
79
|
+
|
80
|
+
JOIN_ROUND = 0
|
81
|
+
JOIN_MITRE = 1
|
82
|
+
JOIN_BEVEL = 2
|
83
|
+
|
80
84
|
# Init internal utilities
|
81
85
|
Utils._init
|
82
|
-
|
83
86
|
end
|
84
87
|
end
|
85
88
|
|
@@ -5,27 +5,19 @@
|
|
5
5
|
# -----------------------------------------------------------------------------
|
6
6
|
|
7
7
|
module RGeo
|
8
|
-
|
9
8
|
module Geos
|
10
|
-
|
11
|
-
|
12
9
|
# This the GEOS CAPI implementation of ::RGeo::Feature::Factory.
|
13
10
|
|
14
11
|
class CAPIFactory
|
15
|
-
|
16
|
-
|
17
12
|
include Feature::Factory::Instance
|
18
13
|
|
19
|
-
|
20
14
|
class << self
|
21
|
-
|
22
|
-
|
23
15
|
# Create a new factory. Returns nil if the GEOS CAPI implementation
|
24
16
|
# is not supported.
|
25
17
|
#
|
26
18
|
# See ::RGeo::Geos.factory for a list of supported options.
|
27
19
|
|
28
|
-
def create(opts_={})
|
20
|
+
def create(opts_ = {})
|
29
21
|
# Make sure GEOS is available
|
30
22
|
return nil unless respond_to?(:_create)
|
31
23
|
|
@@ -51,7 +43,7 @@ module RGeo
|
|
51
43
|
when ::Hash
|
52
44
|
wkt_generator_ = WKRep::WKTGenerator.new(wkt_generator_)
|
53
45
|
else
|
54
|
-
wkt_generator_ = WKRep::WKTGenerator.new(:
|
46
|
+
wkt_generator_ = WKRep::WKTGenerator.new(convert_case: :upper)
|
55
47
|
end
|
56
48
|
wkb_generator_ = opts_[:wkb_generator]
|
57
49
|
case wkb_generator_
|
@@ -67,15 +59,19 @@ module RGeo
|
|
67
59
|
srid_ = opts_[:srid]
|
68
60
|
proj4_ = opts_[:proj4]
|
69
61
|
if CoordSys::Proj4.supported?
|
70
|
-
if proj4_.
|
62
|
+
if proj4_.is_a?(::String) || proj4_.is_a?(::Hash)
|
71
63
|
proj4_ = CoordSys::Proj4.create(proj4_)
|
72
64
|
end
|
73
65
|
else
|
74
66
|
proj4_ = nil
|
75
67
|
end
|
76
68
|
coord_sys_ = opts_[:coord_sys]
|
77
|
-
if coord_sys_.
|
78
|
-
coord_sys_ =
|
69
|
+
if coord_sys_.is_a?(::String)
|
70
|
+
coord_sys_ = begin
|
71
|
+
CoordSys::CS.create_from_wkt(coord_sys_)
|
72
|
+
rescue
|
73
|
+
nil
|
74
|
+
end
|
79
75
|
end
|
80
76
|
if (!proj4_ || !coord_sys_) && srid_ && (db_ = opts_[:srs_database])
|
81
77
|
entry_ = db_.get(srid_.to_i)
|
@@ -115,18 +111,14 @@ module RGeo
|
|
115
111
|
result_
|
116
112
|
end
|
117
113
|
alias_method :new, :create
|
118
|
-
|
119
|
-
|
120
114
|
end
|
121
115
|
|
122
|
-
|
123
116
|
# Standard object inspection output
|
124
117
|
|
125
118
|
def inspect
|
126
119
|
"#<#{self.class}:0x#{object_id.to_s(16)} srid=#{_srid} bufres=#{_buffer_resolution} flags=#{_flags}>"
|
127
120
|
end
|
128
121
|
|
129
|
-
|
130
122
|
# Factory equivalence test.
|
131
123
|
|
132
124
|
def eql?(rhs_)
|
@@ -136,128 +128,123 @@ module RGeo
|
|
136
128
|
end
|
137
129
|
alias_method :==, :eql?
|
138
130
|
|
139
|
-
|
140
131
|
# Standard hash code
|
141
132
|
|
142
133
|
def hash
|
143
134
|
@hash ||= [_srid, _buffer_resolution, _flags, _proj4].hash
|
144
135
|
end
|
145
136
|
|
146
|
-
|
147
137
|
# Marshal support
|
148
138
|
|
149
|
-
def marshal_dump
|
139
|
+
def marshal_dump # :nodoc:
|
150
140
|
hash_ = {
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
141
|
+
"hasz" => (_flags & 0x2 != 0),
|
142
|
+
"hasm" => (_flags & 0x4 != 0),
|
143
|
+
"srid" => _srid,
|
144
|
+
"bufr" => _buffer_resolution,
|
145
|
+
"wktg" => _wkt_generator ? _wkt_generator._properties : {},
|
146
|
+
"wkbg" => _wkb_generator ? _wkb_generator._properties : {},
|
147
|
+
"wktp" => _wkt_parser ? _wkt_parser._properties : {},
|
148
|
+
"wkbp" => _wkb_parser ? _wkb_parser._properties : {},
|
149
|
+
"lmpa" => (_flags & 0x1 != 0),
|
150
|
+
"apre" => ((_flags & 0x8) >> 3)
|
161
151
|
}
|
162
|
-
if (proj4_ =
|
163
|
-
hash_[
|
152
|
+
if (proj4_ = _proj4)
|
153
|
+
hash_["proj4"] = proj4_.marshal_dump
|
164
154
|
end
|
165
|
-
if (coord_sys_ =
|
166
|
-
hash_[
|
155
|
+
if (coord_sys_ = _coord_sys)
|
156
|
+
hash_["cs"] = coord_sys_.to_wkt
|
167
157
|
end
|
168
158
|
hash_
|
169
159
|
end
|
170
160
|
|
171
|
-
def marshal_load(data_)
|
172
|
-
if CoordSys::Proj4.supported? && (proj4_data_ = data_[
|
161
|
+
def marshal_load(data_) # :nodoc:
|
162
|
+
if CoordSys::Proj4.supported? && (proj4_data_ = data_["proj4"])
|
173
163
|
proj4_ = CoordSys::Proj4.allocate
|
174
164
|
proj4_.marshal_load(proj4_data_)
|
175
165
|
else
|
176
166
|
proj4_ = nil
|
177
167
|
end
|
178
|
-
if (coord_sys_data_ = data_[
|
168
|
+
if (coord_sys_data_ = data_["cs"])
|
179
169
|
coord_sys_ = CoordSys::CS.create_from_wkt(coord_sys_data_)
|
180
170
|
else
|
181
171
|
coord_sys_ = nil
|
182
172
|
end
|
183
173
|
initialize_copy(CAPIFactory.create(
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
174
|
+
has_z_coordinate: data_["hasz"],
|
175
|
+
has_m_coordinate: data_["hasm"],
|
176
|
+
srid: data_["srid"],
|
177
|
+
buffer_resolution: data_["bufr"],
|
178
|
+
wkt_generator: ImplHelper::Utils.symbolize_hash(data_["wktg"]),
|
179
|
+
wkb_generator: ImplHelper::Utils.symbolize_hash(data_["wkbg"]),
|
180
|
+
wkt_parser: ImplHelper::Utils.symbolize_hash(data_["wktp"]),
|
181
|
+
wkb_parser: ImplHelper::Utils.symbolize_hash(data_["wkbp"]),
|
182
|
+
uses_lenient_multi_polygon_assertions: data_["lmpa"],
|
183
|
+
auto_prepare: (data_["apre"] == 0 ? :disabled : :simple),
|
184
|
+
proj4: proj4_,
|
185
|
+
coord_sys: coord_sys_
|
196
186
|
))
|
197
187
|
end
|
198
188
|
|
199
|
-
|
200
189
|
# Psych support
|
201
190
|
|
202
|
-
def encode_with(coder_)
|
203
|
-
coder_[
|
204
|
-
coder_[
|
205
|
-
coder_[
|
206
|
-
coder_[
|
207
|
-
coder_[
|
208
|
-
coder_[
|
209
|
-
coder_[
|
210
|
-
coder_[
|
211
|
-
coder_[
|
212
|
-
coder_[
|
213
|
-
if (proj4_ =
|
191
|
+
def encode_with(coder_) # :nodoc:
|
192
|
+
coder_["has_z_coordinate"] = (_flags & 0x2 != 0)
|
193
|
+
coder_["has_m_coordinate"] = (_flags & 0x4 != 0)
|
194
|
+
coder_["srid"] = _srid
|
195
|
+
coder_["buffer_resolution"] = _buffer_resolution
|
196
|
+
coder_["lenient_multi_polygon_assertions"] = (_flags & 0x1 != 0)
|
197
|
+
coder_["wkt_generator"] = _wkt_generator ? _wkt_generator._properties : {}
|
198
|
+
coder_["wkb_generator"] = _wkb_generator ? _wkb_generator._properties : {}
|
199
|
+
coder_["wkt_parser"] = _wkt_parser ? _wkt_parser._properties : {}
|
200
|
+
coder_["wkb_parser"] = _wkb_parser ? _wkb_parser._properties : {}
|
201
|
+
coder_["auto_prepare"] = ((_flags & 0x8) == 0 ? "disabled" : "simple")
|
202
|
+
if (proj4_ = _proj4)
|
214
203
|
str_ = proj4_.original_str || proj4_.canonical_str
|
215
|
-
coder_[
|
204
|
+
coder_["proj4"] = proj4_.radians? ? { "proj4" => str_, "radians" => true } : str_
|
216
205
|
end
|
217
|
-
if (coord_sys_ =
|
218
|
-
coder_[
|
206
|
+
if (coord_sys_ = _coord_sys)
|
207
|
+
coder_["coord_sys"] = coord_sys_.to_wkt
|
219
208
|
end
|
220
209
|
end
|
221
210
|
|
222
|
-
def init_with(coder_)
|
223
|
-
if (proj4_data_ = coder_[
|
211
|
+
def init_with(coder_) # :nodoc:
|
212
|
+
if (proj4_data_ = coder_["proj4"])
|
224
213
|
if proj4_data_.is_a?(::Hash)
|
225
|
-
proj4_ = CoordSys::Proj4.create(proj4_data_[
|
214
|
+
proj4_ = CoordSys::Proj4.create(proj4_data_["proj4"], radians: proj4_data_["radians"])
|
226
215
|
else
|
227
216
|
proj4_ = CoordSys::Proj4.create(proj4_data_.to_s)
|
228
217
|
end
|
229
218
|
else
|
230
219
|
proj4_ = nil
|
231
220
|
end
|
232
|
-
if (coord_sys_data_ = coder_[
|
221
|
+
if (coord_sys_data_ = coder_["cs"])
|
233
222
|
coord_sys_ = CoordSys::CS.create_from_wkt(coord_sys_data_.to_s)
|
234
223
|
else
|
235
224
|
coord_sys_ = nil
|
236
225
|
end
|
237
226
|
initialize_copy(CAPIFactory.create(
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
227
|
+
has_z_coordinate: coder_["has_z_coordinate"],
|
228
|
+
has_m_coordinate: coder_["has_m_coordinate"],
|
229
|
+
srid: coder_["srid"],
|
230
|
+
buffer_resolution: coder_["buffer_resolution"],
|
231
|
+
wkt_generator: ImplHelper::Utils.symbolize_hash(coder_["wkt_generator"]),
|
232
|
+
wkb_generator: ImplHelper::Utils.symbolize_hash(coder_["wkb_generator"]),
|
233
|
+
wkt_parser: ImplHelper::Utils.symbolize_hash(coder_["wkt_parser"]),
|
234
|
+
wkb_parser: ImplHelper::Utils.symbolize_hash(coder_["wkb_parser"]),
|
235
|
+
auto_prepare: coder_["auto_prepare"] == "disabled" ? :disabled : :simple,
|
236
|
+
uses_lenient_multi_polygon_assertions: coder_["lenient_multi_polygon_assertions"],
|
237
|
+
proj4: proj4_,
|
238
|
+
coord_sys: coord_sys_
|
250
239
|
))
|
251
240
|
end
|
252
241
|
|
253
|
-
|
254
242
|
# Returns the SRID of geometries created by this factory.
|
255
243
|
|
256
244
|
def srid
|
257
245
|
_srid
|
258
246
|
end
|
259
247
|
|
260
|
-
|
261
248
|
# Returns the resolution used by buffer calculations on geometries
|
262
249
|
# created by this factory
|
263
250
|
|
@@ -265,14 +252,12 @@ module RGeo
|
|
265
252
|
_buffer_resolution
|
266
253
|
end
|
267
254
|
|
268
|
-
|
269
255
|
# Returns true if this factory is lenient with MultiPolygon assertions
|
270
256
|
|
271
257
|
def lenient_multi_polygon_assertions?
|
272
258
|
_flags & 0x1 != 0
|
273
259
|
end
|
274
260
|
|
275
|
-
|
276
261
|
# See ::RGeo::Feature::Factory#property
|
277
262
|
|
278
263
|
def property(name_)
|
@@ -289,128 +274,146 @@ module RGeo
|
|
289
274
|
_buffer_resolution
|
290
275
|
when :auto_prepare
|
291
276
|
_flags & 0x8 != 0 ? :simple : :disabled
|
292
|
-
else
|
293
|
-
nil
|
294
277
|
end
|
295
278
|
end
|
296
279
|
|
297
|
-
|
298
280
|
# See ::RGeo::Feature::Factory#parse_wkt
|
299
281
|
|
300
282
|
def parse_wkt(str_)
|
301
|
-
if (wkt_parser_ =
|
283
|
+
if (wkt_parser_ = _wkt_parser)
|
302
284
|
wkt_parser_.parse(str_)
|
303
285
|
else
|
304
286
|
_parse_wkt_impl(str_)
|
305
287
|
end
|
306
288
|
end
|
307
289
|
|
308
|
-
|
309
290
|
# See ::RGeo::Feature::Factory#parse_wkb
|
310
291
|
|
311
292
|
def parse_wkb(str_)
|
312
|
-
if (wkb_parser_ =
|
293
|
+
if (wkb_parser_ = _wkb_parser)
|
313
294
|
wkb_parser_.parse(str_)
|
314
295
|
else
|
315
296
|
_parse_wkb_impl(str_)
|
316
297
|
end
|
317
298
|
end
|
318
299
|
|
319
|
-
|
320
300
|
# See ::RGeo::Feature::Factory#point
|
321
301
|
|
322
302
|
def point(x_, y_, *extra_)
|
323
303
|
if extra_.length > (_flags & 6 == 0 ? 0 : 1)
|
324
304
|
nil
|
325
305
|
else
|
326
|
-
|
306
|
+
begin
|
307
|
+
CAPIPointImpl.create(self, x_, y_, extra_[0].to_f)
|
308
|
+
rescue
|
309
|
+
nil
|
310
|
+
end
|
327
311
|
end
|
328
312
|
end
|
329
313
|
|
330
|
-
|
331
314
|
# See ::RGeo::Feature::Factory#line_string
|
332
315
|
|
333
316
|
def line_string(points_)
|
334
|
-
points_ = points_.to_a unless points_.
|
335
|
-
|
317
|
+
points_ = points_.to_a unless points_.is_a?(::Array)
|
318
|
+
begin
|
319
|
+
CAPILineStringImpl.create(self, points_)
|
320
|
+
rescue
|
321
|
+
nil
|
322
|
+
end
|
336
323
|
end
|
337
324
|
|
338
|
-
|
339
325
|
# See ::RGeo::Feature::Factory#line
|
340
326
|
|
341
327
|
def line(start_, end_)
|
342
|
-
CAPILineImpl.create(self, start_, end_)
|
328
|
+
CAPILineImpl.create(self, start_, end_)
|
329
|
+
rescue
|
330
|
+
nil
|
343
331
|
end
|
344
332
|
|
345
|
-
|
346
333
|
# See ::RGeo::Feature::Factory#linear_ring
|
347
334
|
|
348
335
|
def linear_ring(points_)
|
349
|
-
points_ = points_.to_a unless points_.
|
350
|
-
|
336
|
+
points_ = points_.to_a unless points_.is_a?(::Array)
|
337
|
+
begin
|
338
|
+
CAPILinearRingImpl.create(self, points_)
|
339
|
+
rescue
|
340
|
+
nil
|
341
|
+
end
|
351
342
|
end
|
352
343
|
|
353
|
-
|
354
344
|
# See ::RGeo::Feature::Factory#polygon
|
355
345
|
|
356
|
-
def polygon(outer_ring_, inner_rings_=nil)
|
357
|
-
inner_rings_ = inner_rings_.to_a unless inner_rings_.
|
358
|
-
|
346
|
+
def polygon(outer_ring_, inner_rings_ = nil)
|
347
|
+
inner_rings_ = inner_rings_.to_a unless inner_rings_.is_a?(::Array)
|
348
|
+
begin
|
349
|
+
CAPIPolygonImpl.create(self, outer_ring_, inner_rings_)
|
350
|
+
rescue
|
351
|
+
nil
|
352
|
+
end
|
359
353
|
end
|
360
354
|
|
361
|
-
|
362
355
|
# See ::RGeo::Feature::Factory#collection
|
363
356
|
|
364
357
|
def collection(elems_)
|
365
|
-
elems_ = elems_.to_a unless elems_.
|
366
|
-
|
358
|
+
elems_ = elems_.to_a unless elems_.is_a?(::Array)
|
359
|
+
begin
|
360
|
+
CAPIGeometryCollectionImpl.create(self, elems_)
|
361
|
+
rescue
|
362
|
+
nil
|
363
|
+
end
|
367
364
|
end
|
368
365
|
|
369
|
-
|
370
366
|
# See ::RGeo::Feature::Factory#multi_point
|
371
367
|
|
372
368
|
def multi_point(elems_)
|
373
|
-
elems_ = elems_.to_a unless elems_.
|
374
|
-
|
369
|
+
elems_ = elems_.to_a unless elems_.is_a?(::Array)
|
370
|
+
begin
|
371
|
+
CAPIMultiPointImpl.create(self, elems_)
|
372
|
+
rescue
|
373
|
+
nil
|
374
|
+
end
|
375
375
|
end
|
376
376
|
|
377
|
-
|
378
377
|
# See ::RGeo::Feature::Factory#multi_line_string
|
379
378
|
|
380
379
|
def multi_line_string(elems_)
|
381
|
-
elems_ = elems_.to_a unless elems_.
|
382
|
-
|
380
|
+
elems_ = elems_.to_a unless elems_.is_a?(::Array)
|
381
|
+
begin
|
382
|
+
CAPIMultiLineStringImpl.create(self, elems_)
|
383
|
+
rescue
|
384
|
+
nil
|
385
|
+
end
|
383
386
|
end
|
384
387
|
|
385
|
-
|
386
388
|
# See ::RGeo::Feature::Factory#multi_polygon
|
387
389
|
|
388
390
|
def multi_polygon(elems_)
|
389
|
-
elems_ = elems_.to_a unless elems_.
|
390
|
-
|
391
|
+
elems_ = elems_.to_a unless elems_.is_a?(::Array)
|
392
|
+
begin
|
393
|
+
CAPIMultiPolygonImpl.create(self, elems_)
|
394
|
+
rescue
|
395
|
+
nil
|
396
|
+
end
|
391
397
|
end
|
392
398
|
|
393
|
-
|
394
399
|
# See ::RGeo::Feature::Factory#proj4
|
395
400
|
|
396
401
|
def proj4
|
397
402
|
_proj4
|
398
403
|
end
|
399
404
|
|
400
|
-
|
401
405
|
# See ::RGeo::Feature::Factory#coord_sys
|
402
406
|
|
403
407
|
def coord_sys
|
404
408
|
_coord_sys
|
405
409
|
end
|
406
410
|
|
407
|
-
|
408
411
|
# See ::RGeo::Feature::Factory#override_cast
|
409
412
|
|
410
413
|
def override_cast(original_, ntype_, flags_)
|
411
414
|
return nil unless Geos.supported?
|
412
415
|
keep_subtype_ = flags_[:keep_subtype]
|
413
|
-
#force_new_ = flags_[:force_new]
|
416
|
+
# force_new_ = flags_[:force_new]
|
414
417
|
project_ = flags_[:project]
|
415
418
|
type_ = original_.geometry_type
|
416
419
|
ntype_ = type_ if keep_subtype_ && type_.include?(ntype_)
|
@@ -421,7 +424,6 @@ module RGeo
|
|
421
424
|
if original_.factory != self && ntype_ == type_ &&
|
422
425
|
original_.factory._flags & 0x6 == _flags & 0x6 &&
|
423
426
|
(!project_ || original_.factory.proj4 == _proj4)
|
424
|
-
then
|
425
427
|
result_ = original_.dup
|
426
428
|
result_._set_factory(self)
|
427
429
|
return result_
|
@@ -431,7 +433,6 @@ module RGeo
|
|
431
433
|
original_.factory._flags & 0x6 == _flags & 0x6 &&
|
432
434
|
(!project_ || original_.factory.proj4 == _proj4) &&
|
433
435
|
type_.subtype_of?(Feature::LineString) && ntype_.subtype_of?(Feature::LineString)
|
434
|
-
then
|
435
436
|
return IMPL_CLASSES[ntype_]._copy_from(self, original_)
|
436
437
|
end
|
437
438
|
when ZMGeometryMethods
|
@@ -446,7 +447,6 @@ module RGeo
|
|
446
447
|
false
|
447
448
|
end
|
448
449
|
|
449
|
-
|
450
450
|
# :stopdoc:
|
451
451
|
|
452
452
|
IMPL_CLASSES = {
|
@@ -457,20 +457,14 @@ module RGeo
|
|
457
457
|
Feature::GeometryCollection => CAPIGeometryCollectionImpl,
|
458
458
|
Feature::MultiPoint => CAPIMultiPointImpl,
|
459
459
|
Feature::MultiLineString => CAPIMultiLineStringImpl,
|
460
|
-
Feature::MultiPolygon => CAPIMultiPolygonImpl
|
460
|
+
Feature::MultiPolygon => CAPIMultiPolygonImpl
|
461
461
|
}.freeze
|
462
462
|
|
463
463
|
# :startdoc:
|
464
|
-
|
465
|
-
|
466
464
|
end
|
467
465
|
|
468
|
-
|
469
466
|
# Deprecated alias of CAPIFactory.
|
470
467
|
# Defined primarily to support old YAML serializations.
|
471
468
|
Factory = CAPIFactory
|
472
|
-
|
473
|
-
|
474
469
|
end
|
475
|
-
|
476
470
|
end
|