rgeo 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +9 -7
- data/README.rdoc +7 -5
- data/Version +1 -1
- data/ext/geos_c_impl/factory.c +12 -19
- data/ext/geos_c_impl/factory.h +15 -21
- data/ext/geos_c_impl/geometry.c +19 -36
- data/ext/geos_c_impl/geometry.h +2 -12
- data/ext/geos_c_impl/geometry_collection.c +38 -157
- data/ext/geos_c_impl/geometry_collection.h +2 -12
- data/ext/geos_c_impl/line_string.c +83 -80
- data/ext/geos_c_impl/line_string.h +2 -12
- data/ext/geos_c_impl/main.c +5 -0
- data/ext/geos_c_impl/point.c +2 -12
- data/ext/geos_c_impl/point.h +2 -12
- data/ext/geos_c_impl/polygon.c +5 -14
- data/ext/geos_c_impl/polygon.h +2 -12
- data/ext/geos_c_impl/preface.h +8 -0
- data/lib/rgeo.rb +34 -16
- data/lib/rgeo/{geography/simple_spherical/geometry_collection_impl.rb → cartesian.rb} +19 -26
- data/lib/rgeo/cartesian/calculations.rb +129 -0
- data/lib/rgeo/cartesian/interface.rb +85 -0
- data/lib/rgeo/cartesian/simple_factory.rb +159 -0
- data/lib/rgeo/cartesian/simple_feature_classes.rb +187 -0
- data/lib/rgeo/cartesian/simple_feature_methods.rb +97 -0
- data/lib/rgeo/features.rb +1 -0
- data/lib/rgeo/features/curve.rb +3 -2
- data/lib/rgeo/features/factory.rb +62 -37
- data/lib/rgeo/features/geometry.rb +10 -32
- data/lib/rgeo/features/geometry_collection.rb +3 -2
- data/lib/rgeo/features/line.rb +3 -2
- data/lib/rgeo/features/line_string.rb +3 -2
- data/lib/rgeo/features/linear_ring.rb +3 -2
- data/lib/rgeo/features/multi_curve.rb +3 -2
- data/lib/rgeo/features/multi_line_string.rb +3 -2
- data/lib/rgeo/features/multi_point.rb +3 -2
- data/lib/rgeo/features/multi_polygon.rb +3 -2
- data/lib/rgeo/features/multi_surface.rb +3 -2
- data/lib/rgeo/features/point.rb +3 -2
- data/lib/rgeo/features/polygon.rb +3 -2
- data/lib/rgeo/features/surface.rb +3 -2
- data/lib/rgeo/features/types.rb +198 -0
- data/lib/rgeo/geography.rb +4 -14
- data/lib/rgeo/geography/factory.rb +7 -64
- data/lib/rgeo/geography/{simple_spherical/geometry_methods.rb → helper.rb} +4 -13
- data/lib/rgeo/geography/simple_mercator/feature_classes.rb +35 -89
- data/lib/rgeo/geography/simple_mercator/feature_methods.rb +22 -31
- data/lib/rgeo/geography/simple_mercator/projector.rb +4 -8
- data/lib/rgeo/geography/simple_spherical/calculations.rb +11 -9
- data/lib/rgeo/geography/simple_spherical/feature_classes.rb +189 -0
- data/lib/rgeo/geography/simple_spherical/{line_string_impl.rb → feature_methods.rb} +16 -64
- data/lib/rgeo/geos/factory.rb +26 -40
- data/lib/rgeo/geos/impl_additions.rb +3 -5
- data/lib/rgeo/{geography/simple_spherical/polygon_impl.rb → impl_helpers.rb} +16 -26
- data/lib/rgeo/impl_helpers/basic_geometry_collection_methods.rb +186 -0
- data/lib/rgeo/impl_helpers/basic_geometry_methods.rb +90 -0
- data/lib/rgeo/impl_helpers/basic_line_string_methods.rb +188 -0
- data/lib/rgeo/impl_helpers/basic_point_methods.rb +149 -0
- data/lib/rgeo/{geography/common/helper.rb → impl_helpers/basic_polygon_methods.rb} +62 -53
- data/lib/rgeo/{geography/common/polygon_methods.rb → impl_helpers/serialization.rb} +50 -42
- data/tests/common/geometry_collection_tests.rb +9 -7
- data/tests/common/multi_line_string_tests.rb +16 -13
- data/tests/common/multi_point_tests.rb +16 -13
- data/tests/common/multi_polygon_tests.rb +8 -6
- data/tests/common/point_tests.rb +1 -2
- data/tests/common/polygon_tests.rb +9 -9
- data/tests/geos/tc_multi_line_string.rb +2 -2
- data/tests/simple_cartesian/tc_calculations.rb +138 -0
- data/tests/simple_cartesian/tc_geometry_collection.rb +68 -0
- data/tests/simple_cartesian/tc_line_string.rb +70 -0
- data/{lib/rgeo/geography/simple_spherical/multi_line_string_impl.rb → tests/simple_cartesian/tc_multi_line_string.rb} +19 -19
- data/{lib/rgeo/geography/simple_spherical/multi_polygon_impl.rb → tests/simple_cartesian/tc_multi_point.rb} +19 -19
- data/{lib/rgeo/geography/common/geometry_methods.rb → tests/simple_cartesian/tc_multi_polygon.rb} +19 -41
- data/{lib/rgeo/geography/simple_spherical/point_impl.rb → tests/simple_cartesian/tc_point.rb} +33 -35
- data/tests/simple_cartesian/tc_polygon.rb +67 -0
- data/tests/simple_spherical/tc_geometry_collection.rb +68 -0
- data/tests/simple_spherical/tc_line_string.rb +10 -171
- data/tests/simple_spherical/tc_multi_line_string.rb +67 -0
- data/{lib/rgeo/geography/simple_spherical/multi_point_impl.rb → tests/simple_spherical/tc_multi_point.rb} +19 -19
- data/tests/simple_spherical/tc_multi_polygon.rb +70 -0
- data/tests/simple_spherical/tc_point.rb +17 -115
- data/tests/simple_spherical/tc_polygon.rb +67 -0
- metadata +46 -18
- data/ext/geos_c_impl/globals.h +0 -58
- data/lib/rgeo/geography/common/geometry_collection_methods.rb +0 -217
- data/lib/rgeo/geography/common/line_string_methods.rb +0 -201
- data/lib/rgeo/geography/common/point_methods.rb +0 -153
@@ -55,12 +55,11 @@ module RGeo
|
|
55
55
|
#
|
56
56
|
# == Notes
|
57
57
|
#
|
58
|
-
# Geometry is defined as a module and is provided primarily
|
59
|
-
#
|
60
|
-
#
|
58
|
+
# Geometry is defined as a module and is provided primarily for the
|
59
|
+
# sake of documentation. Implementations need not necessarily include
|
60
|
+
# this module itself. Therefore, you should not depend on the
|
61
61
|
# kind_of? method to check type. Instead, use the provided check_type
|
62
|
-
# class method
|
63
|
-
# to support case-when constructs.
|
62
|
+
# class method (or === operator) defined in the Type module.
|
64
63
|
#
|
65
64
|
# Some implementations may support higher dimensional objects or
|
66
65
|
# coordinate systems, despite the limits of the SFS.
|
@@ -73,9 +72,11 @@ module RGeo
|
|
73
72
|
# Spatial equivalence is the weakest form of equivalence, indicating
|
74
73
|
# that the two objects represent the same region of space, but may
|
75
74
|
# be different representations of that region. For example, a
|
76
|
-
# POINT(0 0) and a MULTIPOINT(0 0
|
77
|
-
#
|
75
|
+
# POINT(0 0) and a MULTIPOINT(0 0) are spatially equivalent, as are
|
76
|
+
# LINESTRING(0 0, 10 10) and
|
78
77
|
# GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0, 10 10, 0 0)).
|
78
|
+
# As a general rule, objects must have factories that are eql? in
|
79
|
+
# order to be spatially equivalent.
|
79
80
|
# Objective equivalence::
|
80
81
|
# Objective equivalence is a stronger form of equivalence, indicating
|
81
82
|
# that the two objects are the same representation, but may be
|
@@ -84,7 +85,7 @@ module RGeo
|
|
84
85
|
# objectively equivalent. For example, none of the examples in the
|
85
86
|
# spatial equivalence section above are objectively equivalent.
|
86
87
|
# However, two separate objects that both represent POINT(1 2) are
|
87
|
-
# objectively equivalent.
|
88
|
+
# objectively equivalent as well as spatially equivalent.
|
88
89
|
# Objective identity::
|
89
90
|
# Objective identity is the strongest form, indicating that the two
|
90
91
|
# references refer to the same object. Of course, all pairs of
|
@@ -99,30 +100,7 @@ module RGeo
|
|
99
100
|
|
100
101
|
module Geometry
|
101
102
|
|
102
|
-
|
103
|
-
module ClassMethods
|
104
|
-
|
105
|
-
# Returns true if the given object is this type or a subtype
|
106
|
-
# thereof, or if it is a feature object whose geometry_type is
|
107
|
-
# this type or a subtype thereof.
|
108
|
-
#
|
109
|
-
# Note that feature objects need not actually include this module.
|
110
|
-
|
111
|
-
def check_type(rhs_)
|
112
|
-
rhs_ = rhs_.geometry_type if rhs_.respond_to?(:geometry_type)
|
113
|
-
rhs_.kind_of?(::Module) && (rhs_ == self || rhs_.include?(self))
|
114
|
-
end
|
115
|
-
alias_method :===, :check_type
|
116
|
-
|
117
|
-
|
118
|
-
def included(mod_) # :nodoc:
|
119
|
-
mod_.extend(ClassMethods) unless mod_.kind_of?(Class)
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
123
|
-
|
124
|
-
|
125
|
-
extend ClassMethods
|
103
|
+
extend Type
|
126
104
|
|
127
105
|
|
128
106
|
# Returns a factory for creating features related to this one.
|
@@ -58,11 +58,12 @@ module RGeo
|
|
58
58
|
# for the sake of documentation. Implementations need not necessarily
|
59
59
|
# include this module itself. Therefore, you should not depend on the
|
60
60
|
# kind_of? method to check type. Instead, use the provided check_type
|
61
|
-
# class method
|
62
|
-
# to support case-when constructs.
|
61
|
+
# class method (or === operator) defined in the Type module.
|
63
62
|
|
64
63
|
module GeometryCollection
|
65
64
|
|
65
|
+
extend Type
|
66
|
+
|
66
67
|
include Geometry
|
67
68
|
include ::Enumerable
|
68
69
|
|
data/lib/rgeo/features/line.rb
CHANGED
@@ -49,11 +49,12 @@ module RGeo
|
|
49
49
|
# for the sake of documentation. Implementations need not necessarily
|
50
50
|
# include this module itself. Therefore, you should not depend on the
|
51
51
|
# kind_of? method to check type. Instead, use the provided check_type
|
52
|
-
# class method
|
53
|
-
# to support case-when constructs.
|
52
|
+
# class method (or === operator) defined in the Type module.
|
54
53
|
|
55
54
|
module Line
|
56
55
|
|
56
|
+
extend Type
|
57
|
+
|
57
58
|
include LineString
|
58
59
|
|
59
60
|
|
@@ -50,11 +50,12 @@ module RGeo
|
|
50
50
|
# for the sake of documentation. Implementations need not necessarily
|
51
51
|
# include this module itself. Therefore, you should not depend on the
|
52
52
|
# kind_of? method to check type. Instead, use the provided check_type
|
53
|
-
# class method
|
54
|
-
# to support case-when constructs.
|
53
|
+
# class method (or === operator) defined in the Type module.
|
55
54
|
|
56
55
|
module LineString
|
57
56
|
|
57
|
+
extend Type
|
58
|
+
|
58
59
|
include Curve
|
59
60
|
|
60
61
|
|
@@ -49,11 +49,12 @@ module RGeo
|
|
49
49
|
# for the sake of documentation. Implementations need not necessarily
|
50
50
|
# include this module itself. Therefore, you should not depend on the
|
51
51
|
# kind_of? method to check type. Instead, use the provided check_type
|
52
|
-
# class method
|
53
|
-
# to support case-when constructs.
|
52
|
+
# class method (or === operator) defined in the Type module.
|
54
53
|
|
55
54
|
module LinearRing
|
56
55
|
|
56
|
+
extend Type
|
57
|
+
|
57
58
|
include LineString
|
58
59
|
|
59
60
|
|
@@ -67,11 +67,12 @@ module RGeo
|
|
67
67
|
# for the sake of documentation. Implementations need not necessarily
|
68
68
|
# include this module itself. Therefore, you should not depend on the
|
69
69
|
# kind_of? method to check type. Instead, use the provided check_type
|
70
|
-
# class method
|
71
|
-
# to support case-when constructs.
|
70
|
+
# class method (or === operator) defined in the Type module.
|
72
71
|
|
73
72
|
module MultiCurve
|
74
73
|
|
74
|
+
extend Type
|
75
|
+
|
75
76
|
include GeometryCollection
|
76
77
|
|
77
78
|
|
@@ -49,11 +49,12 @@ module RGeo
|
|
49
49
|
# for the sake of documentation. Implementations need not necessarily
|
50
50
|
# include this module itself. Therefore, you should not depend on the
|
51
51
|
# kind_of? method to check type. Instead, use the provided check_type
|
52
|
-
# class method
|
53
|
-
# to support case-when constructs.
|
52
|
+
# class method (or === operator) defined in the Type module.
|
54
53
|
|
55
54
|
module MultiLineString
|
56
55
|
|
56
|
+
extend Type
|
57
|
+
|
57
58
|
include MultiCurve
|
58
59
|
|
59
60
|
|
@@ -56,11 +56,12 @@ module RGeo
|
|
56
56
|
# for the sake of documentation. Implementations need not necessarily
|
57
57
|
# include this module itself. Therefore, you should not depend on the
|
58
58
|
# kind_of? method to check type. Instead, use the provided check_type
|
59
|
-
# class method
|
60
|
-
# to support case-when constructs.
|
59
|
+
# class method (or === operator) defined in the Type module.
|
61
60
|
|
62
61
|
module MultiPoint
|
63
62
|
|
63
|
+
extend Type
|
64
|
+
|
64
65
|
include GeometryCollection
|
65
66
|
|
66
67
|
|
@@ -80,11 +80,12 @@ module RGeo
|
|
80
80
|
# for the sake of documentation. Implementations need not necessarily
|
81
81
|
# include this module itself. Therefore, you should not depend on the
|
82
82
|
# kind_of? method to check type. Instead, use the provided check_type
|
83
|
-
# class method
|
84
|
-
# to support case-when constructs.
|
83
|
+
# class method (or === operator) defined in the Type module.
|
85
84
|
|
86
85
|
module MultiPolygon
|
87
86
|
|
87
|
+
extend Type
|
88
|
+
|
88
89
|
include MultiSurface
|
89
90
|
|
90
91
|
|
@@ -58,11 +58,12 @@ module RGeo
|
|
58
58
|
# for the sake of documentation. Implementations need not necessarily
|
59
59
|
# include this module itself. Therefore, you should not depend on the
|
60
60
|
# kind_of? method to check type. Instead, use the provided check_type
|
61
|
-
# class method
|
62
|
-
# to support case-when constructs.
|
61
|
+
# class method (or === operator) defined in the Type module.
|
63
62
|
|
64
63
|
module MultiSurface
|
65
64
|
|
65
|
+
extend Type
|
66
|
+
|
66
67
|
include GeometryCollection
|
67
68
|
|
68
69
|
|
data/lib/rgeo/features/point.rb
CHANGED
@@ -53,13 +53,14 @@ module RGeo
|
|
53
53
|
# for the sake of documentation. Implementations need not necessarily
|
54
54
|
# include this module itself. Therefore, you should not depend on the
|
55
55
|
# kind_of? method to check type. Instead, use the provided check_type
|
56
|
-
# class method
|
57
|
-
# to support case-when constructs.
|
56
|
+
# class method (or === operator) defined in the Type module.
|
58
57
|
#
|
59
58
|
# Some implementations may support higher dimensional points.
|
60
59
|
|
61
60
|
module Point
|
62
61
|
|
62
|
+
extend Type
|
63
|
+
|
63
64
|
include Geometry
|
64
65
|
|
65
66
|
|
@@ -75,11 +75,12 @@ module RGeo
|
|
75
75
|
# for the sake of documentation. Implementations need not necessarily
|
76
76
|
# include this module itself. Therefore, you should not depend on the
|
77
77
|
# kind_of? method to check type. Instead, use the provided check_type
|
78
|
-
# class method
|
79
|
-
# to support case-when constructs.
|
78
|
+
# class method (or === operator) defined in the Type module.
|
80
79
|
|
81
80
|
module Polygon
|
82
81
|
|
82
|
+
extend Type
|
83
|
+
|
83
84
|
include Surface
|
84
85
|
include ::Enumerable
|
85
86
|
|
@@ -62,13 +62,14 @@ module RGeo
|
|
62
62
|
# for the sake of documentation. Implementations need not necessarily
|
63
63
|
# include this module itself. Therefore, you should not depend on the
|
64
64
|
# kind_of? method to check type. Instead, use the provided check_type
|
65
|
-
# class method
|
66
|
-
# to support case-when constructs.
|
65
|
+
# class method (or === operator) defined in the Type module.
|
67
66
|
#
|
68
67
|
# Some implementations may support higher dimensional points.
|
69
68
|
|
70
69
|
module Surface
|
71
70
|
|
71
|
+
extend Type
|
72
|
+
|
72
73
|
include Geometry
|
73
74
|
|
74
75
|
|
@@ -0,0 +1,198 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Feature type management and casting
|
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 Features
|
40
|
+
|
41
|
+
|
42
|
+
# These methods are available as class methods (not instance methods)
|
43
|
+
# of the various feature types.
|
44
|
+
# For example, you may determine whether a feature object is a
|
45
|
+
# point by calling:
|
46
|
+
#
|
47
|
+
# ::RGeo::Features::Point.check_type(object)
|
48
|
+
#
|
49
|
+
# A corresponding === operator is provided so you can use the type
|
50
|
+
# modules in a case-when clause.
|
51
|
+
#
|
52
|
+
# You may also use the presence of this module to determine whether
|
53
|
+
# a particular object is a feature type:
|
54
|
+
#
|
55
|
+
# object.kind_of?(::RGeo::Features::Type)
|
56
|
+
|
57
|
+
module Type
|
58
|
+
|
59
|
+
|
60
|
+
# All geometry implementations MUST include this submodule.
|
61
|
+
# This serves as a marker that may be used to test an object for
|
62
|
+
# feature-ness.
|
63
|
+
|
64
|
+
module Instance
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
# Returns true if the given object is this type or a subtype
|
69
|
+
# thereof, or if it is a feature object whose geometry_type is
|
70
|
+
# this type or a subtype thereof.
|
71
|
+
#
|
72
|
+
# Note that feature objects need not actually include this module.
|
73
|
+
|
74
|
+
def check_type(rhs_)
|
75
|
+
rhs_ = rhs_.geometry_type if rhs_.kind_of?(Instance)
|
76
|
+
rhs_.kind_of?(Type) && (rhs_ == self || rhs_.include?(self))
|
77
|
+
end
|
78
|
+
alias_method :===, :check_type
|
79
|
+
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
class << self
|
85
|
+
|
86
|
+
|
87
|
+
# Cast the given object according to the given parameters.
|
88
|
+
#
|
89
|
+
# You may optionally pass a factory, a feature type, and the value
|
90
|
+
# <tt>:force_new</tt> as the parameters. The given object will be
|
91
|
+
# casted into the given factory and feature type, if possible.
|
92
|
+
# If the cast is not possible to accomplish, nil is returned.
|
93
|
+
# If the factory or type is not provided, or is the same as the
|
94
|
+
# object's current attribute, that attribute is not modified.
|
95
|
+
#
|
96
|
+
# Normally, if neither the factory nor the type are set to be
|
97
|
+
# modified, the original object is returned. However, you may cause
|
98
|
+
# cast to return a duplicate of the original object by passing
|
99
|
+
# <tt>:force_new</tt> as one of the parameters. This effectively
|
100
|
+
# forces cast always to return either a new object or nil.
|
101
|
+
#
|
102
|
+
# RGeo provides a default casting algorithm. Individual feature
|
103
|
+
# implementation factories may override this and customize the
|
104
|
+
# casting behavior by defining the override_cast method. See
|
105
|
+
# ::RGeo::Features::Factory#override_cast for more details.
|
106
|
+
|
107
|
+
def cast(obj_, *params_)
|
108
|
+
# Interpret params
|
109
|
+
nfactory_ = factory_ = obj_.factory
|
110
|
+
ntype_ = type_ = obj_.geometry_type
|
111
|
+
force_new_ = nil
|
112
|
+
keep_subtype_ = nil
|
113
|
+
params_.each do |param_|
|
114
|
+
case param_
|
115
|
+
when Factory::Instance
|
116
|
+
nfactory_ = param_
|
117
|
+
when Geometry
|
118
|
+
ntype_ = param_
|
119
|
+
when :force_new
|
120
|
+
force_new_ = param_
|
121
|
+
when :keep_subtype
|
122
|
+
keep_subtype_ = param_
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Let the factory override
|
127
|
+
if nfactory_.respond_to?(:override_cast)
|
128
|
+
override_ = nfactory_.override_cast(obj_, ntype_, keep_subtype_, force_new_)
|
129
|
+
return override_ unless override_ == false
|
130
|
+
end
|
131
|
+
|
132
|
+
# Default algorithm
|
133
|
+
ntype_ = type_ if keep_subtype_ && type_.include?(ntype_)
|
134
|
+
if nfactory_ == factory_ && ntype_ == type_
|
135
|
+
force_new_ ? obj_.dup : obj_
|
136
|
+
elsif ntype_ == type_
|
137
|
+
if type_ == Point
|
138
|
+
nfactory_.point(obj_.x, obj_.y)
|
139
|
+
elsif type_ == Line
|
140
|
+
nfactory_.line(obj_.start_point, obj_.end_point)
|
141
|
+
elsif type_ == LinearRing
|
142
|
+
nfactory_.linear_ring(obj_.points)
|
143
|
+
elsif type_ == LineString
|
144
|
+
nfactory_.line_string(obj_.points)
|
145
|
+
elsif type_ == Polygon
|
146
|
+
nfactory_.polygon(obj_.exterior_ring, obj_.interior_rings)
|
147
|
+
elsif type_ == MultiPoint
|
148
|
+
nfactory_.multi_point(obj_)
|
149
|
+
elsif type_ == MultiLineString
|
150
|
+
nfactory_.multi_line_string(obj_)
|
151
|
+
elsif type_ == MultiPolygon
|
152
|
+
nfactory_.multi_polygon(obj_)
|
153
|
+
elsif type_ == GeometryCollection
|
154
|
+
nfactory_.collection(obj_)
|
155
|
+
else
|
156
|
+
nil
|
157
|
+
end
|
158
|
+
else
|
159
|
+
if ntype_ == Point && (type_ == MultiPoint || type_ == GeometryCollection) ||
|
160
|
+
(ntype_ == Line || ntype_ == LineString || ntype_ == LinearRing) && (type_ == MultiLineString || type_ == GeometryCollection) ||
|
161
|
+
ntype_ == Polygon && (type_ == MultiPolygon || type_ == GeometryCollection)
|
162
|
+
then
|
163
|
+
if obj_.num_geometries == 1
|
164
|
+
cast(obj_.geometry_n(0), nfactory_, ntype_, keep_subtype_, force_new_)
|
165
|
+
else
|
166
|
+
nil
|
167
|
+
end
|
168
|
+
elsif ntype_ == Line && type_ == LineString
|
169
|
+
if obj_.num_points == 2
|
170
|
+
nfactory_.line(obj_.point_n(0), obj_.point_n(1))
|
171
|
+
else
|
172
|
+
nil
|
173
|
+
end
|
174
|
+
elsif ntype_ == LinearRing && type_ == LineString
|
175
|
+
nfactory_.linear_ring(obj_.points)
|
176
|
+
elsif ntype_ == LineString && (type_ == Line || type_ == LinearRing)
|
177
|
+
nfactory_.line_string(obj_.points)
|
178
|
+
elsif ntype_ == MultiPoint && type_ == GeometryCollection
|
179
|
+
nfactory_.multi_point(obj_)
|
180
|
+
elsif ntype_ == MultiLineString && type_ == GeometryCollection
|
181
|
+
nfactory_.multi_line_string(obj_)
|
182
|
+
elsif ntype_ == MultiPolygon && type_ == GeometryCollection
|
183
|
+
nfactory_.multi_polygon(obj_)
|
184
|
+
elsif ntype_ == GeometryCollection && (type_ == MultiPoint || type_ == MultiLineString || type_ == MultiPolygon)
|
185
|
+
nfactory_.collection(obj_)
|
186
|
+
else
|
187
|
+
nil
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|