rgeo 2.4.0 → 3.1.0

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.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +6 -0
  3. data/README.md +23 -14
  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 +43 -29
  11. data/ext/geos_c_impl/factory.c +443 -351
  12. data/ext/geos_c_impl/factory.h +98 -55
  13. data/ext/geos_c_impl/geometry.c +589 -383
  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 +98 -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 +63 -65
  23. data/ext/geos_c_impl/point.h +4 -5
  24. data/ext/geos_c_impl/polygon.c +168 -131
  25. data/ext/geos_c_impl/polygon.h +11 -9
  26. data/ext/geos_c_impl/preface.h +15 -11
  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 +59 -104
  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 +305 -101
  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 +71 -87
  58. data/lib/rgeo/geographic/factory.rb +100 -127
  59. data/lib/rgeo/geographic/interface.rb +71 -168
  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 +26 -25
  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 +107 -175
  72. data/lib/rgeo/geos/ffi_feature_classes.rb +34 -10
  73. data/lib/rgeo/geos/ffi_feature_methods.rb +105 -127
  74. data/lib/rgeo/geos/interface.rb +20 -59
  75. data/lib/rgeo/geos/utils.rb +5 -5
  76. data/lib/rgeo/geos/zm_factory.rb +55 -97
  77. data/lib/rgeo/geos/zm_feature_methods.rb +30 -33
  78. data/lib/rgeo/geos.rb +15 -9
  79. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +11 -24
  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 +63 -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,14 @@
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.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Azuma
8
8
  - Tee Parham
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2022-01-19 00:00:00.000000000 Z
11
+ date: 2026-01-20 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: ffi-geos
@@ -17,14 +16,14 @@ dependencies:
17
16
  requirements:
18
17
  - - "~>"
19
18
  - !ruby/object:Gem::Version
20
- version: '1.2'
19
+ version: '2.2'
21
20
  type: :development
22
21
  prerelease: false
23
22
  version_requirements: !ruby/object:Gem::Requirement
24
23
  requirements:
25
24
  - - "~>"
26
25
  - !ruby/object:Gem::Version
27
- version: '1.2'
26
+ version: '2.2'
28
27
  - !ruby/object:Gem::Dependency
29
28
  name: minitest
30
29
  requirement: !ruby/object:Gem::Requirement
@@ -39,6 +38,20 @@ dependencies:
39
38
  - - "~>"
40
39
  - !ruby/object:Gem::Version
41
40
  version: '5.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ostruct
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
42
55
  - !ruby/object:Gem::Dependency
43
56
  name: rake
44
57
  requirement: !ruby/object:Gem::Requirement
@@ -73,14 +86,42 @@ dependencies:
73
86
  requirements:
74
87
  - - "~>"
75
88
  - !ruby/object:Gem::Version
76
- version: 1.8.1
89
+ version: 1.36.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.36.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: ruby_memcheck
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.9'
77
118
  type: :development
78
119
  prerelease: false
79
120
  version_requirements: !ruby/object:Gem::Requirement
80
121
  requirements:
81
122
  - - "~>"
82
123
  - !ruby/object:Gem::Version
83
- version: 1.8.1
124
+ version: '0.9'
84
125
  description: RGeo is a geospatial data library for Ruby. It provides an implementation
85
126
  of the Open Geospatial Consortium's Simple Features Specification, used by most
86
127
  standard spatial/geographic data storage systems such as PostGIS. A number of add-on
@@ -90,11 +131,13 @@ email:
90
131
  - dazuma@gmail.com
91
132
  - parhameter@gmail.com
92
133
  - kfdoggett@gmail.com
134
+ - buonomo.ulysse@gmail.com
93
135
  executables: []
94
136
  extensions:
95
137
  - ext/geos_c_impl/extconf.rb
96
138
  extra_rdoc_files: []
97
139
  files:
140
+ - ".yardopts"
98
141
  - LICENSE.txt
99
142
  - README.md
100
143
  - ext/geos_c_impl/analysis.c
@@ -120,6 +163,8 @@ files:
120
163
  - ext/geos_c_impl/polygon.c
121
164
  - ext/geos_c_impl/polygon.h
122
165
  - ext/geos_c_impl/preface.h
166
+ - ext/geos_c_impl/ruby_more.c
167
+ - ext/geos_c_impl/ruby_more.h
123
168
  - lib/rgeo.rb
124
169
  - lib/rgeo/cartesian.rb
125
170
  - lib/rgeo/cartesian/analysis.rb
@@ -129,13 +174,13 @@ files:
129
174
  - lib/rgeo/cartesian/feature_classes.rb
130
175
  - lib/rgeo/cartesian/feature_methods.rb
131
176
  - lib/rgeo/cartesian/interface.rb
177
+ - lib/rgeo/cartesian/planar_graph.rb
178
+ - lib/rgeo/cartesian/sweepline_intersector.rb
179
+ - lib/rgeo/cartesian/valid_op.rb
132
180
  - lib/rgeo/coord_sys.rb
133
181
  - lib/rgeo/coord_sys/cs/entities.rb
134
182
  - lib/rgeo/coord_sys/cs/factories.rb
135
183
  - 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
184
  - lib/rgeo/error.rb
140
185
  - lib/rgeo/feature.rb
141
186
  - lib/rgeo/feature/curve.rb
@@ -158,10 +203,10 @@ files:
158
203
  - lib/rgeo/geographic.rb
159
204
  - lib/rgeo/geographic/factory.rb
160
205
  - lib/rgeo/geographic/interface.rb
161
- - lib/rgeo/geographic/proj4_projector.rb
162
206
  - lib/rgeo/geographic/projected_feature_classes.rb
163
207
  - lib/rgeo/geographic/projected_feature_methods.rb
164
208
  - lib/rgeo/geographic/projected_window.rb
209
+ - lib/rgeo/geographic/projector.rb
165
210
  - lib/rgeo/geographic/simple_mercator_projector.rb
166
211
  - lib/rgeo/geographic/spherical_feature_classes.rb
167
212
  - lib/rgeo/geographic/spherical_feature_methods.rb
@@ -185,6 +230,8 @@ files:
185
230
  - lib/rgeo/impl_helper/basic_polygon_methods.rb
186
231
  - lib/rgeo/impl_helper/math.rb
187
232
  - lib/rgeo/impl_helper/utils.rb
233
+ - lib/rgeo/impl_helper/valid_op.rb
234
+ - lib/rgeo/impl_helper/validity_check.rb
188
235
  - lib/rgeo/version.rb
189
236
  - lib/rgeo/wkrep.rb
190
237
  - lib/rgeo/wkrep/wkb_generator.rb
@@ -194,8 +241,9 @@ files:
194
241
  homepage: https://github.com/rgeo/rgeo
195
242
  licenses:
196
243
  - BSD-3-Clause
197
- metadata: {}
198
- post_install_message:
244
+ metadata:
245
+ funding_uri: https://opencollective.com/rgeo
246
+ rubygems_mfa_required: 'true'
199
247
  rdoc_options: []
200
248
  require_paths:
201
249
  - lib
@@ -203,15 +251,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
203
251
  requirements:
204
252
  - - ">="
205
253
  - !ruby/object:Gem::Version
206
- version: 2.5.0
254
+ version: 3.1.4
207
255
  required_rubygems_version: !ruby/object:Gem::Requirement
208
256
  requirements:
209
257
  - - ">="
210
258
  - !ruby/object:Gem::Version
211
259
  version: '0'
212
260
  requirements: []
213
- rubygems_version: 3.1.6
214
- signing_key:
261
+ rubygems_version: 3.6.4
215
262
  specification_version: 4
216
263
  summary: RGeo is a geospatial data library for Ruby.
217
264
  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