rgeo-dschee 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +29 -0
- data/ext/geos_c_impl/coordinates.c +65 -0
- data/ext/geos_c_impl/coordinates.h +2 -0
- data/ext/geos_c_impl/extconf.rb +43 -0
- data/ext/geos_c_impl/factory.c +995 -0
- data/ext/geos_c_impl/factory.h +238 -0
- data/ext/geos_c_impl/geometry.c +1093 -0
- data/ext/geos_c_impl/geometry.h +23 -0
- data/ext/geos_c_impl/geometry_collection.c +757 -0
- data/ext/geos_c_impl/geometry_collection.h +46 -0
- data/ext/geos_c_impl/line_string.c +675 -0
- data/ext/geos_c_impl/line_string.h +32 -0
- data/ext/geos_c_impl/main.c +40 -0
- data/ext/geos_c_impl/point.c +236 -0
- data/ext/geos_c_impl/point.h +30 -0
- data/ext/geos_c_impl/polygon.c +359 -0
- data/ext/geos_c_impl/polygon.h +43 -0
- data/ext/geos_c_impl/preface.h +38 -0
- data/ext/proj4_c_impl/extconf.rb +62 -0
- data/ext/proj4_c_impl/main.c +315 -0
- data/lib/rgeo.rb +89 -0
- data/lib/rgeo/cartesian.rb +25 -0
- data/lib/rgeo/cartesian/analysis.rb +77 -0
- data/lib/rgeo/cartesian/bounding_box.rb +398 -0
- data/lib/rgeo/cartesian/calculations.rb +113 -0
- data/lib/rgeo/cartesian/factory.rb +347 -0
- data/lib/rgeo/cartesian/feature_classes.rb +100 -0
- data/lib/rgeo/cartesian/feature_methods.rb +88 -0
- data/lib/rgeo/cartesian/interface.rb +135 -0
- data/lib/rgeo/coord_sys.rb +43 -0
- data/lib/rgeo/coord_sys/cs/entities.rb +1315 -0
- data/lib/rgeo/coord_sys/cs/factories.rb +148 -0
- data/lib/rgeo/coord_sys/cs/wkt_parser.rb +272 -0
- data/lib/rgeo/coord_sys/proj4.rb +293 -0
- data/lib/rgeo/coord_sys/srs_database/interface.rb +115 -0
- data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +140 -0
- data/lib/rgeo/coord_sys/srs_database/sr_org.rb +62 -0
- data/lib/rgeo/coord_sys/srs_database/url_reader.rb +63 -0
- data/lib/rgeo/error.rb +27 -0
- data/lib/rgeo/feature.rb +54 -0
- data/lib/rgeo/feature/curve.rb +111 -0
- data/lib/rgeo/feature/factory.rb +278 -0
- data/lib/rgeo/feature/factory_generator.rb +96 -0
- data/lib/rgeo/feature/geometry.rb +624 -0
- data/lib/rgeo/feature/geometry_collection.rb +95 -0
- data/lib/rgeo/feature/line.rb +26 -0
- data/lib/rgeo/feature/line_string.rb +60 -0
- data/lib/rgeo/feature/linear_ring.rb +26 -0
- data/lib/rgeo/feature/mixins.rb +143 -0
- data/lib/rgeo/feature/multi_curve.rb +71 -0
- data/lib/rgeo/feature/multi_line_string.rb +26 -0
- data/lib/rgeo/feature/multi_point.rb +33 -0
- data/lib/rgeo/feature/multi_polygon.rb +57 -0
- data/lib/rgeo/feature/multi_surface.rb +73 -0
- data/lib/rgeo/feature/point.rb +84 -0
- data/lib/rgeo/feature/polygon.rb +97 -0
- data/lib/rgeo/feature/surface.rb +79 -0
- data/lib/rgeo/feature/types.rb +284 -0
- data/lib/rgeo/geographic.rb +40 -0
- data/lib/rgeo/geographic/factory.rb +450 -0
- data/lib/rgeo/geographic/interface.rb +489 -0
- data/lib/rgeo/geographic/proj4_projector.rb +58 -0
- data/lib/rgeo/geographic/projected_feature_classes.rb +107 -0
- data/lib/rgeo/geographic/projected_feature_methods.rb +212 -0
- data/lib/rgeo/geographic/projected_window.rb +383 -0
- data/lib/rgeo/geographic/simple_mercator_projector.rb +110 -0
- data/lib/rgeo/geographic/spherical_feature_classes.rb +100 -0
- data/lib/rgeo/geographic/spherical_feature_methods.rb +134 -0
- data/lib/rgeo/geographic/spherical_math.rb +188 -0
- data/lib/rgeo/geos.rb +89 -0
- data/lib/rgeo/geos/capi_factory.rb +470 -0
- data/lib/rgeo/geos/capi_feature_classes.rb +129 -0
- data/lib/rgeo/geos/ffi_factory.rb +592 -0
- data/lib/rgeo/geos/ffi_feature_classes.rb +83 -0
- data/lib/rgeo/geos/ffi_feature_methods.rb +574 -0
- data/lib/rgeo/geos/interface.rb +202 -0
- data/lib/rgeo/geos/utils.rb +74 -0
- data/lib/rgeo/geos/zm_factory.rb +405 -0
- data/lib/rgeo/geos/zm_feature_classes.rb +80 -0
- data/lib/rgeo/geos/zm_feature_methods.rb +344 -0
- data/lib/rgeo/impl_helper.rb +19 -0
- data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +185 -0
- data/lib/rgeo/impl_helper/basic_geometry_methods.rb +61 -0
- data/lib/rgeo/impl_helper/basic_line_string_methods.rb +146 -0
- data/lib/rgeo/impl_helper/basic_point_methods.rb +104 -0
- data/lib/rgeo/impl_helper/basic_polygon_methods.rb +87 -0
- data/lib/rgeo/impl_helper/math.rb +14 -0
- data/lib/rgeo/impl_helper/utils.rb +29 -0
- data/lib/rgeo/version.rb +3 -0
- data/lib/rgeo/wkrep.rb +37 -0
- data/lib/rgeo/wkrep/wkb_generator.rb +201 -0
- data/lib/rgeo/wkrep/wkb_parser.rb +251 -0
- data/lib/rgeo/wkrep/wkt_generator.rb +207 -0
- data/lib/rgeo/wkrep/wkt_parser.rb +415 -0
- data/lib/rgeo/yaml.rb +23 -0
- data/test/cartesian_analysis_test.rb +65 -0
- data/test/cartesian_bbox_test.rb +123 -0
- data/test/common/factory_tests.rb +78 -0
- data/test/common/geometry_collection_tests.rb +237 -0
- data/test/common/line_string_tests.rb +330 -0
- data/test/common/multi_line_string_tests.rb +182 -0
- data/test/common/multi_point_tests.rb +200 -0
- data/test/common/multi_polygon_tests.rb +191 -0
- data/test/common/point_tests.rb +370 -0
- data/test/common/polygon_tests.rb +261 -0
- data/test/coord_sys/ogc_cs_test.rb +342 -0
- data/test/coord_sys/proj4_srs_data_test.rb +41 -0
- data/test/coord_sys/proj4_test.rb +150 -0
- data/test/coord_sys/sr_org_test.rb +32 -0
- data/test/coord_sys/url_reader_test.rb +42 -0
- data/test/geos_capi/factory_test.rb +31 -0
- data/test/geos_capi/geometry_collection_test.rb +24 -0
- data/test/geos_capi/line_string_test.rb +24 -0
- data/test/geos_capi/misc_test.rb +116 -0
- data/test/geos_capi/multi_line_string_test.rb +24 -0
- data/test/geos_capi/multi_point_test.rb +24 -0
- data/test/geos_capi/multi_polygon_test.rb +39 -0
- data/test/geos_capi/parsing_unparsing_test.rb +40 -0
- data/test/geos_capi/point_test.rb +72 -0
- data/test/geos_capi/polygon_test.rb +154 -0
- data/test/geos_capi/zmfactory_test.rb +57 -0
- data/test/geos_ffi/factory_test.rb +31 -0
- data/test/geos_ffi/geometry_collection_test.rb +24 -0
- data/test/geos_ffi/line_string_test.rb +24 -0
- data/test/geos_ffi/misc_test.rb +63 -0
- data/test/geos_ffi/multi_line_string_test.rb +24 -0
- data/test/geos_ffi/multi_point_test.rb +24 -0
- data/test/geos_ffi/multi_polygon_test.rb +33 -0
- data/test/geos_ffi/parsing_unparsing_test.rb +41 -0
- data/test/geos_ffi/point_test.rb +77 -0
- data/test/geos_ffi/polygon_test.rb +46 -0
- data/test/geos_ffi/zmfactory_test.rb +58 -0
- data/test/mixins_test.rb +141 -0
- data/test/oneoff_test.rb +26 -0
- data/test/projected_geographic/factory_test.rb +25 -0
- data/test/projected_geographic/geometry_collection_test.rb +24 -0
- data/test/projected_geographic/line_string_test.rb +24 -0
- data/test/projected_geographic/multi_line_string_test.rb +26 -0
- data/test/projected_geographic/multi_point_test.rb +30 -0
- data/test/projected_geographic/multi_polygon_test.rb +25 -0
- data/test/projected_geographic/point_test.rb +51 -0
- data/test/projected_geographic/polygon_test.rb +24 -0
- data/test/simple_cartesian/calculations_test.rb +99 -0
- data/test/simple_cartesian/factory_test.rb +27 -0
- data/test/simple_cartesian/geometry_collection_test.rb +30 -0
- data/test/simple_cartesian/line_string_test.rb +31 -0
- data/test/simple_cartesian/multi_line_string_test.rb +28 -0
- data/test/simple_cartesian/multi_point_test.rb +31 -0
- data/test/simple_cartesian/multi_polygon_test.rb +31 -0
- data/test/simple_cartesian/point_test.rb +50 -0
- data/test/simple_cartesian/polygon_test.rb +28 -0
- data/test/simple_mercator/factory_test.rb +25 -0
- data/test/simple_mercator/geometry_collection_test.rb +24 -0
- data/test/simple_mercator/line_string_test.rb +24 -0
- data/test/simple_mercator/multi_line_string_test.rb +26 -0
- data/test/simple_mercator/multi_point_test.rb +29 -0
- data/test/simple_mercator/multi_polygon_test.rb +25 -0
- data/test/simple_mercator/point_test.rb +55 -0
- data/test/simple_mercator/polygon_test.rb +24 -0
- data/test/simple_mercator/window_test.rb +173 -0
- data/test/spherical_geographic/calculations_test.rb +167 -0
- data/test/spherical_geographic/factory_test.rb +27 -0
- data/test/spherical_geographic/geometry_collection_test.rb +31 -0
- data/test/spherical_geographic/line_string_test.rb +31 -0
- data/test/spherical_geographic/multi_line_string_test.rb +29 -0
- data/test/spherical_geographic/multi_point_test.rb +31 -0
- data/test/spherical_geographic/multi_polygon_test.rb +31 -0
- data/test/spherical_geographic/point_test.rb +78 -0
- data/test/spherical_geographic/polygon_test.rb +28 -0
- data/test/types_test.rb +42 -0
- data/test/wkrep/wkb_generator_test.rb +185 -0
- data/test/wkrep/wkb_parser_test.rb +293 -0
- data/test/wkrep/wkt_generator_test.rb +294 -0
- data/test/wkrep/wkt_parser_test.rb +412 -0
- metadata +386 -0
@@ -0,0 +1,489 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Access to geographic data factories
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
module RGeo
|
8
|
+
module Geographic
|
9
|
+
class << self
|
10
|
+
# Creates and returns a geographic factory that does not include a
|
11
|
+
# a projection, and which performs calculations assuming a
|
12
|
+
# spherical earth. In other words, geodesics are treated as great
|
13
|
+
# circle arcs, and geometric calculations are handled accordingly.
|
14
|
+
# Size and distance calculations report results in meters.
|
15
|
+
# This implementation is thus ideal for everyday calculations on
|
16
|
+
# the globe in which good accuracy is desired, but in which it is
|
17
|
+
# not deemed necessary to perform the complex ellipsoidal
|
18
|
+
# calculations needed for greater precision.
|
19
|
+
#
|
20
|
+
# The maximum error is about 0.5 percent, for objects and
|
21
|
+
# calculations that span a significant percentage of the globe, due
|
22
|
+
# to distortion caused by rotational flattening of the earth. For
|
23
|
+
# calculations that span a much smaller area, the error can drop to
|
24
|
+
# a few meters or less.
|
25
|
+
#
|
26
|
+
# === Limitations
|
27
|
+
#
|
28
|
+
# This implementation does not implement some of the more advanced
|
29
|
+
# geometric operations. In particular:
|
30
|
+
#
|
31
|
+
# * Relational operators such as Feature::Geometry#intersects? are
|
32
|
+
# not implemented for most types.
|
33
|
+
# * Relational constructors such as Feature::Geometry#union are
|
34
|
+
# not implemented for most types.
|
35
|
+
# * Buffer, convex hull, and envelope calculations are not
|
36
|
+
# implemented for most types. Boundaries are available except for
|
37
|
+
# GeometryCollection.
|
38
|
+
# * Length calculations are available, but areas are not. Distances
|
39
|
+
# are available only between points.
|
40
|
+
# * Equality and simplicity evaluation are implemented for some but
|
41
|
+
# not all types.
|
42
|
+
# * Assertions for polygons and multipolygons are not implemented.
|
43
|
+
#
|
44
|
+
# Unimplemented operations will return nil if invoked.
|
45
|
+
#
|
46
|
+
# === Options
|
47
|
+
#
|
48
|
+
# You may use the following options when creating a spherical
|
49
|
+
# factory:
|
50
|
+
#
|
51
|
+
# [<tt>:has_z_coordinate</tt>]
|
52
|
+
# Support a Z coordinate. Default is false.
|
53
|
+
# [<tt>:has_m_coordinate</tt>]
|
54
|
+
# Support an M coordinate. Default is false.
|
55
|
+
# [<tt>:uses_lenient_assertions</tt>]
|
56
|
+
# If set to true, assertion checking is disabled. This includes
|
57
|
+
# simplicity checking on LinearRing, and validity checks on
|
58
|
+
# Polygon and MultiPolygon. This may speed up creation of certain
|
59
|
+
# objects, at the expense of not doing the proper checking for
|
60
|
+
# OGC compliance. Default is false.
|
61
|
+
# [<tt>:buffer_resolution</tt>]
|
62
|
+
# The resolution of buffers around geometries created by this
|
63
|
+
# factory. This controls the number of line segments used to
|
64
|
+
# approximate curves. The default is 1, which causes, for
|
65
|
+
# example, the buffer around a point to be approximated by a
|
66
|
+
# 4-sided polygon. A resolution of 2 would cause that buffer
|
67
|
+
# to be approximated by an 8-sided polygon. The exact behavior
|
68
|
+
# for different kinds of buffers is not specified precisely,
|
69
|
+
# but in general the value is taken as the number of segments
|
70
|
+
# per 90-degree curve.
|
71
|
+
# [<tt>:proj4</tt>]
|
72
|
+
# Provide the coordinate system in Proj4 format. You may pass
|
73
|
+
# either an RGeo::CoordSys::Proj4 object, or a string or hash
|
74
|
+
# containing the Proj4 parameters. This coordinate system must be
|
75
|
+
# a geographic (lat/long) coordinate system. The default is the
|
76
|
+
# "popular visualization CRS" (EPSG 4055), represented by
|
77
|
+
# "<tt>+proj=longlat +a=6378137 +b=6378137 +towgs84=0,0,0,0,0,0,0 +no_defs</tt>".
|
78
|
+
# Has no effect if Proj4 is not available.
|
79
|
+
# [<tt>:coord_sys</tt>]
|
80
|
+
# Provide a coordinate system in OGC format, either as an object
|
81
|
+
# (one of the CoordSys::CS classes) or as a string in WKT format.
|
82
|
+
# This coordinate system must be a GeographicCoordinateSystem.
|
83
|
+
# The default is the "popular visualization CRS" (EPSG 4055).
|
84
|
+
# [<tt>:srid</tt>]
|
85
|
+
# The SRID that should be returned by features from this factory.
|
86
|
+
# Default is 4055, indicating EPSG 4055, the "popular
|
87
|
+
# visualization crs". You may alternatively wish to set the srid
|
88
|
+
# to 4326, indicating the WGS84 crs, but note that that value
|
89
|
+
# implies an ellipsoidal datum, not a spherical datum.
|
90
|
+
# [<tt>:srs_database</tt>]
|
91
|
+
# Optional. If provided, the value should be an implementation of
|
92
|
+
# CoordSys::SRSDatabase::Interface. If both this and an SRID are
|
93
|
+
# provided, they are used to look up the proj4 and coord_sys
|
94
|
+
# objects from a spatial reference system database.
|
95
|
+
# [<tt>:wkt_parser</tt>]
|
96
|
+
# Configure the parser for WKT. The value is a hash of
|
97
|
+
# configuration parameters for WKRep::WKTParser.new. Default is
|
98
|
+
# the empty hash, indicating the default configuration for
|
99
|
+
# WKRep::WKTParser.
|
100
|
+
# [<tt>:wkb_parser</tt>]
|
101
|
+
# Configure the parser for WKB. The value is a hash of
|
102
|
+
# configuration parameters for WKRep::WKBParser.new. Default is
|
103
|
+
# the empty hash, indicating the default configuration for
|
104
|
+
# WKRep::WKBParser.
|
105
|
+
# [<tt>:wkt_generator</tt>]
|
106
|
+
# Configure the generator for WKT. The value is a hash of
|
107
|
+
# configuration parameters for WKRep::WKTGenerator.new.
|
108
|
+
# Default is <tt>{:convert_case => :upper}</tt>.
|
109
|
+
# [<tt>:wkb_generator</tt>]
|
110
|
+
# Configure the generator for WKT. The value is a hash of
|
111
|
+
# configuration parameters for WKRep::WKTGenerator.new.
|
112
|
+
# Default is the empty hash, indicating the default configuration
|
113
|
+
# for WKRep::WKBGenerator.
|
114
|
+
|
115
|
+
def spherical_factory(opts_ = {})
|
116
|
+
proj4_ = opts_[:proj4]
|
117
|
+
coord_sys_ = opts_[:coord_sys]
|
118
|
+
srid_ = opts_[:srid]
|
119
|
+
if (!proj4_ || !coord_sys_) && srid_ && (db_ = opts_[:srs_database])
|
120
|
+
entry_ = db_.get(srid_.to_i)
|
121
|
+
if entry_
|
122
|
+
proj4_ ||= entry_.proj4
|
123
|
+
coord_sys_ ||= entry_.coord_sys
|
124
|
+
end
|
125
|
+
end
|
126
|
+
srid_ ||= coord_sys_.authority_code if coord_sys_
|
127
|
+
Geographic::Factory.new("Spherical",
|
128
|
+
has_z_coordinate: opts_[:has_z_coordinate],
|
129
|
+
has_m_coordinate: opts_[:has_m_coordinate],
|
130
|
+
proj4: proj4_ || _proj4_4055,
|
131
|
+
coord_sys: coord_sys_ || _coordsys_4055,
|
132
|
+
uses_lenient_assertions: opts_[:uses_lenient_assertions],
|
133
|
+
buffer_resolution: opts_[:buffer_resolution],
|
134
|
+
wkt_parser: opts_[:wkt_parser],
|
135
|
+
wkb_parser: opts_[:wkb_parser],
|
136
|
+
wkt_generator: opts_[:wkt_generator],
|
137
|
+
wkb_generator: opts_[:wkb_generator],
|
138
|
+
srid: (srid_ || 4055).to_i)
|
139
|
+
end
|
140
|
+
|
141
|
+
# Creates and returns a geographic factory that is designed for
|
142
|
+
# visualization applications that use Google or Bing maps, or any
|
143
|
+
# other visualization systems that use the same projection. It
|
144
|
+
# includes a projection factory that matches the projection used
|
145
|
+
# by those mapping systems.
|
146
|
+
#
|
147
|
+
# Like all geographic factories, this one creates features using
|
148
|
+
# latitude-longitude values. However, calculations such as
|
149
|
+
# intersections are done in the projected coordinate system, and
|
150
|
+
# size and distance calculations report results in the projected
|
151
|
+
# units.
|
152
|
+
#
|
153
|
+
# The behavior of the simple_mercator factory could also be obtained
|
154
|
+
# using a projected_factory with appropriate Proj4 specifications.
|
155
|
+
# However, the simple_mercator implementation is done without
|
156
|
+
# actually requiring the Proj4 library. The projections are simple
|
157
|
+
# enough to be implemented in pure ruby.
|
158
|
+
#
|
159
|
+
# === About the coordinate system
|
160
|
+
#
|
161
|
+
# Many popular visualization technologies, such as Google and Bing
|
162
|
+
# maps, actually use two coordinate systems. The first is the
|
163
|
+
# standard WSG84 lat-long system used by the GPS and represented
|
164
|
+
# by EPSG 4326. Most API calls and input-output in these mapping
|
165
|
+
# technologies utilize this coordinate system. The second is a
|
166
|
+
# Mercator projection based on a "sphericalization" of the WGS84
|
167
|
+
# lat-long system. This projection is the basis of the map's screen
|
168
|
+
# and tiling coordinates, and has been assigned EPSG 3857.
|
169
|
+
#
|
170
|
+
# This factory represents both coordinate systems. The main factory
|
171
|
+
# produces data in the lat-long system and reports SRID 4326, and
|
172
|
+
# the projected factory produces data in the projection and reports
|
173
|
+
# SRID 3857. Latitudes are restricted to the range
|
174
|
+
# (-85.05112877980659, 85.05112877980659), which conveniently
|
175
|
+
# results in a square projected domain.
|
176
|
+
#
|
177
|
+
# === Options
|
178
|
+
#
|
179
|
+
# You may use the following options when creating a simple_mercator
|
180
|
+
# factory:
|
181
|
+
#
|
182
|
+
# [<tt>:has_z_coordinate</tt>]
|
183
|
+
# Support a Z coordinate. Default is false.
|
184
|
+
# [<tt>:has_m_coordinate</tt>]
|
185
|
+
# Support an M coordinate. Default is false.
|
186
|
+
# [<tt>:wkt_parser</tt>]
|
187
|
+
# Configure the parser for WKT. The value is a hash of
|
188
|
+
# configuration parameters for WKRep::WKTParser.new. Default is
|
189
|
+
# the empty hash, indicating the default configuration for
|
190
|
+
# WKRep::WKTParser.
|
191
|
+
# [<tt>:wkb_parser</tt>]
|
192
|
+
# Configure the parser for WKB. The value is a hash of
|
193
|
+
# configuration parameters for WKRep::WKBParser.new. Default is
|
194
|
+
# the empty hash, indicating the default configuration for
|
195
|
+
# WKRep::WKBParser.
|
196
|
+
# [<tt>:wkt_generator</tt>]
|
197
|
+
# Configure the generator for WKT. The value is a hash of
|
198
|
+
# configuration parameters for WKRep::WKTGenerator.new.
|
199
|
+
# Default is <tt>{:convert_case => :upper}</tt>.
|
200
|
+
# [<tt>:wkb_generator</tt>]
|
201
|
+
# Configure the generator for WKT. The value is a hash of
|
202
|
+
# configuration parameters for WKRep::WKTGenerator.new.
|
203
|
+
# Default is the empty hash, indicating the default configuration
|
204
|
+
# for WKRep::WKBGenerator.
|
205
|
+
#
|
206
|
+
# You may also provide options understood by the underlying
|
207
|
+
# projected Cartesian factory. For example, if GEOS is used for the
|
208
|
+
# projected factory, you may also set the
|
209
|
+
# <tt>:lenient_multi_polygon_assertions</tt> and
|
210
|
+
# <tt>:buffer_resolution</tt> options. See RGeo::Geos.factory for
|
211
|
+
# more details.
|
212
|
+
|
213
|
+
def simple_mercator_factory(opts_ = {})
|
214
|
+
factory_ = Geographic::Factory.new("Projected",
|
215
|
+
proj4: _proj4_4326,
|
216
|
+
coord_sys: _coordsys_4326,
|
217
|
+
srid: 4326,
|
218
|
+
wkt_parser: opts_[:wkt_parser],
|
219
|
+
wkb_parser: opts_[:wkb_parser],
|
220
|
+
wkt_generator: opts_[:wkt_generator],
|
221
|
+
wkb_generator: opts_[:wkb_generator],
|
222
|
+
has_z_coordinate: opts_[:has_z_coordinate],
|
223
|
+
has_m_coordinate: opts_[:has_m_coordinate])
|
224
|
+
projector_ = Geographic::SimpleMercatorProjector.new(factory_,
|
225
|
+
buffer_resolution: opts_[:buffer_resolution],
|
226
|
+
lenient_multi_polygon_assertions: opts_[:lenient_multi_polygon_assertions],
|
227
|
+
uses_lenient_assertions: opts_[:uses_lenient_assertions],
|
228
|
+
has_z_coordinate: opts_[:has_z_coordinate],
|
229
|
+
has_m_coordinate: opts_[:has_m_coordinate])
|
230
|
+
factory_._set_projector(projector_)
|
231
|
+
factory_
|
232
|
+
end
|
233
|
+
|
234
|
+
# Creates and returns a geographic factory that includes a
|
235
|
+
# projection specified by a Proj4 coordinate system. Like all
|
236
|
+
# geographic factories, this one creates features using latitude-
|
237
|
+
# longitude values. However, calculations such as intersections are
|
238
|
+
# done in the projected coordinate system, and size and distance
|
239
|
+
# calculations report results in the projected units. Thus, this
|
240
|
+
# factory actually includes two factories representing different
|
241
|
+
# coordinate systems: the main factory representing the geographic
|
242
|
+
# lat-long coordinate system, and an auxiliary "projection factory"
|
243
|
+
# representing the projected coordinate system.
|
244
|
+
#
|
245
|
+
# This implementation is intended for advanced GIS applications
|
246
|
+
# requiring greater control over the projection being used.
|
247
|
+
#
|
248
|
+
# === Options
|
249
|
+
#
|
250
|
+
# When creating a projected implementation, you must provide enough
|
251
|
+
# information to construct a Proj4 specification for the projection.
|
252
|
+
# Generally, this means you will provide either the projection's
|
253
|
+
# factory itself (via the <tt>:projection_factory</tt> option), in
|
254
|
+
# which case the factory must include a Proj4 coordinate system;
|
255
|
+
# or, alternatively, you should provide the Proj4 coordinate system
|
256
|
+
# and let this method construct a projection factory for you (which
|
257
|
+
# it will do using the preferred Cartesian factory generator).
|
258
|
+
# If you choose this second method, you may provide the proj4
|
259
|
+
# directly via the <tt>:projection_proj4</tt> option, or indirectly
|
260
|
+
# by providing both an <tt>:srid</tt> and a <tt>:srs_database</tt>
|
261
|
+
# to use to look up the coordinate system.
|
262
|
+
#
|
263
|
+
# Following are detailed descriptions of the various options you can
|
264
|
+
# pass to this method.
|
265
|
+
#
|
266
|
+
# [<tt>:projection_factory</tt>]
|
267
|
+
# Specify an existing Cartesian factory to use for the projection.
|
268
|
+
# This factory must have a non-nil Proj4. If this is provided, any
|
269
|
+
# <tt>:projection_proj4</tt>, <tt>:projection_coord_sys</tt>, and
|
270
|
+
# <tt>:projection_srid</tt> are ignored.
|
271
|
+
# [<tt>:projection_proj4</tt>]
|
272
|
+
# Specify a Proj4 projection to use to construct the projection
|
273
|
+
# factory. This may be specified as a CoordSys::Proj4 object, or
|
274
|
+
# as a Proj4 string or hash representation.
|
275
|
+
# [<tt>:projection_coord_sys</tt>]
|
276
|
+
# Specify a OGC coordinate system for the projection. This may be
|
277
|
+
# specified as an RGeo::CoordSys::CS::GeographicCoordinateSystem
|
278
|
+
# object, or as a String in OGC WKT format. Optional.
|
279
|
+
# [<tt>:projection_srid</tt>]
|
280
|
+
# The SRID value to use for the projection factory. Defaults to
|
281
|
+
# the given projection coordinate system's authority code, or to
|
282
|
+
# 0 if no projection coordinate system is known.
|
283
|
+
# [<tt>:proj4</tt>]
|
284
|
+
# A proj4 projection for the geographic (lat-lon) factory. You may
|
285
|
+
# pass either an RGeo::CoordSys::Proj4 object, or a string or hash
|
286
|
+
# containing the Proj4 parameters. This coordinate system must be
|
287
|
+
# a geographic (lat/long) coordinate system. It defaults to the
|
288
|
+
# geographic part of the projection factory's coordinate system.
|
289
|
+
# Generally, you should leave it at the default unless you want
|
290
|
+
# the geographic coordinate system to be based on a different
|
291
|
+
# horizontal datum than the projection.
|
292
|
+
# [<tt>:coord_sys</tt>]
|
293
|
+
# An OGC coordinate system for the geographic (lat-lon) factory,
|
294
|
+
# which may be an RGeo::CoordSys::CS::GeographicCoordinateSystem
|
295
|
+
# object or a string in OGC WKT format. It defaults to the
|
296
|
+
# geographic system embedded in the projection coordinate system.
|
297
|
+
# Generally, you should leave it at the default unless you want
|
298
|
+
# the geographic coordinate system to be based on a different
|
299
|
+
# horizontal datum than the projection.
|
300
|
+
# [<tt>:srid</tt>]
|
301
|
+
# The SRID value to use for the main geographic factory. Defaults
|
302
|
+
# to the given geographic coordinate system's authority code, or
|
303
|
+
# to 0 if no geographic coordinate system is known.
|
304
|
+
# [<tt>:srs_database</tt>]
|
305
|
+
# Optional. If provided, the value should be an implementation of
|
306
|
+
# CoordSys::SRSDatabase::Interface. If both this and an SRID are
|
307
|
+
# provided, they are used to look up the proj4 and coord_sys
|
308
|
+
# objects from a spatial reference system database.
|
309
|
+
# [<tt>:has_z_coordinate</tt>]
|
310
|
+
# Support a Z coordinate. Default is false.
|
311
|
+
# Note: this is ignored if a <tt>:projection_factory</tt> is
|
312
|
+
# provided; in that case, the geographic factory's z-coordinate
|
313
|
+
# availability will match the projection factory's setting.
|
314
|
+
# [<tt>:has_m_coordinate</tt>]
|
315
|
+
# Support an M coordinate. Default is false.
|
316
|
+
# Note: this is ignored if a <tt>:projection_factory</tt> is
|
317
|
+
# provided; in that case, the geographic factory's m-coordinate
|
318
|
+
# availability will match the projection factory's setting.
|
319
|
+
# [<tt>:wkt_parser</tt>]
|
320
|
+
# Configure the parser for WKT. The value is a hash of
|
321
|
+
# configuration parameters for WKRep::WKTParser.new. Default is
|
322
|
+
# the empty hash, indicating the default configuration for
|
323
|
+
# WKRep::WKTParser.
|
324
|
+
# [<tt>:wkb_parser</tt>]
|
325
|
+
# Configure the parser for WKB. The value is a hash of
|
326
|
+
# configuration parameters for WKRep::WKBParser.new. Default is
|
327
|
+
# the empty hash, indicating the default configuration for
|
328
|
+
# WKRep::WKBParser.
|
329
|
+
# [<tt>:wkt_generator</tt>]
|
330
|
+
# Configure the generator for WKT. The value is a hash of
|
331
|
+
# configuration parameters for WKRep::WKTGenerator.new.
|
332
|
+
# Default is <tt>{:convert_case => :upper}</tt>.
|
333
|
+
# [<tt>:wkb_generator</tt>]
|
334
|
+
# Configure the generator for WKT. The value is a hash of
|
335
|
+
# configuration parameters for WKRep::WKTGenerator.new.
|
336
|
+
# Default is the empty hash, indicating the default configuration
|
337
|
+
# for WKRep::WKBGenerator.
|
338
|
+
#
|
339
|
+
# If a <tt>:projection_factory</tt> is _not_ provided, you may also
|
340
|
+
# provide options for configuring the projected Cartesian factory.
|
341
|
+
# For example, if GEOS is used for the projected factory, you may
|
342
|
+
# also set the <tt>:lenient_multi_polygon_assertions</tt> and
|
343
|
+
# <tt>:buffer_resolution</tt> options. See RGeo::Geos.factory for
|
344
|
+
# more details.
|
345
|
+
|
346
|
+
def projected_factory(opts_ = {})
|
347
|
+
unless CoordSys::Proj4.supported?
|
348
|
+
raise Error::UnsupportedOperation, "Proj4 is not supported because the proj4 library was not found at install time."
|
349
|
+
end
|
350
|
+
db_ = opts_[:srs_database]
|
351
|
+
if (projection_factory_ = opts_[:projection_factory])
|
352
|
+
# Get the projection coordinate systems from the given factory
|
353
|
+
projection_proj4_ = projection_factory_.proj4
|
354
|
+
unless projection_proj4_
|
355
|
+
raise ::ArgumentError, "The :projection_factory does not have a proj4."
|
356
|
+
end
|
357
|
+
projection_coord_sys_ = projection_factory_.coord_sys
|
358
|
+
if projection_coord_sys_ && !projection_coord_sys_.is_a?(CoordSys::CS::ProjectedCoordinateSystem)
|
359
|
+
raise ::ArgumentError, 'The :projection_factory\'s coord_sys is not a ProjectedCoordinateSystem.'
|
360
|
+
end
|
361
|
+
# Determine geographic coordinate system. First check parameters.
|
362
|
+
proj4_ = opts_[:proj4]
|
363
|
+
coord_sys_ = opts_[:coord_sys]
|
364
|
+
srid_ = opts_[:srid]
|
365
|
+
# Lookup srid from srs database if needed
|
366
|
+
if (!proj4_ || !coord_sys_) && srid_ && db_
|
367
|
+
entry_ = db_.get(srid_.to_i)
|
368
|
+
if entry_
|
369
|
+
proj4_ ||= entry_.proj4
|
370
|
+
coord_sys_ ||= entry_.coord_sys
|
371
|
+
end
|
372
|
+
end
|
373
|
+
# Fall back to getting the values from the projection.
|
374
|
+
proj4_ ||= projection_proj4_.get_geographic || _proj4_4326
|
375
|
+
coord_sys_ ||= projection_coord_sys_.geographic_coordinate_system if projection_coord_sys_
|
376
|
+
srid_ ||= coord_sys_.authority_code if coord_sys_
|
377
|
+
srid_ ||= 4326
|
378
|
+
# Now we should have all the coordinate system info.
|
379
|
+
factory_ = Geographic::Factory.new("Projected",
|
380
|
+
proj4: proj4_,
|
381
|
+
coord_sys: coord_sys_,
|
382
|
+
srid: srid_.to_i,
|
383
|
+
has_z_coordinate: projection_factory_.property(:has_z_coordinate),
|
384
|
+
has_m_coordinate: projection_factory_.property(:has_m_coordinate),
|
385
|
+
wkt_parser: opts_[:wkt_parser], wkt_generator: opts_[:wkt_generator],
|
386
|
+
wkb_parser: opts_[:wkb_parser], wkb_generator: opts_[:wkb_generator])
|
387
|
+
projector_ = Geographic::Proj4Projector.create_from_existing_factory(factory_,
|
388
|
+
projection_factory_)
|
389
|
+
else
|
390
|
+
# Determine projection coordinate system. First check the parameters.
|
391
|
+
projection_proj4_ = opts_[:projection_proj4]
|
392
|
+
projection_coord_sys_ = opts_[:projection_coord_sys]
|
393
|
+
projection_srid_ = opts_[:projection_srid]
|
394
|
+
# Check the case where we need to look up a srid from an srs database.
|
395
|
+
if (!projection_proj4_ || !projection_coord_sys_) && projection_srid_ && db_
|
396
|
+
entry_ = db_.get(projection_srid_.to_i)
|
397
|
+
if entry_
|
398
|
+
projection_proj4_ ||= entry_.proj4
|
399
|
+
projection_coord_sys_ ||= entry_.coord_sys
|
400
|
+
end
|
401
|
+
end
|
402
|
+
# A projection proj4 is absolutely required.
|
403
|
+
unless projection_proj4_
|
404
|
+
raise ::ArgumentError, "Unable to determine the Proj4 for the projected coordinate system."
|
405
|
+
end
|
406
|
+
# Check the projection coordinate systems, and parse if needed.
|
407
|
+
if projection_proj4_.is_a?(::String) || projection_proj4_.is_a?(::Hash)
|
408
|
+
actual_projection_proj4_ = CoordSys::Proj4.create(projection_proj4_)
|
409
|
+
unless actual_projection_proj4_
|
410
|
+
raise ::ArgumentError, "Bad proj4 syntax: #{projection_proj4_.inspect}"
|
411
|
+
end
|
412
|
+
projection_proj4_ = actual_projection_proj4_
|
413
|
+
end
|
414
|
+
if projection_coord_sys_ && !projection_coord_sys_.is_a?(CoordSys::CS::ProjectedCoordinateSystem)
|
415
|
+
raise ::ArgumentError, "The :projection_coord_sys is not a ProjectedCoordinateSystem."
|
416
|
+
end
|
417
|
+
projection_srid_ ||= projection_coord_sys_.authority_code if projection_coord_sys_
|
418
|
+
# Determine geographic coordinate system. First check parameters.
|
419
|
+
proj4_ = opts_[:proj4]
|
420
|
+
coord_sys_ = opts_[:coord_sys]
|
421
|
+
srid_ = opts_[:srid]
|
422
|
+
# Lookup srid from srs database if needed
|
423
|
+
if (!proj4_ || !coord_sys_) && srid_ && db_
|
424
|
+
entry_ = db_.get(srid_.to_i)
|
425
|
+
if entry_
|
426
|
+
proj4_ ||= entry_.proj4
|
427
|
+
coord_sys_ ||= entry_.coord_sys
|
428
|
+
end
|
429
|
+
end
|
430
|
+
# Fall back to getting the values from the projection.
|
431
|
+
proj4_ ||= projection_proj4_.get_geographic || _proj4_4326
|
432
|
+
coord_sys_ ||= projection_coord_sys_.geographic_coordinate_system if projection_coord_sys_
|
433
|
+
srid_ ||= coord_sys_.authority_code if coord_sys_
|
434
|
+
srid_ ||= 4326
|
435
|
+
# Now we should have all the coordinate system info.
|
436
|
+
factory_ = Geographic::Factory.new("Projected",
|
437
|
+
proj4: proj4_,
|
438
|
+
coord_sys: coord_sys_,
|
439
|
+
srid: srid_.to_i,
|
440
|
+
has_z_coordinate: opts_[:has_z_coordinate],
|
441
|
+
has_m_coordinate: opts_[:has_m_coordinate],
|
442
|
+
wkt_parser: opts_[:wkt_parser], wkt_generator: opts_[:wkt_generator],
|
443
|
+
wkb_parser: opts_[:wkb_parser], wkb_generator: opts_[:wkb_generator])
|
444
|
+
projector_ = Geographic::Proj4Projector.create_from_proj4(factory_,
|
445
|
+
projection_proj4_,
|
446
|
+
srid: projection_srid_,
|
447
|
+
coord_sys: projection_coord_sys_,
|
448
|
+
buffer_resolution: opts_[:buffer_resolution],
|
449
|
+
lenient_multi_polygon_assertions: opts_[:lenient_multi_polygon_assertions],
|
450
|
+
uses_lenient_assertions: opts_[:uses_lenient_assertions],
|
451
|
+
has_z_coordinate: opts_[:has_z_coordinate],
|
452
|
+
has_m_coordinate: opts_[:has_m_coordinate],
|
453
|
+
wkt_parser: opts_[:wkt_parser], wkt_generator: opts_[:wkt_generator],
|
454
|
+
wkb_parser: opts_[:wkb_parser], wkb_generator: opts_[:wkb_generator])
|
455
|
+
end
|
456
|
+
factory_._set_projector(projector_)
|
457
|
+
factory_
|
458
|
+
end
|
459
|
+
|
460
|
+
def _proj4_4055 # :nodoc:
|
461
|
+
unless defined?(@proj4_4055)
|
462
|
+
@proj4_4055 = CoordSys::Proj4.create("+proj=longlat +a=6378137 +b=6378137 +towgs84=0,0,0,0,0,0,0 +no_defs")
|
463
|
+
end
|
464
|
+
@proj4_4055
|
465
|
+
end
|
466
|
+
|
467
|
+
def _coordsys_4055 # :nodoc:
|
468
|
+
unless defined?(@coordsys_4055)
|
469
|
+
@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"]]')
|
470
|
+
end
|
471
|
+
@coordsys_4055
|
472
|
+
end
|
473
|
+
|
474
|
+
def _proj4_4326 # :nodoc:
|
475
|
+
unless defined?(@proj4_4326)
|
476
|
+
@proj4_4326 = CoordSys::Proj4.create("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
|
477
|
+
end
|
478
|
+
@proj4_4326
|
479
|
+
end
|
480
|
+
|
481
|
+
def _coordsys_4326 # :nodoc:
|
482
|
+
unless defined?(@coordsys_4326)
|
483
|
+
@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"]]')
|
484
|
+
end
|
485
|
+
@coordsys_4326
|
486
|
+
end
|
487
|
+
end
|
488
|
+
end
|
489
|
+
end
|