rgeo 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +8 -0
- data/README.rdoc +2 -2
- data/Version +1 -1
- data/lib/rgeo/cartesian/factory.rb +10 -1
- data/lib/rgeo/cartesian/interface.rb +46 -2
- data/lib/rgeo/coord_sys/cs/entities.rb +758 -39
- data/lib/rgeo/coord_sys/cs/factories.rb +82 -12
- data/lib/rgeo/coord_sys/cs/wkt_parser.rb +1 -0
- data/lib/rgeo/coord_sys/srs_database/active_record_table.rb +83 -1
- data/lib/rgeo/coord_sys/srs_database/interface.rb +53 -0
- data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +60 -15
- data/lib/rgeo/coord_sys/srs_database/sr_org.rb +20 -0
- data/lib/rgeo/coord_sys/srs_database/url_reader.rb +18 -0
- data/lib/rgeo/feature/factory_generator.rb +17 -4
- data/lib/rgeo/geographic/factory.rb +5 -1
- data/lib/rgeo/geographic/interface.rb +205 -71
- data/lib/rgeo/geographic/proj4_projector.rb +1 -1
- data/lib/rgeo/geographic/simple_mercator_projector.rb +17 -1
- data/lib/rgeo/geos/factory.rb +10 -1
- data/lib/rgeo/geos/interface.rb +26 -0
- data/lib/rgeo/geos/zm_factory.rb +18 -2
- data/test/coord_sys/tc_active_record_table.rb +8 -3
- metadata +3 -3
@@ -44,18 +44,36 @@ module RGeo
|
|
44
44
|
module SRSDatabase
|
45
45
|
|
46
46
|
|
47
|
+
# A spatial reference database implementation that fetches data
|
48
|
+
# from the spatialreference.org website.
|
49
|
+
|
47
50
|
class SrOrg
|
48
51
|
|
49
52
|
|
53
|
+
# Create a database backed by the given catalog of the
|
54
|
+
# spatialreference.org website. Catalogs currently supported by
|
55
|
+
# spatialreference.org are "epsg", "esri", "iau2000" and "sr-org".
|
56
|
+
#
|
57
|
+
# Options:
|
58
|
+
#
|
59
|
+
# <tt>:cache</tt>::
|
60
|
+
# If set to true, lookup results are cached so if the same URL
|
61
|
+
# is requested again, the result is served from cache rather
|
62
|
+
# than issuing another HTTP request. Default is false.
|
63
|
+
|
50
64
|
def initialize(catalog_, opts_={})
|
51
65
|
@catalog = catalog_.to_s.downcase
|
52
66
|
@cache = opts_[:cache] ? {} : nil
|
53
67
|
end
|
54
68
|
|
55
69
|
|
70
|
+
# The spatialreference.org catalog used by this database.
|
56
71
|
attr_reader :catalog
|
57
72
|
|
58
73
|
|
74
|
+
# Retrieve the Entry from a spatialreference.org catalog given an
|
75
|
+
# integer ID.
|
76
|
+
|
59
77
|
def get(ident_)
|
60
78
|
ident_ = ident_.to_s
|
61
79
|
return @cache[ident_] if @cache && @cache.include?(ident_)
|
@@ -73,6 +91,8 @@ module RGeo
|
|
73
91
|
end
|
74
92
|
|
75
93
|
|
94
|
+
# Clear the cache if one exists.
|
95
|
+
|
76
96
|
def clear_cache
|
77
97
|
@cache.clear if @cache
|
78
98
|
end
|
@@ -44,14 +44,30 @@ module RGeo
|
|
44
44
|
module SRSDatabase
|
45
45
|
|
46
46
|
|
47
|
+
# A spatial reference database implementation that fetches data from
|
48
|
+
# internet URLs.
|
49
|
+
|
47
50
|
class UrlReader
|
48
51
|
|
49
52
|
|
53
|
+
# Create a URL-based spatial reference database.
|
54
|
+
#
|
55
|
+
# Options:
|
56
|
+
#
|
57
|
+
# <tt>:cache</tt>::
|
58
|
+
# If set to true, lookup results are cached so if the same URL
|
59
|
+
# is requested again, the result is served from cache rather
|
60
|
+
# than issuing another HTTP request. Default is false.
|
61
|
+
|
50
62
|
def initialize(opts_={})
|
51
63
|
@cache = opts_[:cache] ? {} : nil
|
52
64
|
end
|
53
65
|
|
54
66
|
|
67
|
+
# Retrieve the given URL and return an Entry.
|
68
|
+
# Returns nil if the URL cannot be read as an OGC WKT or Proj4
|
69
|
+
# coordinate system
|
70
|
+
|
55
71
|
def get(ident_)
|
56
72
|
ident_ = ident_.to_s
|
57
73
|
return @cache[ident_] if @cache && @cache.include?(ident_)
|
@@ -75,6 +91,8 @@ module RGeo
|
|
75
91
|
end
|
76
92
|
|
77
93
|
|
94
|
+
# Clear the cache if one is present.
|
95
|
+
|
78
96
|
def clear_cache
|
79
97
|
@cache.clear if @cache
|
80
98
|
end
|
@@ -46,8 +46,8 @@ module RGeo
|
|
46
46
|
#
|
47
47
|
# See the call method for a list of common configuration parameters.
|
48
48
|
# Different generators will support different parameters. There is
|
49
|
-
# no mechanism defined to reflect on the
|
50
|
-
# generator.
|
49
|
+
# no mechanism defined to reflect on the parameters understood by a
|
50
|
+
# factory generator.
|
51
51
|
#
|
52
52
|
# Many of the implementations provide a factory method for creating
|
53
53
|
# factories. For example, RGeo::Cartesian::preferred_factory can be
|
@@ -71,8 +71,8 @@ module RGeo
|
|
71
71
|
# If the generator does not recognize or does not support a given
|
72
72
|
# configuration value, the behavior is usually determined by the
|
73
73
|
# <tt>:strict</tt> configuration element. If <tt>strict</tt> is
|
74
|
-
# set to true, the generator should fail fast
|
75
|
-
#
|
74
|
+
# set to true, the generator should fail fast by returning nil or
|
75
|
+
# raising an exception. If it is set to false, the generator should
|
76
76
|
# attempt to do the best it can, even if it means returning a
|
77
77
|
# factory that does not match the requested configuration.
|
78
78
|
#
|
@@ -89,6 +89,19 @@ module RGeo
|
|
89
89
|
# <tt>:srid</tt>::
|
90
90
|
# The SRID for the factory and objects it creates.
|
91
91
|
# Default is usually 0.
|
92
|
+
# <tt>:proj4</tt>::
|
93
|
+
# The coordinate system in Proj4 format, either as a
|
94
|
+
# CoordSys::Proj4 object or as a string or hash representing the
|
95
|
+
# proj4 format. This is usually an optional parameter; the default
|
96
|
+
# is usually nil.
|
97
|
+
# <tt>:coord_sys</tt>::
|
98
|
+
# The coordinate system in OGC form, either as a subclass of
|
99
|
+
# CoordSys::CS::CoordinateSystem, or as a string in WKT format.
|
100
|
+
# This is usually an optional parameter; the default is usually
|
101
|
+
# nil.
|
102
|
+
# <tt>:srs_database</tt>::
|
103
|
+
# If provided, look up the Proj4 and OGC coordinate systems from
|
104
|
+
# the given database and SRID.
|
92
105
|
# <tt>:has_z_coordinate</tt>::
|
93
106
|
# Support Z coordinates. Default is usually false.
|
94
107
|
# <tt>:has_m_coordinate</tt>::
|
@@ -70,6 +70,10 @@ module RGeo
|
|
70
70
|
else
|
71
71
|
@proj4 = nil
|
72
72
|
end
|
73
|
+
@coord_sys = opts_[:coord_sys]
|
74
|
+
if @coord_sys.kind_of?(::String)
|
75
|
+
@coord_sys = CoordSys::CS.create_from_wkt(@coord_sys) rescue nil
|
76
|
+
end
|
73
77
|
end
|
74
78
|
|
75
79
|
|
@@ -272,7 +276,7 @@ module RGeo
|
|
272
276
|
# See ::RGeo::Feature::Factory#coord_sys
|
273
277
|
|
274
278
|
def coord_sys
|
275
|
-
|
279
|
+
@coord_sys
|
276
280
|
end
|
277
281
|
|
278
282
|
|
@@ -94,15 +94,36 @@ module RGeo
|
|
94
94
|
# "popular visualization CRS" (EPSG 4055), represented by
|
95
95
|
# "<tt>+proj=longlat +a=6378137 +b=6378137 +towgs84=0,0,0,0,0,0,0 +no_defs</tt>".
|
96
96
|
# Has no effect if Proj4 is not available.
|
97
|
+
# <tt>:coord_sys</tt>::
|
98
|
+
# Provide a coordinate system in OGC format, either as an object
|
99
|
+
# (one of the CoordSys::CS classes) or as a string in WKT format.
|
100
|
+
# This coordinate system must be a GeographicCoordinateSystem.
|
101
|
+
# The default is the "popular visualization CRS" (EPSG 4055).
|
97
102
|
# <tt>:srid</tt>::
|
98
103
|
# The SRID that should be returned by features from this factory.
|
99
104
|
# Default is 4055, indicating EPSG 4055, the "popular
|
100
105
|
# visualization crs". You may alternatively wish to set the srid
|
101
106
|
# to 4326, indicating the WGS84 crs, but note that that value
|
102
107
|
# implies an ellipsoidal datum, not a spherical datum.
|
108
|
+
# <tt>:srs_database</tt>::
|
109
|
+
# Optional. If provided, the value should be an implementation of
|
110
|
+
# CoordSys::SRSDatabase::Interface. If both this and an SRID are
|
111
|
+
# provided, they are used to look up the proj4 and coord_sys
|
112
|
+
# objects from a spatial reference system database.
|
103
113
|
|
104
114
|
def spherical_factory(opts_={})
|
105
|
-
|
115
|
+
proj4_ = opts_[:proj4]
|
116
|
+
coord_sys_ = opts_[:coord_sys]
|
117
|
+
srid_ = opts_[:srid]
|
118
|
+
if (!proj4_ || !coord_sys_) && srid_ && (db_ = opts_[:srs_database])
|
119
|
+
entry_ = db_.get(srid_.to_i)
|
120
|
+
if entry_
|
121
|
+
proj4_ ||= entry_.proj4
|
122
|
+
coord_sys_ ||= entry_.coord_sys
|
123
|
+
end
|
124
|
+
end
|
125
|
+
srid_ ||= coord_sys_.authority_code if coord_sys_
|
126
|
+
Geographic::Factory.new('Spherical', :has_z_coordinate => opts_[:has_z_coordinate], :has_m_coordinate => opts_[:has_m_coordinate], :proj4 => proj4_ || _proj4_4055, :coord_sys => coord_sys_ || _coordsys_4055, :srid => (srid_ || 4055).to_i)
|
106
127
|
end
|
107
128
|
|
108
129
|
|
@@ -119,10 +140,10 @@ module RGeo
|
|
119
140
|
# units.
|
120
141
|
#
|
121
142
|
# The behavior of the simple_mercator factory could also be obtained
|
122
|
-
# using a
|
123
|
-
# the simple_mercator implementation is done without
|
124
|
-
# requiring the Proj4 library. The projections are simple
|
125
|
-
# be implemented in pure ruby.
|
143
|
+
# using a projected_factory with appropriate Proj4 specifications.
|
144
|
+
# However, the simple_mercator implementation is done without
|
145
|
+
# actually requiring the Proj4 library. The projections are simple
|
146
|
+
# enough to be implemented in pure ruby.
|
126
147
|
#
|
127
148
|
# === About the coordinate system
|
128
149
|
#
|
@@ -133,12 +154,12 @@ module RGeo
|
|
133
154
|
# technologies utilize this coordinate system. The second is a
|
134
155
|
# Mercator projection based on a "sphericalization" of the WGS84
|
135
156
|
# lat-long system. This projection is the basis of the map's screen
|
136
|
-
# and tiling coordinates, and has been assigned EPSG
|
157
|
+
# and tiling coordinates, and has been assigned EPSG 3785.
|
137
158
|
#
|
138
159
|
# This factory represents both coordinate systems. The main factory
|
139
160
|
# produces data in the lat-long system and reports SRID 4326, and
|
140
161
|
# the projected factory produces data in the projection and reports
|
141
|
-
# SRID
|
162
|
+
# SRID 3785. Latitudes are restricted to the range
|
142
163
|
# (-85.05112877980659, 85.05112877980659), which conveniently
|
143
164
|
# results in a square projected domain.
|
144
165
|
#
|
@@ -147,27 +168,20 @@ module RGeo
|
|
147
168
|
# You may use the following options when creating a simple_mercator
|
148
169
|
# factory:
|
149
170
|
#
|
150
|
-
# <tt>:lenient_multi_polygon_assertions</tt>::
|
151
|
-
# If set to true, assertion checking on MultiPolygon is disabled.
|
152
|
-
# This may speed up creation of MultiPolygon objects, at the
|
153
|
-
# expense of not doing the proper checking for OGC MultiPolygon
|
154
|
-
# compliance. See RGeo::Feature::MultiPolygon for details on
|
155
|
-
# the MultiPolygon assertions. Default is false.
|
156
|
-
# <tt>:buffer_resolution</tt>::
|
157
|
-
# The resolution of buffers around geometries created by this
|
158
|
-
# factory. This controls the number of line segments used to
|
159
|
-
# approximate curves. The default is 1, which causes, for
|
160
|
-
# example, the buffer around a point to be approximated by a
|
161
|
-
# 4-sided polygon. A resolution of 2 would cause that buffer
|
162
|
-
# to be approximated by an 8-sided polygon. The exact behavior
|
163
|
-
# for different kinds of buffers is defined by GEOS.
|
164
171
|
# <tt>:has_z_coordinate</tt>::
|
165
172
|
# Support a Z coordinate. Default is false.
|
166
173
|
# <tt>:has_m_coordinate</tt>::
|
167
174
|
# Support an M coordinate. Default is false.
|
175
|
+
#
|
176
|
+
# You may also provide options understood by the underlying
|
177
|
+
# projected Cartesian factory. For example, if GEOS is used for the
|
178
|
+
# projected factory, you may also set the
|
179
|
+
# <tt>:lenient_multi_polygon_assertions</tt> and
|
180
|
+
# <tt>:buffer_resolution</tt> options. See RGeo::Geos::factory for
|
181
|
+
# more details.
|
168
182
|
|
169
183
|
def simple_mercator_factory(opts_={})
|
170
|
-
factory_ = Geographic::Factory.new('Projected', :proj4 =>
|
184
|
+
factory_ = Geographic::Factory.new('Projected', :proj4 => _proj4_4326, :coord_sys => _coordsys_4326, :srid => 4326, :has_z_coordinate => opts_[:has_z_coordinate], :has_m_coordinate => opts_[:has_m_coordinate])
|
171
185
|
projector_ = Geographic::SimpleMercatorProjector.new(factory_, :buffer_resolution => opts_[:buffer_resolution], :lenient_multi_polygon_assertions => opts_[:lenient_multi_polygon_assertions], :has_z_coordinate => opts_[:has_z_coordinate], :has_m_coordinate => opts_[:has_m_coordinate])
|
172
186
|
factory_._set_projector(projector_)
|
173
187
|
factory_
|
@@ -179,78 +193,147 @@ module RGeo
|
|
179
193
|
# geographic factories, this one creates features using latitude-
|
180
194
|
# longitude values. However, calculations such as intersections are
|
181
195
|
# done in the projected coordinate system, and size and distance
|
182
|
-
# calculations report results in the projected units.
|
196
|
+
# calculations report results in the projected units. Thus, this
|
197
|
+
# factory actually includes two factories representing different
|
198
|
+
# coordinate systems: the main factory representing the geographic
|
199
|
+
# lat-long coordinate system, and an auxiliary "projection factory"
|
200
|
+
# representing the projected coordinate system.
|
183
201
|
#
|
184
202
|
# This implementation is intended for advanced GIS applications
|
185
203
|
# requiring greater control over the projection being used.
|
186
204
|
#
|
187
205
|
# === Options
|
188
206
|
#
|
189
|
-
# When creating a projected implementation, you must provide
|
190
|
-
#
|
191
|
-
#
|
192
|
-
# <tt>:
|
193
|
-
#
|
207
|
+
# When creating a projected implementation, you must provide enough
|
208
|
+
# information to construct a Proj4 specification for the projection.
|
209
|
+
# Generally, this means you will provide either the projection's
|
210
|
+
# factory itself (via the <tt>:projection_factory</tt> option), in
|
211
|
+
# which case the factory must include a Proj4 coordinate system;
|
212
|
+
# or, alternatively, you should provide the Proj4 coordinate system
|
213
|
+
# and let this method construct a projection factory for you (which
|
214
|
+
# it will do using the preferred Cartesian factory generator).
|
215
|
+
# If you choose this second method, you may provide the proj4
|
216
|
+
# directly via the <tt>:projection_proj4</tt> option, or indirectly
|
217
|
+
# by providing both an <tt>:srid</tt> and a <tt>:srs_database</tt>
|
218
|
+
# to use to look up the coordinate system.
|
194
219
|
#
|
195
|
-
#
|
196
|
-
#
|
220
|
+
# Following are detailed descriptions of the various options you can
|
221
|
+
# pass to this method.
|
197
222
|
#
|
198
223
|
# <tt>:projection_factory</tt>::
|
199
224
|
# Specify an existing Cartesian factory to use for the projection.
|
200
|
-
# This factory must have a non-nil Proj4.
|
201
|
-
#
|
202
|
-
#
|
203
|
-
# m-coordinate availability will be set to match the projection's
|
204
|
-
# z-coordinate and m-coordinate availability.
|
205
|
-
#
|
206
|
-
# If you provide <tt>:projection_proj4</tt>, the following options
|
207
|
-
# are supported.
|
208
|
-
#
|
225
|
+
# This factory must have a non-nil Proj4. If this is provided, any
|
226
|
+
# <tt>:projection_proj4</tt>, <tt>:projection_coord_sys</tt>, and
|
227
|
+
# <tt>:projection_srid</tt> are ignored.
|
209
228
|
# <tt>:projection_proj4</tt>::
|
210
|
-
# Specify a Proj4 projection to use
|
211
|
-
#
|
212
|
-
# representation.
|
229
|
+
# Specify a Proj4 projection to use to construct the projection
|
230
|
+
# factory. This may be specified as a CoordSys::Proj4 object, or
|
231
|
+
# as a Proj4 string or hash representation.
|
232
|
+
# <tt>:projection_coord_sys</tt>::
|
233
|
+
# Specify a OGC coordinate system for the projection. This may be
|
234
|
+
# specified as an RGeo::CoordSys::CS::GeographicCoordinateSystem
|
235
|
+
# object, or as a String in OGC WKT format. Optional.
|
213
236
|
# <tt>:projection_srid</tt>::
|
214
|
-
#
|
215
|
-
#
|
216
|
-
#
|
217
|
-
#
|
218
|
-
#
|
219
|
-
#
|
220
|
-
# the
|
221
|
-
#
|
222
|
-
#
|
223
|
-
#
|
224
|
-
#
|
225
|
-
#
|
226
|
-
#
|
227
|
-
#
|
228
|
-
#
|
237
|
+
# The SRID value to use for the projection factory. Defaults to
|
238
|
+
# the given projection coordinate system's authority code, or to
|
239
|
+
# 0 if no projection coordinate system is known.
|
240
|
+
# <tt>:proj4</tt>::
|
241
|
+
# A proj4 projection for the geographic (lat-lon) factory. You may
|
242
|
+
# pass either an RGeo::CoordSys::Proj4 object, or a string or hash
|
243
|
+
# containing the Proj4 parameters. This coordinate system must be
|
244
|
+
# a geographic (lat/long) coordinate system. It defaults to the
|
245
|
+
# geographic part of the projection factory's coordinate system.
|
246
|
+
# Generally, you should leave it at the default unless you want
|
247
|
+
# the geographic coordinate system to be based on a different
|
248
|
+
# horizontal datum than the projection.
|
249
|
+
# <tt>:coord_sys</tt>::
|
250
|
+
# An OGC coordinate system for the geographic (lat-lon) factory,
|
251
|
+
# which may be an RGeo::CoordSys::CS::GeographicCoordinateSystem
|
252
|
+
# object or a string in OGC WKT format. It defaults to the
|
253
|
+
# geographic system embedded in the projection coordinate system.
|
254
|
+
# Generally, you should leave it at the default unless you want
|
255
|
+
# the geographic coordinate system to be based on a different
|
256
|
+
# horizontal datum than the projection.
|
257
|
+
# <tt>:srid</tt>::
|
258
|
+
# The SRID value to use for the main geographic factory. Defaults
|
259
|
+
# to the given geographic coordinate system's authority code, or
|
260
|
+
# to 0 if no geographic coordinate system is known.
|
261
|
+
# <tt>:srs_database</tt>::
|
262
|
+
# Optional. If provided, the value should be an implementation of
|
263
|
+
# CoordSys::SRSDatabase::Interface. If both this and an SRID are
|
264
|
+
# provided, they are used to look up the proj4 and coord_sys
|
265
|
+
# objects from a spatial reference system database.
|
229
266
|
# <tt>:has_z_coordinate</tt>::
|
230
267
|
# Support a Z coordinate. Default is false.
|
268
|
+
# Note: this is ignored if a <tt>:projection_factory</tt> is
|
269
|
+
# provided; in that case, the geographic factory's z-coordinate
|
270
|
+
# availability will match the projection factory's setting.
|
231
271
|
# <tt>:has_m_coordinate</tt>::
|
232
272
|
# Support an M coordinate. Default is false.
|
273
|
+
# Note: this is ignored if a <tt>:projection_factory</tt> is
|
274
|
+
# provided; in that case, the geographic factory's m-coordinate
|
275
|
+
# availability will match the projection factory's setting.
|
233
276
|
#
|
234
|
-
#
|
235
|
-
#
|
236
|
-
#
|
237
|
-
#
|
238
|
-
#
|
239
|
-
#
|
277
|
+
# If a <tt>:projection_factory</tt> is _not_ provided, you may also
|
278
|
+
# provide options for configuring the projected Cartesian factory.
|
279
|
+
# For example, if GEOS is used for the projected factory, you may
|
280
|
+
# also set the <tt>:lenient_multi_polygon_assertions</tt> and
|
281
|
+
# <tt>:buffer_resolution</tt> options. See RGeo::Geos::factory for
|
282
|
+
# more details.
|
240
283
|
|
241
284
|
def projected_factory(opts_={})
|
242
285
|
unless CoordSys::Proj4.supported?
|
243
286
|
raise Error::UnsupportedOperation, "Proj4 is not supported because the proj4 library was not found at install time."
|
244
287
|
end
|
288
|
+
db_ = opts_[:srs_database]
|
245
289
|
if (projection_factory_ = opts_[:projection_factory])
|
290
|
+
# Get the projection coordinate systems from the given factory
|
246
291
|
projection_proj4_ = projection_factory_.proj4
|
247
292
|
unless projection_proj4_
|
248
293
|
raise ::ArgumentError, 'The :projection_factory does not have a proj4.'
|
249
294
|
end
|
250
|
-
|
251
|
-
|
295
|
+
projection_coord_sys_ = projection_factory_.coord_sys
|
296
|
+
if projection_coord_sys_ && !projection_coord_sys_.kind_of?(CoordSys::CS::ProjectedCoordinateSystem)
|
297
|
+
raise ::ArgumentError, 'The :projection_factory\'s coord_sys is not a ProjectedCoordinateSystem.'
|
298
|
+
end
|
299
|
+
# Determine geographic coordinate system. First check parameters.
|
300
|
+
proj4_ = opts_[:proj4]
|
301
|
+
coord_sys_ = opts_[:coord_sys]
|
302
|
+
srid_ = opts_[:srid]
|
303
|
+
# Lookup srid from srs database if needed
|
304
|
+
if (!proj4_ || !coord_sys_) && srid_ && db_
|
305
|
+
entry_ = db_.get(srid_.to_i)
|
306
|
+
if entry_
|
307
|
+
proj4_ ||= entry_.proj4
|
308
|
+
coord_sys_ ||= entry_.coord_sys
|
309
|
+
end
|
310
|
+
end
|
311
|
+
# Fall back to getting the values from the projection.
|
312
|
+
proj4_ ||= projection_proj4_.get_geographic || _proj4_4326
|
313
|
+
coord_sys_ ||= projection_coord_sys_.geographic_coordinate_system if projection_coord_sys_
|
314
|
+
srid_ ||= coord_sys_.authority_code if coord_sys_
|
315
|
+
srid_ ||= 4326
|
316
|
+
# Now we should have all the coordinate system info.
|
317
|
+
factory_ = Geographic::Factory.new('Projected', :proj4 => proj4_, :coord_sys => coord_sys_, :srid => srid_.to_i, :has_z_coordinate => projection_factory_.property(:has_z_coordinate), :has_m_coordinate => projection_factory_.property(:has_m_coordinate))
|
252
318
|
projector_ = Geographic::Proj4Projector.create_from_existing_factory(factory_, projection_factory_)
|
253
|
-
|
319
|
+
else
|
320
|
+
# Determine projection coordinate system. First check the parameters.
|
321
|
+
projection_proj4_ = opts_[:projection_proj4]
|
322
|
+
projection_coord_sys_ = opts_[:projection_coord_sys]
|
323
|
+
projection_srid_ = opts_[:projection_srid]
|
324
|
+
# Check the case where we need to look up a srid from an srs database.
|
325
|
+
if (!projection_proj4_ || !projection_coord_sys_) && projection_srid_ && db_
|
326
|
+
entry_ = db_.get(projection_srid_.to_i)
|
327
|
+
if entry_
|
328
|
+
projection_proj4_ ||= entry_.proj4
|
329
|
+
projection_coord_sys_ ||= entry_.coord_sys
|
330
|
+
end
|
331
|
+
end
|
332
|
+
# A projection proj4 is absolutely required.
|
333
|
+
unless projection_proj4_
|
334
|
+
raise ::ArgumentError, 'Unable to determine the Proj4 for the projected coordinate system.'
|
335
|
+
end
|
336
|
+
# Check the projection coordinate systems, and parse if needed.
|
254
337
|
if projection_proj4_.kind_of?(::String) || projection_proj4_.kind_of?(::Hash)
|
255
338
|
actual_projection_proj4_ = CoordSys::Proj4.create(projection_proj4_)
|
256
339
|
unless actual_projection_proj4_
|
@@ -258,17 +341,68 @@ module RGeo
|
|
258
341
|
end
|
259
342
|
projection_proj4_ = actual_projection_proj4_
|
260
343
|
end
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
344
|
+
if projection_coord_sys_ && !projection_coord_sys_.kind_of?(CoordSys::CS::ProjectedCoordinateSystem)
|
345
|
+
raise ::ArgumentError, 'The :projection_coord_sys is not a ProjectedCoordinateSystem.'
|
346
|
+
end
|
347
|
+
projection_srid_ ||= projection_coord_sys_.authority_code if projection_coord_sys_
|
348
|
+
# Determine geographic coordinate system. First check parameters.
|
349
|
+
proj4_ = opts_[:proj4]
|
350
|
+
coord_sys_ = opts_[:coord_sys]
|
351
|
+
srid_ = opts_[:srid]
|
352
|
+
# Lookup srid from srs database if needed
|
353
|
+
if (!proj4_ || !coord_sys_) && srid_ && db_
|
354
|
+
entry_ = db_.get(srid_.to_i)
|
355
|
+
if entry_
|
356
|
+
proj4_ ||= entry_.proj4
|
357
|
+
coord_sys_ ||= entry_.coord_sys
|
358
|
+
end
|
359
|
+
end
|
360
|
+
# Fall back to getting the values from the projection.
|
361
|
+
proj4_ ||= projection_proj4_.get_geographic || _proj4_4326
|
362
|
+
coord_sys_ ||= projection_coord_sys_.geographic_coordinate_system if projection_coord_sys_
|
363
|
+
srid_ ||= coord_sys_.authority_code if coord_sys_
|
364
|
+
srid_ ||= 4326
|
365
|
+
# Now we should have all the coordinate system info.
|
366
|
+
factory_ = Geographic::Factory.new('Projected', :proj4 => proj4_, :coord_sys => coord_sys_, :srid => srid_.to_i, :has_z_coordinate => opts_[:has_z_coordinate], :has_m_coordinate => opts_[:has_m_coordinate])
|
367
|
+
projector_ = Geographic::Proj4Projector.create_from_proj4(factory_, projection_proj4_, :srid => projection_srid_, :coord_sys => projection_coord_sys_, :buffer_resolution => opts_[:buffer_resolution], :lenient_multi_polygon_assertions => opts_[:lenient_multi_polygon_assertions], :has_z_coordinate => opts_[:has_z_coordinate], :has_m_coordinate => opts_[:has_m_coordinate])
|
266
368
|
end
|
267
369
|
factory_._set_projector(projector_)
|
268
370
|
factory_
|
269
371
|
end
|
270
372
|
|
271
373
|
|
374
|
+
def _proj4_4055 # :nodoc:
|
375
|
+
unless defined?(@proj4_4055)
|
376
|
+
@proj4_4055 = CoordSys::Proj4.create('+proj=longlat +a=6378137 +b=6378137 +towgs84=0,0,0,0,0,0,0 +no_defs')
|
377
|
+
end
|
378
|
+
@proj4_4055
|
379
|
+
end
|
380
|
+
|
381
|
+
|
382
|
+
def _coordsys_4055 # :nodoc:
|
383
|
+
unless defined?(@coordsys_4055)
|
384
|
+
@coordsys_4055 = CoordSys::CS.create_from_wkt('GEOGCS["Popular Visualisation CRS",DATUM["Popular_Visualisation_Datum",SPHEROID["Popular Visualisation Sphere",6378137,0,AUTHORITY["EPSG","7059"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6055"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4055"]]')
|
385
|
+
end
|
386
|
+
@coordsys_4055
|
387
|
+
end
|
388
|
+
|
389
|
+
|
390
|
+
def _proj4_4326 # :nodoc:
|
391
|
+
unless defined?(@proj4_4326)
|
392
|
+
@proj4_4326 = CoordSys::Proj4.create('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')
|
393
|
+
end
|
394
|
+
@proj4_4326
|
395
|
+
end
|
396
|
+
|
397
|
+
|
398
|
+
def _coordsys_4326 # :nodoc:
|
399
|
+
unless defined?(@coordsys_4326)
|
400
|
+
@coordsys_4326 = CoordSys::CS.create_from_wkt('GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]')
|
401
|
+
end
|
402
|
+
@coordsys_4326
|
403
|
+
end
|
404
|
+
|
405
|
+
|
272
406
|
end
|
273
407
|
|
274
408
|
end
|