rgeo 2.4.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +6 -0
  3. data/README.md +21 -11
  4. data/ext/geos_c_impl/analysis.c +29 -26
  5. data/ext/geos_c_impl/analysis.h +8 -5
  6. data/ext/geos_c_impl/coordinates.c +27 -21
  7. data/ext/geos_c_impl/coordinates.h +5 -2
  8. data/ext/geos_c_impl/errors.c +19 -10
  9. data/ext/geos_c_impl/errors.h +11 -4
  10. data/ext/geos_c_impl/extconf.rb +41 -29
  11. data/ext/geos_c_impl/factory.c +441 -351
  12. data/ext/geos_c_impl/factory.h +98 -55
  13. data/ext/geos_c_impl/geometry.c +563 -384
  14. data/ext/geos_c_impl/geometry.h +10 -3
  15. data/ext/geos_c_impl/geometry_collection.c +288 -316
  16. data/ext/geos_c_impl/geometry_collection.h +6 -18
  17. data/ext/geos_c_impl/globals.c +99 -21
  18. data/ext/geos_c_impl/globals.h +3 -2
  19. data/ext/geos_c_impl/line_string.c +263 -222
  20. data/ext/geos_c_impl/line_string.h +5 -6
  21. data/ext/geos_c_impl/main.c +8 -9
  22. data/ext/geos_c_impl/point.c +62 -65
  23. data/ext/geos_c_impl/point.h +4 -5
  24. data/ext/geos_c_impl/polygon.c +134 -132
  25. data/ext/geos_c_impl/polygon.h +11 -9
  26. data/ext/geos_c_impl/preface.h +10 -12
  27. data/ext/geos_c_impl/ruby_more.c +67 -0
  28. data/ext/geos_c_impl/ruby_more.h +25 -0
  29. data/lib/rgeo/cartesian/analysis.rb +5 -3
  30. data/lib/rgeo/cartesian/bounding_box.rb +74 -79
  31. data/lib/rgeo/cartesian/calculations.rb +64 -33
  32. data/lib/rgeo/cartesian/factory.rb +57 -102
  33. data/lib/rgeo/cartesian/feature_classes.rb +68 -46
  34. data/lib/rgeo/cartesian/feature_methods.rb +67 -25
  35. data/lib/rgeo/cartesian/interface.rb +6 -41
  36. data/lib/rgeo/cartesian/planar_graph.rb +373 -0
  37. data/lib/rgeo/cartesian/sweepline_intersector.rb +147 -0
  38. data/lib/rgeo/cartesian/valid_op.rb +69 -0
  39. data/lib/rgeo/cartesian.rb +3 -0
  40. data/lib/rgeo/coord_sys/cs/entities.rb +299 -99
  41. data/lib/rgeo/coord_sys/cs/factories.rb +0 -2
  42. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +90 -42
  43. data/lib/rgeo/coord_sys.rb +1 -20
  44. data/lib/rgeo/error.rb +15 -0
  45. data/lib/rgeo/feature/curve.rb +0 -11
  46. data/lib/rgeo/feature/factory.rb +26 -36
  47. data/lib/rgeo/feature/factory_generator.rb +6 -14
  48. data/lib/rgeo/feature/geometry.rb +146 -66
  49. data/lib/rgeo/feature/geometry_collection.rb +16 -9
  50. data/lib/rgeo/feature/line_string.rb +4 -5
  51. data/lib/rgeo/feature/linear_ring.rb +0 -1
  52. data/lib/rgeo/feature/multi_curve.rb +0 -6
  53. data/lib/rgeo/feature/multi_surface.rb +3 -4
  54. data/lib/rgeo/feature/point.rb +4 -5
  55. data/lib/rgeo/feature/polygon.rb +1 -2
  56. data/lib/rgeo/feature/surface.rb +3 -4
  57. data/lib/rgeo/feature/types.rb +73 -83
  58. data/lib/rgeo/geographic/factory.rb +98 -125
  59. data/lib/rgeo/geographic/interface.rb +66 -163
  60. data/lib/rgeo/geographic/projected_feature_classes.rb +21 -9
  61. data/lib/rgeo/geographic/projected_feature_methods.rb +67 -42
  62. data/lib/rgeo/geographic/projected_window.rb +36 -22
  63. data/lib/rgeo/geographic/{proj4_projector.rb → projector.rb} +3 -5
  64. data/lib/rgeo/geographic/simple_mercator_projector.rb +24 -23
  65. data/lib/rgeo/geographic/spherical_feature_classes.rb +29 -9
  66. data/lib/rgeo/geographic/spherical_feature_methods.rb +86 -9
  67. data/lib/rgeo/geographic/spherical_math.rb +17 -20
  68. data/lib/rgeo/geographic.rb +1 -1
  69. data/lib/rgeo/geos/capi_factory.rb +87 -158
  70. data/lib/rgeo/geos/capi_feature_classes.rb +50 -36
  71. data/lib/rgeo/geos/ffi_factory.rb +95 -165
  72. data/lib/rgeo/geos/ffi_feature_classes.rb +34 -10
  73. data/lib/rgeo/geos/ffi_feature_methods.rb +105 -126
  74. data/lib/rgeo/geos/interface.rb +20 -59
  75. data/lib/rgeo/geos/utils.rb +3 -3
  76. data/lib/rgeo/geos/zm_factory.rb +53 -95
  77. data/lib/rgeo/geos/zm_feature_methods.rb +30 -32
  78. data/lib/rgeo/geos.rb +8 -8
  79. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +9 -22
  80. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +1 -2
  81. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +28 -56
  82. data/lib/rgeo/impl_helper/basic_point_methods.rb +2 -14
  83. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +17 -26
  84. data/lib/rgeo/impl_helper/utils.rb +21 -0
  85. data/lib/rgeo/impl_helper/valid_op.rb +350 -0
  86. data/lib/rgeo/impl_helper/validity_check.rb +139 -0
  87. data/lib/rgeo/impl_helper.rb +1 -0
  88. data/lib/rgeo/version.rb +1 -1
  89. data/lib/rgeo/wkrep/wkb_generator.rb +73 -63
  90. data/lib/rgeo/wkrep/wkb_parser.rb +33 -31
  91. data/lib/rgeo/wkrep/wkt_generator.rb +52 -45
  92. data/lib/rgeo/wkrep/wkt_parser.rb +48 -35
  93. data/lib/rgeo.rb +1 -3
  94. metadata +51 -16
  95. data/lib/rgeo/coord_sys/srs_database/entry.rb +0 -107
  96. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +0 -64
  97. 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 = @support_ewkt || @support_wkt12 ? false : opts[:strict_wkt11] ? true : false
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
- str = str.downcase
119
- @cur_factory = @exact_factory
120
- if @cur_factory
121
- @cur_factory_support_z = @cur_factory.property(:has_z_coordinate) ? true : false
122
- @cur_factory_support_m = @cur_factory.property(:has_m_coordinate) ? true : false
123
- end
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
- ensure
138
- clean_scanner
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
- if @cur_expect_m && !@cur_factory_support_m
150
- raise Error::ParseError, "Geometry calls for M coordinate but factory doesn't support it."
151
- end
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(srid: @cur_srid, has_z_coordinate: @cur_expect_z, has_m_coordinate: @cur_expect_m)
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" ? true : false
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" ? true : false
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 = false)
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. For example, it
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,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgeo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Azuma
8
8
  - Tee Parham
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-01-19 00:00:00.000000000 Z
12
+ date: 2023-01-25 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: '1.2'
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: '1.2'
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.8.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.8.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
@@ -120,6 +150,8 @@ files:
120
150
  - ext/geos_c_impl/polygon.c
121
151
  - ext/geos_c_impl/polygon.h
122
152
  - ext/geos_c_impl/preface.h
153
+ - ext/geos_c_impl/ruby_more.c
154
+ - ext/geos_c_impl/ruby_more.h
123
155
  - lib/rgeo.rb
124
156
  - lib/rgeo/cartesian.rb
125
157
  - lib/rgeo/cartesian/analysis.rb
@@ -129,13 +161,13 @@ files:
129
161
  - lib/rgeo/cartesian/feature_classes.rb
130
162
  - lib/rgeo/cartesian/feature_methods.rb
131
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
132
167
  - lib/rgeo/coord_sys.rb
133
168
  - lib/rgeo/coord_sys/cs/entities.rb
134
169
  - lib/rgeo/coord_sys/cs/factories.rb
135
170
  - lib/rgeo/coord_sys/cs/wkt_parser.rb
136
- - lib/rgeo/coord_sys/srs_database/entry.rb
137
- - lib/rgeo/coord_sys/srs_database/sr_org.rb
138
- - lib/rgeo/coord_sys/srs_database/url_reader.rb
139
171
  - lib/rgeo/error.rb
140
172
  - lib/rgeo/feature.rb
141
173
  - lib/rgeo/feature/curve.rb
@@ -158,10 +190,10 @@ files:
158
190
  - lib/rgeo/geographic.rb
159
191
  - lib/rgeo/geographic/factory.rb
160
192
  - lib/rgeo/geographic/interface.rb
161
- - lib/rgeo/geographic/proj4_projector.rb
162
193
  - lib/rgeo/geographic/projected_feature_classes.rb
163
194
  - lib/rgeo/geographic/projected_feature_methods.rb
164
195
  - lib/rgeo/geographic/projected_window.rb
196
+ - lib/rgeo/geographic/projector.rb
165
197
  - lib/rgeo/geographic/simple_mercator_projector.rb
166
198
  - lib/rgeo/geographic/spherical_feature_classes.rb
167
199
  - lib/rgeo/geographic/spherical_feature_methods.rb
@@ -185,6 +217,8 @@ files:
185
217
  - lib/rgeo/impl_helper/basic_polygon_methods.rb
186
218
  - lib/rgeo/impl_helper/math.rb
187
219
  - lib/rgeo/impl_helper/utils.rb
220
+ - lib/rgeo/impl_helper/valid_op.rb
221
+ - lib/rgeo/impl_helper/validity_check.rb
188
222
  - lib/rgeo/version.rb
189
223
  - lib/rgeo/wkrep.rb
190
224
  - lib/rgeo/wkrep/wkb_generator.rb
@@ -194,8 +228,9 @@ files:
194
228
  homepage: https://github.com/rgeo/rgeo
195
229
  licenses:
196
230
  - BSD-3-Clause
197
- metadata: {}
198
- post_install_message:
231
+ metadata:
232
+ rubygems_mfa_required: 'true'
233
+ post_install_message:
199
234
  rdoc_options: []
200
235
  require_paths:
201
236
  - lib
@@ -203,15 +238,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
203
238
  requirements:
204
239
  - - ">="
205
240
  - !ruby/object:Gem::Version
206
- version: 2.5.0
241
+ version: 2.6.0
207
242
  required_rubygems_version: !ruby/object:Gem::Requirement
208
243
  requirements:
209
244
  - - ">="
210
245
  - !ruby/object:Gem::Version
211
246
  version: '0'
212
247
  requirements: []
213
- rubygems_version: 3.1.6
214
- signing_key:
248
+ rubygems_version: 3.1.4
249
+ signing_key:
215
250
  specification_version: 4
216
251
  summary: RGeo is a geospatial data library for Ruby.
217
252
  test_files: []
@@ -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