schleyfox-rgeo 0.2.5
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.
- data/History.rdoc +199 -0
- data/README.rdoc +172 -0
- data/Spatial_Programming_With_RGeo.rdoc +440 -0
- data/Version +1 -0
- data/ext/geos_c_impl/extconf.rb +84 -0
- data/ext/geos_c_impl/factory.c +468 -0
- data/ext/geos_c_impl/factory.h +224 -0
- data/ext/geos_c_impl/geometry.c +705 -0
- data/ext/geos_c_impl/geometry.h +55 -0
- data/ext/geos_c_impl/geometry_collection.c +482 -0
- data/ext/geos_c_impl/geometry_collection.h +69 -0
- data/ext/geos_c_impl/line_string.c +509 -0
- data/ext/geos_c_impl/line_string.h +64 -0
- data/ext/geos_c_impl/main.c +70 -0
- data/ext/geos_c_impl/point.c +193 -0
- data/ext/geos_c_impl/point.h +62 -0
- data/ext/geos_c_impl/polygon.c +265 -0
- data/ext/geos_c_impl/polygon.h +66 -0
- data/ext/geos_c_impl/preface.h +50 -0
- data/ext/proj4_c_impl/extconf.rb +88 -0
- data/ext/proj4_c_impl/main.c +271 -0
- data/lib/rgeo.rb +124 -0
- data/lib/rgeo/cartesian.rb +60 -0
- data/lib/rgeo/cartesian/analysis.rb +118 -0
- data/lib/rgeo/cartesian/bounding_box.rb +337 -0
- data/lib/rgeo/cartesian/calculations.rb +161 -0
- data/lib/rgeo/cartesian/factory.rb +209 -0
- data/lib/rgeo/cartesian/feature_classes.rb +173 -0
- data/lib/rgeo/cartesian/feature_methods.rb +106 -0
- data/lib/rgeo/cartesian/interface.rb +150 -0
- data/lib/rgeo/coord_sys.rb +79 -0
- data/lib/rgeo/coord_sys/cs/entities.rb +1524 -0
- data/lib/rgeo/coord_sys/cs/factories.rb +208 -0
- data/lib/rgeo/coord_sys/cs/wkt_parser.rb +308 -0
- data/lib/rgeo/coord_sys/proj4.rb +312 -0
- data/lib/rgeo/coord_sys/srs_database/active_record_table.rb +194 -0
- data/lib/rgeo/coord_sys/srs_database/interface.rb +165 -0
- data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +188 -0
- data/lib/rgeo/coord_sys/srs_database/sr_org.rb +108 -0
- data/lib/rgeo/coord_sys/srs_database/url_reader.rb +108 -0
- data/lib/rgeo/error.rb +63 -0
- data/lib/rgeo/feature.rb +88 -0
- data/lib/rgeo/feature/curve.rb +156 -0
- data/lib/rgeo/feature/factory.rb +332 -0
- data/lib/rgeo/feature/factory_generator.rb +138 -0
- data/lib/rgeo/feature/geometry.rb +614 -0
- data/lib/rgeo/feature/geometry_collection.rb +129 -0
- data/lib/rgeo/feature/line.rb +66 -0
- data/lib/rgeo/feature/line_string.rb +102 -0
- data/lib/rgeo/feature/linear_ring.rb +66 -0
- data/lib/rgeo/feature/multi_curve.rb +113 -0
- data/lib/rgeo/feature/multi_line_string.rb +66 -0
- data/lib/rgeo/feature/multi_point.rb +73 -0
- data/lib/rgeo/feature/multi_polygon.rb +97 -0
- data/lib/rgeo/feature/multi_surface.rb +116 -0
- data/lib/rgeo/feature/point.rb +120 -0
- data/lib/rgeo/feature/polygon.rb +141 -0
- data/lib/rgeo/feature/surface.rb +122 -0
- data/lib/rgeo/feature/types.rb +305 -0
- data/lib/rgeo/geographic.rb +75 -0
- data/lib/rgeo/geographic/factory.rb +287 -0
- data/lib/rgeo/geographic/interface.rb +410 -0
- data/lib/rgeo/geographic/proj4_projector.rb +98 -0
- data/lib/rgeo/geographic/projected_feature_classes.rb +213 -0
- data/lib/rgeo/geographic/projected_feature_methods.rb +228 -0
- data/lib/rgeo/geographic/projected_window.rb +467 -0
- data/lib/rgeo/geographic/simple_mercator_projector.rb +157 -0
- data/lib/rgeo/geographic/spherical_feature_classes.rb +212 -0
- data/lib/rgeo/geographic/spherical_feature_methods.rb +97 -0
- data/lib/rgeo/geographic/spherical_math.rb +206 -0
- data/lib/rgeo/geos.rb +72 -0
- data/lib/rgeo/geos/factory.rb +301 -0
- data/lib/rgeo/geos/impl_additions.rb +76 -0
- data/lib/rgeo/geos/interface.rb +139 -0
- data/lib/rgeo/geos/zm_factory.rb +275 -0
- data/lib/rgeo/geos/zm_impl.rb +432 -0
- data/lib/rgeo/impl_helper.rb +53 -0
- data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +235 -0
- data/lib/rgeo/impl_helper/basic_geometry_methods.rb +85 -0
- data/lib/rgeo/impl_helper/basic_line_string_methods.rb +197 -0
- data/lib/rgeo/impl_helper/basic_point_methods.rb +138 -0
- data/lib/rgeo/impl_helper/basic_polygon_methods.rb +121 -0
- data/lib/rgeo/impl_helper/math.rb +50 -0
- data/lib/rgeo/version.rb +52 -0
- data/lib/rgeo/wkrep.rb +72 -0
- data/lib/rgeo/wkrep/wkb_generator.rb +267 -0
- data/lib/rgeo/wkrep/wkb_parser.rb +315 -0
- data/lib/rgeo/wkrep/wkt_generator.rb +275 -0
- data/lib/rgeo/wkrep/wkt_parser.rb +496 -0
- data/test/common/geometry_collection_tests.rb +238 -0
- data/test/common/line_string_tests.rb +324 -0
- data/test/common/multi_line_string_tests.rb +209 -0
- data/test/common/multi_point_tests.rb +201 -0
- data/test/common/multi_polygon_tests.rb +208 -0
- data/test/common/point_tests.rb +331 -0
- data/test/common/polygon_tests.rb +232 -0
- data/test/coord_sys/tc_active_record_table.rb +102 -0
- data/test/coord_sys/tc_ogc_cs.rb +356 -0
- data/test/coord_sys/tc_proj4.rb +138 -0
- data/test/coord_sys/tc_proj4_srs_data.rb +76 -0
- data/test/coord_sys/tc_sr_org.rb +70 -0
- data/test/coord_sys/tc_url_reader.rb +82 -0
- data/test/geos/tc_factory.rb +91 -0
- data/test/geos/tc_geometry_collection.rb +62 -0
- data/test/geos/tc_line_string.rb +62 -0
- data/test/geos/tc_misc.rb +72 -0
- data/test/geos/tc_multi_line_string.rb +62 -0
- data/test/geos/tc_multi_point.rb +62 -0
- data/test/geos/tc_multi_polygon.rb +63 -0
- data/test/geos/tc_point.rb +86 -0
- data/test/geos/tc_polygon.rb +86 -0
- data/test/geos/tc_zmfactory.rb +85 -0
- data/test/projected_geographic/tc_geometry_collection.rb +62 -0
- data/test/projected_geographic/tc_line_string.rb +62 -0
- data/test/projected_geographic/tc_multi_line_string.rb +62 -0
- data/test/projected_geographic/tc_multi_point.rb +62 -0
- data/test/projected_geographic/tc_multi_polygon.rb +63 -0
- data/test/projected_geographic/tc_point.rb +93 -0
- data/test/projected_geographic/tc_polygon.rb +62 -0
- data/test/simple_cartesian/tc_calculations.rb +145 -0
- data/test/simple_cartesian/tc_geometry_collection.rb +69 -0
- data/test/simple_cartesian/tc_line_string.rb +70 -0
- data/test/simple_cartesian/tc_multi_line_string.rb +67 -0
- data/test/simple_cartesian/tc_multi_point.rb +67 -0
- data/test/simple_cartesian/tc_multi_polygon.rb +70 -0
- data/test/simple_cartesian/tc_point.rb +91 -0
- data/test/simple_cartesian/tc_polygon.rb +67 -0
- data/test/simple_mercator/tc_geometry_collection.rb +62 -0
- data/test/simple_mercator/tc_line_string.rb +62 -0
- data/test/simple_mercator/tc_multi_line_string.rb +62 -0
- data/test/simple_mercator/tc_multi_point.rb +62 -0
- data/test/simple_mercator/tc_multi_polygon.rb +63 -0
- data/test/simple_mercator/tc_point.rb +93 -0
- data/test/simple_mercator/tc_polygon.rb +62 -0
- data/test/simple_mercator/tc_window.rb +219 -0
- data/test/spherical_geographic/tc_calculations.rb +203 -0
- data/test/spherical_geographic/tc_geometry_collection.rb +70 -0
- data/test/spherical_geographic/tc_line_string.rb +70 -0
- data/test/spherical_geographic/tc_multi_line_string.rb +67 -0
- data/test/spherical_geographic/tc_multi_point.rb +67 -0
- data/test/spherical_geographic/tc_multi_polygon.rb +70 -0
- data/test/spherical_geographic/tc_point.rb +100 -0
- data/test/spherical_geographic/tc_polygon.rb +67 -0
- data/test/tc_cartesian_analysis.rb +107 -0
- data/test/tc_oneoff.rb +63 -0
- data/test/wkrep/tc_wkb_generator.rb +249 -0
- data/test/wkrep/tc_wkb_parser.rb +353 -0
- data/test/wkrep/tc_wkt_generator.rb +362 -0
- data/test/wkrep/tc_wkt_parser.rb +480 -0
- metadata +267 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# GEOS implementation additions written in Ruby
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
# Copyright 2010 Daniel Azuma
|
7
|
+
#
|
8
|
+
# All rights reserved.
|
9
|
+
#
|
10
|
+
# Redistribution and use in source and binary forms, with or without
|
11
|
+
# modification, are permitted provided that the following conditions are met:
|
12
|
+
#
|
13
|
+
# * Redistributions of source code must retain the above copyright notice,
|
14
|
+
# this list of conditions and the following disclaimer.
|
15
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
+
# this list of conditions and the following disclaimer in the documentation
|
17
|
+
# and/or other materials provided with the distribution.
|
18
|
+
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
+
# contributors to this software, may be used to endorse or promote products
|
20
|
+
# derived from this software without specific prior written permission.
|
21
|
+
#
|
22
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
27
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
28
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
29
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
30
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
# -----------------------------------------------------------------------------
|
33
|
+
;
|
34
|
+
|
35
|
+
|
36
|
+
module RGeo
|
37
|
+
|
38
|
+
module Geos
|
39
|
+
|
40
|
+
|
41
|
+
class GeometryImpl # :nodoc:
|
42
|
+
|
43
|
+
include Feature::Instance
|
44
|
+
|
45
|
+
def inspect
|
46
|
+
"#<#{self.class}:0x#{object_id.to_s(16)} #{as_text.inspect}>"
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
class Factory
|
53
|
+
|
54
|
+
|
55
|
+
# :stopdoc:
|
56
|
+
if ::RGeo::Geos.supported?
|
57
|
+
IMPL_CLASSES = {
|
58
|
+
Feature::Point => PointImpl,
|
59
|
+
Feature::LineString => LineStringImpl,
|
60
|
+
Feature::LinearRing => LinearRingImpl,
|
61
|
+
Feature::Line => LineImpl,
|
62
|
+
Feature::GeometryCollection => GeometryCollectionImpl,
|
63
|
+
Feature::MultiPoint => MultiPointImpl,
|
64
|
+
Feature::MultiLineString => MultiLineStringImpl,
|
65
|
+
Feature::MultiPolygon => MultiPolygonImpl,
|
66
|
+
}
|
67
|
+
end
|
68
|
+
# :startdoc:
|
69
|
+
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# GEOS toplevel interface
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
# Copyright 2010 Daniel Azuma
|
7
|
+
#
|
8
|
+
# All rights reserved.
|
9
|
+
#
|
10
|
+
# Redistribution and use in source and binary forms, with or without
|
11
|
+
# modification, are permitted provided that the following conditions are met:
|
12
|
+
#
|
13
|
+
# * Redistributions of source code must retain the above copyright notice,
|
14
|
+
# this list of conditions and the following disclaimer.
|
15
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
+
# this list of conditions and the following disclaimer in the documentation
|
17
|
+
# and/or other materials provided with the distribution.
|
18
|
+
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
+
# contributors to this software, may be used to endorse or promote products
|
20
|
+
# derived from this software without specific prior written permission.
|
21
|
+
#
|
22
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
+
# -----------------------------------------------------------------------------
|
34
|
+
;
|
35
|
+
|
36
|
+
|
37
|
+
module RGeo
|
38
|
+
|
39
|
+
module Geos
|
40
|
+
|
41
|
+
@supported = nil
|
42
|
+
|
43
|
+
class << self
|
44
|
+
|
45
|
+
|
46
|
+
# Returns true if GEOS implementation is supported.
|
47
|
+
# If this returns false, GEOS features are not available.
|
48
|
+
|
49
|
+
def supported?
|
50
|
+
@supported.nil? ? (@supported = Factory.respond_to?(:_create)) : @supported
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
# Returns true if the given feature is a GEOS feature, or if the given
|
55
|
+
# factory is a GEOS factory.
|
56
|
+
|
57
|
+
def is_geos?(object_)
|
58
|
+
supported? && (Factory === object_ || GeometryImpl === object_ || ZMFactory === object_ || ZMGeometryImpl === object_)
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
# Returns a factory for the GEOS implementation.
|
63
|
+
# Returns nil if the GEOS implementation is not supported.
|
64
|
+
#
|
65
|
+
# Note that GEOS does not natively support 4-dimensional data
|
66
|
+
# (i.e. both z and m values). However, RGeo's GEOS wrapper does
|
67
|
+
# provide a 4-dimensional factory that utilizes an extra native
|
68
|
+
# GEOS object to handle the extra coordinate. Hence, a factory
|
69
|
+
# configured with both Z and M support will work, but will be
|
70
|
+
# slower than a 2-dimensional or 3-dimensional factory.
|
71
|
+
#
|
72
|
+
# Options include:
|
73
|
+
#
|
74
|
+
# [<tt>:lenient_multi_polygon_assertions</tt>]
|
75
|
+
# If set to true, assertion checking on MultiPolygon is disabled.
|
76
|
+
# This may speed up creation of MultiPolygon objects, at the
|
77
|
+
# expense of not doing the proper checking for OGC MultiPolygon
|
78
|
+
# compliance. See RGeo::Feature::MultiPolygon for details on
|
79
|
+
# the MultiPolygon assertions. Default is false.
|
80
|
+
# [<tt>:buffer_resolution</tt>]
|
81
|
+
# The resolution of buffers around geometries created by this
|
82
|
+
# factory. This controls the number of line segments used to
|
83
|
+
# approximate curves. The default is 1, which causes, for
|
84
|
+
# example, the buffer around a point to be approximated by a
|
85
|
+
# 4-sided polygon. A resolution of 2 would cause that buffer
|
86
|
+
# to be approximated by an 8-sided polygon. The exact behavior
|
87
|
+
# for different kinds of buffers is defined by GEOS.
|
88
|
+
# [<tt>:srid</tt>]
|
89
|
+
# Set the SRID returned by geometries created by this factory.
|
90
|
+
# Default is 0.
|
91
|
+
# [<tt>:proj4</tt>]
|
92
|
+
# The coordinate system in Proj4 format, either as a
|
93
|
+
# CoordSys::Proj4 object or as a string or hash representing the
|
94
|
+
# proj4 format. Optional.
|
95
|
+
# [<tt>:coord_sys</tt>]
|
96
|
+
# The coordinate system in OGC form, either as a subclass of
|
97
|
+
# CoordSys::CS::CoordinateSystem, or as a string in WKT format.
|
98
|
+
# Optional.
|
99
|
+
# [<tt>:srs_database</tt>]
|
100
|
+
# Optional. If provided, the value should be an implementation of
|
101
|
+
# CoordSys::SRSDatabase::Interface. If both this and an SRID are
|
102
|
+
# provided, they are used to look up the proj4 and coord_sys
|
103
|
+
# objects from a spatial reference system database.
|
104
|
+
# [<tt>:has_z_coordinate</tt>]
|
105
|
+
# Support <tt>z_coordinate</tt>. Default is false.
|
106
|
+
# [<tt>:has_m_coordinate</tt>]
|
107
|
+
# Support <tt>m_coordinate</tt>. Default is false.
|
108
|
+
|
109
|
+
def factory(opts_={})
|
110
|
+
if supported?
|
111
|
+
if opts_[:has_z_coordinate] && opts_[:has_m_coordinate]
|
112
|
+
ZMFactory.new(opts_)
|
113
|
+
else
|
114
|
+
Factory.create(opts_)
|
115
|
+
end
|
116
|
+
else
|
117
|
+
nil
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
# Returns a Feature::FactoryGenerator that creates Geos-backed
|
123
|
+
# factories. The given options are used as the default options.
|
124
|
+
#
|
125
|
+
# A common case for this is to provide the <tt>:srs_database</tt>
|
126
|
+
# as a default. Then, the factory generator need only be passed
|
127
|
+
# an SRID and it will automatically fetch the appropriate Proj4
|
128
|
+
# and CoordSys objects.
|
129
|
+
|
130
|
+
def factory_generator(defaults_={})
|
131
|
+
::Proc.new{ |c_| factory(defaults_.merge(c_)) }
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
@@ -0,0 +1,275 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# GEOS zm factory implementation
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
# Copyright 2010 Daniel Azuma
|
7
|
+
#
|
8
|
+
# All rights reserved.
|
9
|
+
#
|
10
|
+
# Redistribution and use in source and binary forms, with or without
|
11
|
+
# modification, are permitted provided that the following conditions are met:
|
12
|
+
#
|
13
|
+
# * Redistributions of source code must retain the above copyright notice,
|
14
|
+
# this list of conditions and the following disclaimer.
|
15
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
+
# this list of conditions and the following disclaimer in the documentation
|
17
|
+
# and/or other materials provided with the distribution.
|
18
|
+
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
+
# contributors to this software, may be used to endorse or promote products
|
20
|
+
# derived from this software without specific prior written permission.
|
21
|
+
#
|
22
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
+
# -----------------------------------------------------------------------------
|
34
|
+
;
|
35
|
+
|
36
|
+
|
37
|
+
module RGeo
|
38
|
+
|
39
|
+
module Geos
|
40
|
+
|
41
|
+
|
42
|
+
# A factory for Geos that handles both Z and M.
|
43
|
+
|
44
|
+
class ZMFactory
|
45
|
+
|
46
|
+
include Feature::Factory::Instance
|
47
|
+
|
48
|
+
|
49
|
+
class << self
|
50
|
+
|
51
|
+
|
52
|
+
# Create a new factory. Returns nil if the GEOS implementation is
|
53
|
+
# not supported.
|
54
|
+
|
55
|
+
def create(opts_={})
|
56
|
+
return nil unless Geos.supported?
|
57
|
+
new(opts_)
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
def initialize(opts_={}) # :nodoc:
|
65
|
+
proj4_ = opts_[:proj4]
|
66
|
+
coord_sys_ = opts_[:coord_sys]
|
67
|
+
srid_ = opts_[:srid]
|
68
|
+
if (!proj4_ || !coord_sys_) && srid_ && (db_ = opts_[:srs_database])
|
69
|
+
entry_ = db_.get(srid_.to_i)
|
70
|
+
if entry_
|
71
|
+
proj4_ ||= entry_.proj4
|
72
|
+
coord_sys_ ||= entry_.coord_sys
|
73
|
+
end
|
74
|
+
end
|
75
|
+
srid_ ||= coord_sys_.authority_code if coord_sys_
|
76
|
+
config_ = {
|
77
|
+
:lenient_multi_polygon_assertions => opts_[:lenient_multi_polygon_assertions],
|
78
|
+
:buffer_resolution => opts_[:buffer_resolution],
|
79
|
+
:srid => srid_.to_i, :proj4 => proj4_, :coord_sys => coord_sys_,
|
80
|
+
}
|
81
|
+
@zfactory = Factory.create(config_.merge(:has_z_coordinate => true))
|
82
|
+
@mfactory = Factory.create(config_.merge(:has_m_coordinate => true))
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
# Returns the SRID of geometries created by this factory.
|
87
|
+
|
88
|
+
def srid
|
89
|
+
@zfactory._srid
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
# Returns the resolution used by buffer calculations on geometries
|
94
|
+
# created by this factory
|
95
|
+
|
96
|
+
def buffer_resolution
|
97
|
+
@zfactory._buffer_resolution
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
# Returns true if this factory is lenient with MultiPolygon assertions
|
102
|
+
|
103
|
+
def lenient_multi_polygon_assertions?
|
104
|
+
@zfactory.lenient_multi_polygon_assertions?
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
# Returns the z-only factory corresponding to this factory.
|
109
|
+
|
110
|
+
def z_factory
|
111
|
+
@zfactory
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
# Returns the m-only factory corresponding to this factory.
|
116
|
+
|
117
|
+
def m_factory
|
118
|
+
@mfactory
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
# Factory equivalence test.
|
123
|
+
|
124
|
+
def eql?(rhs_)
|
125
|
+
rhs_.is_a?(ZMFactory) && rhs_.z_factory == @zfactory
|
126
|
+
end
|
127
|
+
alias_method :==, :eql?
|
128
|
+
|
129
|
+
|
130
|
+
# See ::RGeo::Feature::Factory#property
|
131
|
+
|
132
|
+
def property(name_)
|
133
|
+
case name_
|
134
|
+
when :has_z_coordinate, :has_m_coordinate, :is_cartesian
|
135
|
+
true
|
136
|
+
else
|
137
|
+
nil
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
# See ::RGeo::Feature::Factory#parse_wkt
|
143
|
+
|
144
|
+
def parse_wkt(str_)
|
145
|
+
WKRep::WKTParser.new(self).parse(str_)
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
# See ::RGeo::Feature::Factory#parse_wkb
|
150
|
+
|
151
|
+
def parse_wkb(str_)
|
152
|
+
WKRep::WKBParser.new(self).parse(str_)
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
# See ::RGeo::Feature::Factory#point
|
157
|
+
|
158
|
+
def point(x_, y_, z_=0, m_=0)
|
159
|
+
ZMPointImpl.create(self, @zfactory.point(x_, y_, z_), @mfactory.point(x_, y_, m_))
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
# See ::RGeo::Feature::Factory#line_string
|
164
|
+
|
165
|
+
def line_string(points_)
|
166
|
+
ZMLineStringImpl.create(self, @zfactory.line_string(points_), @mfactory.line_string(points_))
|
167
|
+
end
|
168
|
+
|
169
|
+
|
170
|
+
# See ::RGeo::Feature::Factory#line
|
171
|
+
|
172
|
+
def line(start_, end_)
|
173
|
+
ZMLineStringImpl.create(self, @zfactory.line(start_, end_), @mfactory.line(start_, end_))
|
174
|
+
end
|
175
|
+
|
176
|
+
|
177
|
+
# See ::RGeo::Feature::Factory#linear_ring
|
178
|
+
|
179
|
+
def linear_ring(points_)
|
180
|
+
ZMLineStringImpl.create(self, @zfactory.linear_ring(points_), @mfactory.linear_ring(points_))
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
# See ::RGeo::Feature::Factory#polygon
|
185
|
+
|
186
|
+
def polygon(outer_ring_, inner_rings_=nil)
|
187
|
+
ZMPolygonImpl.create(self, @zfactory.polygon(outer_ring_, inner_rings_), @mfactory.polygon(outer_ring_, inner_rings_))
|
188
|
+
end
|
189
|
+
|
190
|
+
|
191
|
+
# See ::RGeo::Feature::Factory#collection
|
192
|
+
|
193
|
+
def collection(elems_)
|
194
|
+
ZMGeometryCollectionImpl.create(self, @zfactory.collection(elems_), @mfactory.collection(elems_))
|
195
|
+
end
|
196
|
+
|
197
|
+
|
198
|
+
# See ::RGeo::Feature::Factory#multi_point
|
199
|
+
|
200
|
+
def multi_point(elems_)
|
201
|
+
ZMGeometryCollectionImpl.create(self, @zfactory.multi_point(elems_), @mfactory.multi_point(elems_))
|
202
|
+
end
|
203
|
+
|
204
|
+
|
205
|
+
# See ::RGeo::Feature::Factory#multi_line_string
|
206
|
+
|
207
|
+
def multi_line_string(elems_)
|
208
|
+
ZMMultiLineStringImpl.create(self, @zfactory.multi_line_string(elems_), @mfactory.multi_line_string(elems_))
|
209
|
+
end
|
210
|
+
|
211
|
+
|
212
|
+
# See ::RGeo::Feature::Factory#multi_polygon
|
213
|
+
|
214
|
+
def multi_polygon(elems_)
|
215
|
+
ZMMultiPolygonImpl.create(self, @zfactory.multi_polygon(elems_), @mfactory.multi_polygon(elems_))
|
216
|
+
end
|
217
|
+
|
218
|
+
|
219
|
+
# See ::RGeo::Feature::Factory#proj4
|
220
|
+
|
221
|
+
def proj4
|
222
|
+
@zfactory.proj4
|
223
|
+
end
|
224
|
+
|
225
|
+
|
226
|
+
# See ::RGeo::Feature::Factory#coord_sys
|
227
|
+
|
228
|
+
def coord_sys
|
229
|
+
@zfactory.coord_sys
|
230
|
+
end
|
231
|
+
|
232
|
+
|
233
|
+
# See ::RGeo::Feature::Factory#override_cast
|
234
|
+
|
235
|
+
def override_cast(original_, ntype_, flags_)
|
236
|
+
return nil unless Geos.supported?
|
237
|
+
keep_subtype_ = flags_[:keep_subtype]
|
238
|
+
force_new_ = flags_[:force_new]
|
239
|
+
project_ = flags_[:project]
|
240
|
+
type_ = original_.geometry_type
|
241
|
+
ntype_ = type_ if keep_subtype_ && type_.include?(ntype_)
|
242
|
+
case original_
|
243
|
+
when ZMGeometryImpl
|
244
|
+
# Optimization if we're just changing factories, but to
|
245
|
+
# another ZM factory.
|
246
|
+
if original_.factory != self && ntype_ == type_ &&
|
247
|
+
(!project_ || original_.factory.proj4 == @proj4)
|
248
|
+
then
|
249
|
+
zresult_ = original_.z_geometry.dup
|
250
|
+
zresult_._set_factory(@zfactory)
|
251
|
+
mresult_ = original_.m_geometry.dup
|
252
|
+
mresult_._set_factory(@mfactory)
|
253
|
+
return original_.class.create(self, zresult_, mresult_)
|
254
|
+
end
|
255
|
+
# LineString conversion optimization.
|
256
|
+
if (original_.factory != self || ntype_ != type_) &&
|
257
|
+
(!project_ || original_.factory.proj4 == @proj4) &&
|
258
|
+
type_.subtype_of?(Feature::LineString) && ntype_.subtype_of?(Feature::LineString)
|
259
|
+
then
|
260
|
+
klass_ = Factory::IMPL_CLASSES[ntype_]
|
261
|
+
zresult_ = klass_._copy_from(@zfactory, original_.z_geometry)
|
262
|
+
mresult_ = klass_._copy_from(@mfactory, original_.m_geometry)
|
263
|
+
return ZMLineStringImpl.create(self, zresult_, mresult_)
|
264
|
+
end
|
265
|
+
end
|
266
|
+
false
|
267
|
+
end
|
268
|
+
|
269
|
+
|
270
|
+
end
|
271
|
+
|
272
|
+
|
273
|
+
end
|
274
|
+
|
275
|
+
end
|