rgeo 2.3.1 → 3.0.1
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/.yardopts +6 -0
- data/README.md +23 -14
- data/ext/geos_c_impl/analysis.c +30 -25
- data/ext/geos_c_impl/analysis.h +8 -7
- data/ext/geos_c_impl/coordinates.c +27 -21
- data/ext/geos_c_impl/coordinates.h +5 -2
- data/ext/geos_c_impl/errors.c +19 -10
- data/ext/geos_c_impl/errors.h +11 -4
- data/ext/geos_c_impl/extconf.rb +42 -28
- data/ext/geos_c_impl/factory.c +540 -451
- data/ext/geos_c_impl/factory.h +105 -95
- data/ext/geos_c_impl/geometry.c +593 -387
- data/ext/geos_c_impl/geometry.h +10 -5
- data/ext/geos_c_impl/geometry_collection.c +306 -339
- data/ext/geos_c_impl/geometry_collection.h +6 -20
- data/ext/geos_c_impl/globals.c +169 -0
- data/ext/geos_c_impl/globals.h +46 -0
- data/ext/geos_c_impl/line_string.c +271 -231
- data/ext/geos_c_impl/line_string.h +5 -8
- data/ext/geos_c_impl/main.c +16 -16
- data/ext/geos_c_impl/point.c +65 -67
- data/ext/geos_c_impl/point.h +4 -7
- data/ext/geos_c_impl/polygon.c +137 -135
- data/ext/geos_c_impl/polygon.h +11 -11
- data/ext/geos_c_impl/preface.h +16 -10
- data/ext/geos_c_impl/ruby_more.c +67 -0
- data/ext/geos_c_impl/ruby_more.h +25 -0
- data/lib/rgeo/cartesian/analysis.rb +5 -3
- data/lib/rgeo/cartesian/bounding_box.rb +74 -79
- data/lib/rgeo/cartesian/calculations.rb +64 -33
- data/lib/rgeo/cartesian/factory.rb +57 -102
- data/lib/rgeo/cartesian/feature_classes.rb +68 -46
- data/lib/rgeo/cartesian/feature_methods.rb +67 -25
- data/lib/rgeo/cartesian/interface.rb +6 -41
- data/lib/rgeo/cartesian/planar_graph.rb +373 -0
- data/lib/rgeo/cartesian/sweepline_intersector.rb +147 -0
- data/lib/rgeo/cartesian/valid_op.rb +69 -0
- data/lib/rgeo/cartesian.rb +3 -0
- data/lib/rgeo/coord_sys/cs/entities.rb +303 -99
- data/lib/rgeo/coord_sys/cs/factories.rb +0 -2
- data/lib/rgeo/coord_sys/cs/wkt_parser.rb +90 -42
- data/lib/rgeo/coord_sys.rb +1 -20
- data/lib/rgeo/error.rb +15 -0
- data/lib/rgeo/feature/curve.rb +0 -11
- data/lib/rgeo/feature/factory.rb +26 -36
- data/lib/rgeo/feature/factory_generator.rb +6 -14
- data/lib/rgeo/feature/geometry.rb +146 -66
- data/lib/rgeo/feature/geometry_collection.rb +16 -9
- data/lib/rgeo/feature/line_string.rb +4 -5
- data/lib/rgeo/feature/linear_ring.rb +0 -1
- data/lib/rgeo/feature/multi_curve.rb +0 -6
- data/lib/rgeo/feature/multi_surface.rb +3 -4
- data/lib/rgeo/feature/point.rb +4 -5
- data/lib/rgeo/feature/polygon.rb +1 -2
- data/lib/rgeo/feature/surface.rb +3 -4
- data/lib/rgeo/feature/types.rb +69 -85
- data/lib/rgeo/geographic/factory.rb +98 -125
- data/lib/rgeo/geographic/interface.rb +69 -166
- data/lib/rgeo/geographic/projected_feature_classes.rb +21 -9
- data/lib/rgeo/geographic/projected_feature_methods.rb +67 -42
- data/lib/rgeo/geographic/projected_window.rb +36 -22
- data/lib/rgeo/geographic/{proj4_projector.rb → projector.rb} +3 -5
- data/lib/rgeo/geographic/simple_mercator_projector.rb +26 -25
- data/lib/rgeo/geographic/spherical_feature_classes.rb +29 -9
- data/lib/rgeo/geographic/spherical_feature_methods.rb +86 -9
- data/lib/rgeo/geographic/spherical_math.rb +17 -20
- data/lib/rgeo/geographic.rb +1 -1
- data/lib/rgeo/geos/capi_factory.rb +87 -158
- data/lib/rgeo/geos/capi_feature_classes.rb +50 -36
- data/lib/rgeo/geos/ffi_factory.rb +105 -173
- data/lib/rgeo/geos/ffi_feature_classes.rb +34 -10
- data/lib/rgeo/geos/ffi_feature_methods.rb +105 -127
- data/lib/rgeo/geos/interface.rb +20 -59
- data/lib/rgeo/geos/utils.rb +5 -5
- data/lib/rgeo/geos/zm_factory.rb +53 -95
- data/lib/rgeo/geos/zm_feature_methods.rb +30 -33
- data/lib/rgeo/geos.rb +8 -8
- data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +9 -22
- data/lib/rgeo/impl_helper/basic_geometry_methods.rb +1 -2
- data/lib/rgeo/impl_helper/basic_line_string_methods.rb +28 -56
- data/lib/rgeo/impl_helper/basic_point_methods.rb +2 -14
- data/lib/rgeo/impl_helper/basic_polygon_methods.rb +17 -26
- data/lib/rgeo/impl_helper/utils.rb +21 -0
- data/lib/rgeo/impl_helper/valid_op.rb +350 -0
- data/lib/rgeo/impl_helper/validity_check.rb +139 -0
- data/lib/rgeo/impl_helper.rb +1 -0
- data/lib/rgeo/version.rb +1 -1
- data/lib/rgeo/wkrep/wkb_generator.rb +73 -63
- data/lib/rgeo/wkrep/wkb_parser.rb +33 -31
- data/lib/rgeo/wkrep/wkt_generator.rb +52 -45
- data/lib/rgeo/wkrep/wkt_parser.rb +48 -35
- data/lib/rgeo.rb +1 -3
- metadata +50 -13
- data/lib/rgeo/coord_sys/srs_database/entry.rb +0 -107
- data/lib/rgeo/coord_sys/srs_database/sr_org.rb +0 -64
- data/lib/rgeo/coord_sys/srs_database/url_reader.rb +0 -65
@@ -48,7 +48,6 @@ module RGeo
|
|
48
48
|
# [<tt>:default_srid</tt>]
|
49
49
|
# A SRID to pass to the factory generator if no SRID is present in
|
50
50
|
# the input. Defaults to nil (i.e. don't specify a SRID).
|
51
|
-
|
52
51
|
class WKTParser
|
53
52
|
# Create and configure a WKT parser. See the WKTParser
|
54
53
|
# documentation for the options that can be passed.
|
@@ -66,9 +65,15 @@ module RGeo
|
|
66
65
|
end
|
67
66
|
@support_ewkt = opts[:support_ewkt] ? true : false
|
68
67
|
@support_wkt12 = opts[:support_wkt12] ? true : false
|
69
|
-
@strict_wkt11 =
|
68
|
+
@strict_wkt11 =
|
69
|
+
if @support_ewkt || @support_wkt12
|
70
|
+
false
|
71
|
+
else
|
72
|
+
opts[:strict_wkt11] ? true : false
|
73
|
+
end
|
70
74
|
@ignore_extra_tokens = opts[:ignore_extra_tokens] ? true : false
|
71
75
|
@default_srid = opts[:default_srid]
|
76
|
+
@mutex = Mutex.new
|
72
77
|
end
|
73
78
|
|
74
79
|
# Returns the factory generator. See WKTParser for details.
|
@@ -115,29 +120,32 @@ module RGeo
|
|
115
120
|
# Parse the given string, and return a geometry object.
|
116
121
|
|
117
122
|
def parse(str)
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
@cur_expect_z = nil
|
125
|
-
@cur_expect_m = nil
|
126
|
-
@cur_srid = @default_srid
|
127
|
-
if @support_ewkt && str =~ /^srid=(\d+);/i
|
128
|
-
str = $'
|
129
|
-
@cur_srid = Regexp.last_match(1).to_i
|
130
|
-
end
|
131
|
-
begin
|
132
|
-
start_scanner(str)
|
133
|
-
obj = parse_type_tag
|
134
|
-
if @cur_token && !@ignore_extra_tokens
|
135
|
-
raise Error::ParseError, "Extra tokens beginning with #{@cur_token.inspect}."
|
123
|
+
@mutex.synchronize do
|
124
|
+
str = str.downcase
|
125
|
+
@cur_factory = @exact_factory
|
126
|
+
if @cur_factory
|
127
|
+
@cur_factory_support_z = @cur_factory.property(:has_z_coordinate) ? true : false
|
128
|
+
@cur_factory_support_m = @cur_factory.property(:has_m_coordinate) ? true : false
|
136
129
|
end
|
137
|
-
|
138
|
-
|
130
|
+
@cur_expect_z = nil
|
131
|
+
@cur_expect_m = nil
|
132
|
+
@cur_srid = @default_srid
|
133
|
+
if @support_ewkt && str =~ /^srid=(\d+);/i
|
134
|
+
str = Regexp.last_match&.post_match
|
135
|
+
@cur_srid = Regexp.last_match(1).to_i
|
136
|
+
end
|
137
|
+
begin
|
138
|
+
start_scanner(str)
|
139
|
+
obj = parse_type_tag
|
140
|
+
|
141
|
+
if @cur_token && !@ignore_extra_tokens
|
142
|
+
raise Error::ParseError, "Extra tokens beginning with #{@cur_token.inspect}."
|
143
|
+
end
|
144
|
+
ensure
|
145
|
+
clean_scanner
|
146
|
+
end
|
147
|
+
obj
|
139
148
|
end
|
140
|
-
obj
|
141
149
|
end
|
142
150
|
|
143
151
|
private
|
@@ -146,14 +154,19 @@ module RGeo
|
|
146
154
|
if @cur_expect_z && !@cur_factory_support_z
|
147
155
|
raise Error::ParseError, "Geometry calls for Z coordinate but factory doesn't support it."
|
148
156
|
end
|
149
|
-
|
150
|
-
|
151
|
-
|
157
|
+
|
158
|
+
return unless @cur_expect_m && !@cur_factory_support_m
|
159
|
+
|
160
|
+
raise Error::ParseError, "Geometry calls for M coordinate but factory doesn't support it."
|
152
161
|
end
|
153
162
|
|
154
163
|
def ensure_factory
|
155
164
|
unless @cur_factory
|
156
|
-
@cur_factory = @factory_generator.call(
|
165
|
+
@cur_factory = @factory_generator.call(
|
166
|
+
srid: @cur_srid,
|
167
|
+
has_z_coordinate: @cur_expect_z,
|
168
|
+
has_m_coordinate: @cur_expect_m
|
169
|
+
)
|
157
170
|
@cur_factory_support_z = @cur_factory.property(:has_z_coordinate) ? true : false
|
158
171
|
@cur_factory_support_m = @cur_factory.property(:has_m_coordinate) ? true : false
|
159
172
|
check_factory_support unless @cur_expect_z.nil?
|
@@ -177,13 +190,13 @@ module RGeo
|
|
177
190
|
end
|
178
191
|
if zm.length > 0 || @strict_wkt11
|
179
192
|
creating_expectation = @cur_expect_z.nil?
|
180
|
-
expect_z = zm[0, 1] == "z"
|
193
|
+
expect_z = zm[0, 1] == "z"
|
181
194
|
if @cur_expect_z.nil?
|
182
195
|
@cur_expect_z = expect_z
|
183
196
|
elsif expect_z != @cur_expect_z
|
184
197
|
raise Error::ParseError, "Surrounding collection has Z but contained geometry doesn't."
|
185
198
|
end
|
186
|
-
expect_m = zm[-1, 1] == "m"
|
199
|
+
expect_m = zm[-1, 1] == "m"
|
187
200
|
if @cur_expect_m.nil?
|
188
201
|
@cur_expect_m = expect_m
|
189
202
|
elsif expect_m != @cur_expect_m
|
@@ -199,7 +212,7 @@ module RGeo
|
|
199
212
|
end
|
200
213
|
case type
|
201
214
|
when "point"
|
202
|
-
parse_point(true)
|
215
|
+
parse_point(convert_empty: true)
|
203
216
|
when "linestring"
|
204
217
|
parse_line_string
|
205
218
|
when "polygon"
|
@@ -235,9 +248,11 @@ module RGeo
|
|
235
248
|
num_extras -= 1 if @cur_expect_z
|
236
249
|
@cur_expect_m = num_extras > 0 && (!@cur_factory || @cur_factory_support_m) ? true : false
|
237
250
|
num_extras -= 1 if @cur_expect_m
|
251
|
+
|
238
252
|
if num_extras > 0
|
239
253
|
raise Error::ParseError, "Found #{extra.size + 2} coordinates, which is too many for this factory."
|
240
254
|
end
|
255
|
+
|
241
256
|
ensure_factory
|
242
257
|
else
|
243
258
|
val = 0
|
@@ -258,7 +273,7 @@ module RGeo
|
|
258
273
|
@cur_factory.point(x, y, *extra)
|
259
274
|
end
|
260
275
|
|
261
|
-
def parse_point(convert_empty
|
276
|
+
def parse_point(convert_empty: false)
|
262
277
|
if convert_empty && @cur_token == "empty"
|
263
278
|
point = ensure_factory.multi_point([])
|
264
279
|
else
|
@@ -387,13 +402,11 @@ module RGeo
|
|
387
402
|
end
|
388
403
|
|
389
404
|
def expect_token_type(type)
|
390
|
-
unless type === @cur_token
|
391
|
-
raise Error::ParseError, "#{type.inspect} expected but #{@cur_token.inspect} found."
|
392
|
-
end
|
405
|
+
raise Error::ParseError, "#{type.inspect} expected but #{@cur_token.inspect} found." unless type === @cur_token
|
393
406
|
end
|
394
407
|
|
395
408
|
def next_token
|
396
|
-
if @scanner.scan_until(/\(|\)|\[|\]|,|[^\s
|
409
|
+
if @scanner.scan_until(/\(|\)|\[|\]|,|[^\s()\[\],]+/)
|
397
410
|
token = @scanner.matched
|
398
411
|
case token
|
399
412
|
when /^[-+]?(\d+(\.\d*)?|\.\d+)(e[-+]?\d+)?$/
|
data/lib/rgeo.rb
CHANGED
@@ -16,9 +16,7 @@
|
|
16
16
|
# Simple Features Specifiation (SFS). This module forms the core of RGeo.
|
17
17
|
#
|
18
18
|
# * RGeo::CoordSys contains classes for representing spatial
|
19
|
-
# reference systems and coordinate transformations.
|
20
|
-
# includes a wrapper for the Proj4 library, supporting many geographic
|
21
|
-
# projections.
|
19
|
+
# reference systems and coordinate transformations.
|
22
20
|
#
|
23
21
|
# * RGeo::Cartesian is a gateway for geometric data implementations
|
24
22
|
# that operate in Caresian (flat) coordinate systems. It also provides a
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rgeo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Azuma
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-11-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi-geos
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '2.2'
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
27
|
+
version: '2.2'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: minitest
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,14 +73,42 @@ dependencies:
|
|
73
73
|
requirements:
|
74
74
|
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: 1.
|
76
|
+
version: 1.36.0
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version: 1.
|
83
|
+
version: 1.36.0
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: ruby_memcheck
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '1.0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '1.0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: yard
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0.9'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0.9'
|
84
112
|
description: RGeo is a geospatial data library for Ruby. It provides an implementation
|
85
113
|
of the Open Geospatial Consortium's Simple Features Specification, used by most
|
86
114
|
standard spatial/geographic data storage systems such as PostGIS. A number of add-on
|
@@ -90,11 +118,13 @@ email:
|
|
90
118
|
- dazuma@gmail.com
|
91
119
|
- parhameter@gmail.com
|
92
120
|
- kfdoggett@gmail.com
|
121
|
+
- buonomo.ulysse@gmail.com
|
93
122
|
executables: []
|
94
123
|
extensions:
|
95
124
|
- ext/geos_c_impl/extconf.rb
|
96
125
|
extra_rdoc_files: []
|
97
126
|
files:
|
127
|
+
- ".yardopts"
|
98
128
|
- LICENSE.txt
|
99
129
|
- README.md
|
100
130
|
- ext/geos_c_impl/analysis.c
|
@@ -110,6 +140,8 @@ files:
|
|
110
140
|
- ext/geos_c_impl/geometry.h
|
111
141
|
- ext/geos_c_impl/geometry_collection.c
|
112
142
|
- ext/geos_c_impl/geometry_collection.h
|
143
|
+
- ext/geos_c_impl/globals.c
|
144
|
+
- ext/geos_c_impl/globals.h
|
113
145
|
- ext/geos_c_impl/line_string.c
|
114
146
|
- ext/geos_c_impl/line_string.h
|
115
147
|
- ext/geos_c_impl/main.c
|
@@ -118,6 +150,8 @@ files:
|
|
118
150
|
- ext/geos_c_impl/polygon.c
|
119
151
|
- ext/geos_c_impl/polygon.h
|
120
152
|
- ext/geos_c_impl/preface.h
|
153
|
+
- ext/geos_c_impl/ruby_more.c
|
154
|
+
- ext/geos_c_impl/ruby_more.h
|
121
155
|
- lib/rgeo.rb
|
122
156
|
- lib/rgeo/cartesian.rb
|
123
157
|
- lib/rgeo/cartesian/analysis.rb
|
@@ -127,13 +161,13 @@ files:
|
|
127
161
|
- lib/rgeo/cartesian/feature_classes.rb
|
128
162
|
- lib/rgeo/cartesian/feature_methods.rb
|
129
163
|
- lib/rgeo/cartesian/interface.rb
|
164
|
+
- lib/rgeo/cartesian/planar_graph.rb
|
165
|
+
- lib/rgeo/cartesian/sweepline_intersector.rb
|
166
|
+
- lib/rgeo/cartesian/valid_op.rb
|
130
167
|
- lib/rgeo/coord_sys.rb
|
131
168
|
- lib/rgeo/coord_sys/cs/entities.rb
|
132
169
|
- lib/rgeo/coord_sys/cs/factories.rb
|
133
170
|
- lib/rgeo/coord_sys/cs/wkt_parser.rb
|
134
|
-
- lib/rgeo/coord_sys/srs_database/entry.rb
|
135
|
-
- lib/rgeo/coord_sys/srs_database/sr_org.rb
|
136
|
-
- lib/rgeo/coord_sys/srs_database/url_reader.rb
|
137
171
|
- lib/rgeo/error.rb
|
138
172
|
- lib/rgeo/feature.rb
|
139
173
|
- lib/rgeo/feature/curve.rb
|
@@ -156,10 +190,10 @@ files:
|
|
156
190
|
- lib/rgeo/geographic.rb
|
157
191
|
- lib/rgeo/geographic/factory.rb
|
158
192
|
- lib/rgeo/geographic/interface.rb
|
159
|
-
- lib/rgeo/geographic/proj4_projector.rb
|
160
193
|
- lib/rgeo/geographic/projected_feature_classes.rb
|
161
194
|
- lib/rgeo/geographic/projected_feature_methods.rb
|
162
195
|
- lib/rgeo/geographic/projected_window.rb
|
196
|
+
- lib/rgeo/geographic/projector.rb
|
163
197
|
- lib/rgeo/geographic/simple_mercator_projector.rb
|
164
198
|
- lib/rgeo/geographic/spherical_feature_classes.rb
|
165
199
|
- lib/rgeo/geographic/spherical_feature_methods.rb
|
@@ -183,6 +217,8 @@ files:
|
|
183
217
|
- lib/rgeo/impl_helper/basic_polygon_methods.rb
|
184
218
|
- lib/rgeo/impl_helper/math.rb
|
185
219
|
- lib/rgeo/impl_helper/utils.rb
|
220
|
+
- lib/rgeo/impl_helper/valid_op.rb
|
221
|
+
- lib/rgeo/impl_helper/validity_check.rb
|
186
222
|
- lib/rgeo/version.rb
|
187
223
|
- lib/rgeo/wkrep.rb
|
188
224
|
- lib/rgeo/wkrep/wkb_generator.rb
|
@@ -192,7 +228,8 @@ files:
|
|
192
228
|
homepage: https://github.com/rgeo/rgeo
|
193
229
|
licenses:
|
194
230
|
- BSD-3-Clause
|
195
|
-
metadata:
|
231
|
+
metadata:
|
232
|
+
rubygems_mfa_required: 'true'
|
196
233
|
post_install_message:
|
197
234
|
rdoc_options: []
|
198
235
|
require_paths:
|
@@ -201,14 +238,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
201
238
|
requirements:
|
202
239
|
- - ">="
|
203
240
|
- !ruby/object:Gem::Version
|
204
|
-
version: 2.
|
241
|
+
version: 2.7.7
|
205
242
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
206
243
|
requirements:
|
207
244
|
- - ">="
|
208
245
|
- !ruby/object:Gem::Version
|
209
246
|
version: '0'
|
210
247
|
requirements: []
|
211
|
-
rubygems_version: 3.
|
248
|
+
rubygems_version: 3.2.33
|
212
249
|
signing_key:
|
213
250
|
specification_version: 4
|
214
251
|
summary: RGeo is a geospatial data library for Ruby.
|
@@ -1,107 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# -----------------------------------------------------------------------------
|
4
|
-
#
|
5
|
-
# SRS database interface
|
6
|
-
#
|
7
|
-
# -----------------------------------------------------------------------------
|
8
|
-
|
9
|
-
module RGeo
|
10
|
-
module CoordSys
|
11
|
-
# This module contains tools for accessing spatial reference
|
12
|
-
# databases. These are databases (either local or remote) from which
|
13
|
-
# you can look up coordinate system specifications, typically in
|
14
|
-
# either OGC or Proj4 format. For example, you can access the
|
15
|
-
# <tt>spatial_ref_sys</tt> table provided with an OGC-compliant RDBMS
|
16
|
-
# such as PostGIS. You can also read the database files provided with
|
17
|
-
# the proj4 library, or access online databases such as the
|
18
|
-
# spatialreference.org site.
|
19
|
-
|
20
|
-
# Spatial reference system database classes must implement these methods:
|
21
|
-
# get
|
22
|
-
# clear_cache
|
23
|
-
#
|
24
|
-
# See SrOrg and UrlReader for implementations of SRSDatabase classes.
|
25
|
-
#
|
26
|
-
# Retrieve an Entry given an identifier. The identifier is usually
|
27
|
-
# a numeric spatial reference ID (SRID), but could be a string
|
28
|
-
# value for certain database types.
|
29
|
-
# get(identifier)
|
30
|
-
#
|
31
|
-
# Clear any cache utilized by this database.
|
32
|
-
# clear_cache
|
33
|
-
|
34
|
-
module SRSDatabase
|
35
|
-
# An entry in a spatial reference system database.
|
36
|
-
# Every entry has an identifier, but all the other attributes are
|
37
|
-
# optional and may or may not be present depending on the database.
|
38
|
-
class Entry
|
39
|
-
# Create an entry.
|
40
|
-
# You must provide an identifier, which may be numeric or a
|
41
|
-
# string. The data hash should contain any other attributes,
|
42
|
-
# keyed by symbol.
|
43
|
-
#
|
44
|
-
# Some attribute inputs have special behaviors:
|
45
|
-
#
|
46
|
-
# [<tt>:coord_sys</tt>]
|
47
|
-
# You can pass a CS coordinate system object, or a string in
|
48
|
-
# WKT format.
|
49
|
-
# [<tt>:proj4</tt>]
|
50
|
-
# You can pass a Proj4 object, or a proj4-format string.
|
51
|
-
# [<tt>:name</tt>]
|
52
|
-
# If the name is not provided directly, it is taken from the
|
53
|
-
# coord_sys.
|
54
|
-
# [<tt>:authority</tt>]
|
55
|
-
# If the authority name is not provided directly, it is taken
|
56
|
-
# from the coord_sys.
|
57
|
-
# [<tt>:authority_code</tt>]
|
58
|
-
# If the authority code is not provided directly, it is taken
|
59
|
-
# from the coord_sys.
|
60
|
-
|
61
|
-
def initialize(ident, data = {})
|
62
|
-
@identifier = ident
|
63
|
-
@authority = data[:authority]
|
64
|
-
@authority_code = data[:authority_code]
|
65
|
-
@name = data[:name]
|
66
|
-
@description = data[:description]
|
67
|
-
@coord_sys = data[:coord_sys]
|
68
|
-
if @coord_sys.is_a?(String)
|
69
|
-
@coord_sys = CS.create_from_wkt(@coord_sys)
|
70
|
-
end
|
71
|
-
@proj4 = data[:proj4]
|
72
|
-
if @proj4 && CoordSys.check!(:proj4)
|
73
|
-
if @proj4.is_a?(String) || @proj4.is_a?(Hash)
|
74
|
-
@proj4 = Proj4.create(@proj4)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
if @coord_sys
|
78
|
-
@name = @coord_sys.name unless @name
|
79
|
-
@authority = @coord_sys.authority unless @authority
|
80
|
-
@authority_code = @coord_sys.authority unless @authority_code
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
# The database key or identifier.
|
85
|
-
attr_reader :identifier
|
86
|
-
|
87
|
-
# The authority name, if present. Example: "epsg".
|
88
|
-
attr_reader :authority
|
89
|
-
|
90
|
-
# The authority code, e.g. an EPSG code.
|
91
|
-
attr_reader :authority_code
|
92
|
-
|
93
|
-
# A human-readable name for this coordinate system.
|
94
|
-
attr_reader :name
|
95
|
-
|
96
|
-
# A human-readable description for this coordinate system.
|
97
|
-
attr_reader :description
|
98
|
-
|
99
|
-
# The CS::CoordinateSystem object.
|
100
|
-
attr_reader :coord_sys
|
101
|
-
|
102
|
-
# The Proj4 object.
|
103
|
-
attr_reader :proj4
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# -----------------------------------------------------------------------------
|
4
|
-
#
|
5
|
-
# SRS database interface
|
6
|
-
#
|
7
|
-
# -----------------------------------------------------------------------------
|
8
|
-
|
9
|
-
require "net/http"
|
10
|
-
|
11
|
-
module RGeo
|
12
|
-
module CoordSys
|
13
|
-
module SRSDatabase
|
14
|
-
# A spatial reference database implementation that fetches data
|
15
|
-
# from the spatialreference.org website.
|
16
|
-
|
17
|
-
class SrOrg
|
18
|
-
# Create a database backed by the given catalog of the
|
19
|
-
# spatialreference.org website. Catalogs currently supported by
|
20
|
-
# spatialreference.org are "epsg", "esri", "iau2000" and "sr-org".
|
21
|
-
#
|
22
|
-
# Options:
|
23
|
-
#
|
24
|
-
# [<tt>:cache</tt>]
|
25
|
-
# If set to true, lookup results are cached so if the same URL
|
26
|
-
# is requested again, the result is served from cache rather
|
27
|
-
# than issuing another HTTP request. Default is false.
|
28
|
-
|
29
|
-
def initialize(catalog, opts = {})
|
30
|
-
@catalog = catalog.to_s.downcase
|
31
|
-
@cache = opts[:cache] ? {} : nil
|
32
|
-
end
|
33
|
-
|
34
|
-
# The spatialreference.org catalog used by this database.
|
35
|
-
attr_reader :catalog
|
36
|
-
|
37
|
-
# Retrieve the Entry from a spatialreference.org catalog given an
|
38
|
-
# integer ID.
|
39
|
-
|
40
|
-
def get(ident)
|
41
|
-
ident = ident.to_s
|
42
|
-
return @cache[ident] if @cache&.include?(ident)
|
43
|
-
coord_sys = nil
|
44
|
-
proj4 = nil
|
45
|
-
Net::HTTP.start("spatialreference.org") do |http|
|
46
|
-
response = http.request_get("/ref/#{@catalog}/#{ident}/ogcwkt/")
|
47
|
-
coord_sys = response.body if response.is_a?(Net::HTTPSuccess)
|
48
|
-
response = http.request_get("/ref/#{@catalog}/#{ident}/proj4/")
|
49
|
-
proj4 = response.body if response.is_a?(Net::HTTPSuccess)
|
50
|
-
end
|
51
|
-
result = Entry.new(ident, coord_sys: coord_sys.strip, proj4: proj4.strip)
|
52
|
-
@cache[ident] = result if @cache
|
53
|
-
result
|
54
|
-
end
|
55
|
-
|
56
|
-
# Clear the cache if one exists.
|
57
|
-
|
58
|
-
def clear_cache
|
59
|
-
@cache&.clear
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# -----------------------------------------------------------------------------
|
4
|
-
#
|
5
|
-
# SRS database interface
|
6
|
-
#
|
7
|
-
# -----------------------------------------------------------------------------
|
8
|
-
|
9
|
-
require "net/http"
|
10
|
-
|
11
|
-
module RGeo
|
12
|
-
module CoordSys
|
13
|
-
module SRSDatabase
|
14
|
-
# A spatial reference database implementation that fetches data from
|
15
|
-
# internet URLs.
|
16
|
-
|
17
|
-
class UrlReader
|
18
|
-
# Create a URL-based spatial reference database.
|
19
|
-
#
|
20
|
-
# Options:
|
21
|
-
#
|
22
|
-
# [<tt>:cache</tt>]
|
23
|
-
# If set to true, lookup results are cached so if the same URL
|
24
|
-
# is requested again, the result is served from cache rather
|
25
|
-
# than issuing another HTTP request. Default is false.
|
26
|
-
|
27
|
-
def initialize(opts = {})
|
28
|
-
@cache = opts[:cache] ? {} : nil
|
29
|
-
end
|
30
|
-
|
31
|
-
# Retrieve the given URL and return an Entry.
|
32
|
-
# Returns nil if the URL cannot be read as an OGC WKT or Proj4
|
33
|
-
# coordinate system
|
34
|
-
|
35
|
-
def get(ident)
|
36
|
-
ident = ident.to_s
|
37
|
-
return @cache[ident] if @cache&.include?(ident)
|
38
|
-
uri = URI.parse(ident)
|
39
|
-
result = nil
|
40
|
-
Net::HTTP.start(uri.host, uri.port) do |http|
|
41
|
-
request = uri.path
|
42
|
-
request = "#{request}?#{uri.query}" if uri.query
|
43
|
-
response = http.requestget(request)
|
44
|
-
if response.is_a?(Net::HTTPSuccess)
|
45
|
-
response = response.body.strip
|
46
|
-
if response[0, 1] == "+"
|
47
|
-
result = Entry.new(ident, proj4: response)
|
48
|
-
else
|
49
|
-
result = Entry.new(ident, coord_sys: response)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
@cache[ident] = result if @cache
|
54
|
-
result
|
55
|
-
end
|
56
|
-
|
57
|
-
# Clear the cache if one is present.
|
58
|
-
|
59
|
-
def clear_cache
|
60
|
-
@cache&.clear
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|