rgeo 0.3.3 → 0.3.4
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 +6 -0
- data/README.rdoc +1 -1
- data/Version +1 -1
- data/ext/geos_c_impl/extconf.rb +13 -13
- data/ext/geos_c_impl/factory.c +30 -18
- data/ext/geos_c_impl/factory.h +18 -12
- data/ext/geos_c_impl/geometry.c +11 -11
- data/ext/geos_c_impl/geometry.h +7 -7
- data/ext/geos_c_impl/geometry_collection.c +15 -15
- data/ext/geos_c_impl/geometry_collection.h +8 -8
- data/ext/geos_c_impl/line_string.c +14 -14
- data/ext/geos_c_impl/line_string.h +7 -7
- data/ext/geos_c_impl/main.c +7 -7
- data/ext/geos_c_impl/point.c +9 -9
- data/ext/geos_c_impl/point.h +7 -7
- data/ext/geos_c_impl/polygon.c +9 -9
- data/ext/geos_c_impl/polygon.h +7 -7
- data/ext/geos_c_impl/preface.h +7 -7
- data/ext/proj4_c_impl/extconf.rb +13 -13
- data/ext/proj4_c_impl/main.c +12 -12
- data/lib/rgeo.rb +26 -26
- data/lib/rgeo/cartesian.rb +12 -12
- data/lib/rgeo/cartesian/analysis.rb +26 -26
- data/lib/rgeo/cartesian/bounding_box.rb +83 -83
- data/lib/rgeo/cartesian/calculations.rb +36 -36
- data/lib/rgeo/cartesian/factory.rb +78 -78
- data/lib/rgeo/cartesian/feature_classes.rb +74 -74
- data/lib/rgeo/cartesian/feature_methods.rb +34 -34
- data/lib/rgeo/cartesian/interface.rb +33 -33
- data/lib/rgeo/coord_sys.rb +15 -15
- data/lib/rgeo/coord_sys/cs/entities.rb +533 -534
- data/lib/rgeo/coord_sys/cs/factories.rb +69 -69
- data/lib/rgeo/coord_sys/cs/wkt_parser.rb +44 -44
- data/lib/rgeo/coord_sys/proj4.rb +85 -85
- data/lib/rgeo/coord_sys/srs_database/active_record_table.rb +31 -31
- data/lib/rgeo/coord_sys/srs_database/interface.rb +44 -44
- data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +31 -31
- data/lib/rgeo/coord_sys/srs_database/sr_org.rb +31 -31
- data/lib/rgeo/coord_sys/srs_database/url_reader.rb +29 -29
- data/lib/rgeo/error.rb +17 -17
- data/lib/rgeo/feature.rb +15 -15
- data/lib/rgeo/feature/curve.rb +58 -58
- data/lib/rgeo/feature/factory.rb +84 -84
- data/lib/rgeo/feature/factory_generator.rb +32 -32
- data/lib/rgeo/feature/geometry.rb +215 -215
- data/lib/rgeo/feature/geometry_collection.rb +46 -46
- data/lib/rgeo/feature/line.rb +21 -21
- data/lib/rgeo/feature/line_string.rb +35 -35
- data/lib/rgeo/feature/linear_ring.rb +20 -20
- data/lib/rgeo/feature/mixins.rb +61 -61
- data/lib/rgeo/feature/multi_curve.rb +37 -37
- data/lib/rgeo/feature/multi_line_string.rb +20 -20
- data/lib/rgeo/feature/multi_point.rb +22 -22
- data/lib/rgeo/feature/multi_polygon.rb +28 -28
- data/lib/rgeo/feature/multi_surface.rb +39 -39
- data/lib/rgeo/feature/point.rb +42 -42
- data/lib/rgeo/feature/polygon.rb +50 -50
- data/lib/rgeo/feature/surface.rb +42 -42
- data/lib/rgeo/feature/types.rb +58 -58
- data/lib/rgeo/geographic.rb +14 -14
- data/lib/rgeo/geographic/factory.rb +87 -87
- data/lib/rgeo/geographic/interface.rb +55 -55
- data/lib/rgeo/geographic/proj4_projector.rb +35 -35
- data/lib/rgeo/geographic/projected_feature_classes.rb +95 -95
- data/lib/rgeo/geographic/projected_feature_methods.rb +81 -81
- data/lib/rgeo/geographic/projected_window.rb +103 -103
- data/lib/rgeo/geographic/simple_mercator_projector.rb +32 -32
- data/lib/rgeo/geographic/spherical_feature_classes.rb +93 -93
- data/lib/rgeo/geographic/spherical_feature_methods.rb +25 -25
- data/lib/rgeo/geographic/spherical_math.rb +58 -58
- data/lib/rgeo/geos.rb +22 -17
- data/lib/rgeo/geos/factory.rb +93 -93
- data/lib/rgeo/geos/ffi_classes.rb +306 -231
- data/lib/rgeo/geos/ffi_factory.rb +100 -96
- data/lib/rgeo/geos/impl_additions.rb +22 -22
- data/lib/rgeo/geos/interface.rb +45 -45
- data/lib/rgeo/geos/zm_factory.rb +90 -90
- data/lib/rgeo/geos/zm_impl.rb +167 -167
- data/lib/rgeo/impl_helper.rb +11 -11
- data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +71 -71
- data/lib/rgeo/impl_helper/basic_geometry_methods.rb +29 -29
- data/lib/rgeo/impl_helper/basic_line_string_methods.rb +61 -61
- data/lib/rgeo/impl_helper/basic_point_methods.rb +43 -43
- data/lib/rgeo/impl_helper/basic_polygon_methods.rb +35 -35
- data/lib/rgeo/impl_helper/math.rb +13 -13
- data/lib/rgeo/version.rb +10 -10
- data/lib/rgeo/wkrep.rb +16 -16
- data/lib/rgeo/wkrep/wkb_generator.rb +51 -51
- data/lib/rgeo/wkrep/wkb_parser.rb +52 -52
- data/lib/rgeo/wkrep/wkt_generator.rb +51 -51
- data/lib/rgeo/wkrep/wkt_parser.rb +66 -66
- data/lib/rgeo/yaml.rb +14 -14
- data/test/common/geometry_collection_tests.rb +53 -53
- data/test/common/line_string_tests.rb +57 -57
- data/test/common/multi_line_string_tests.rb +43 -43
- data/test/common/multi_point_tests.rb +43 -43
- data/test/common/multi_polygon_tests.rb +43 -43
- data/test/common/point_tests.rb +75 -75
- data/test/common/polygon_tests.rb +37 -37
- data/test/coord_sys/tc_active_record_table.rb +25 -25
- data/test/coord_sys/tc_ogc_cs.rb +72 -72
- data/test/coord_sys/tc_proj4.rb +51 -51
- data/test/coord_sys/tc_proj4_srs_data.rb +17 -17
- data/test/coord_sys/tc_sr_org.rb +15 -15
- data/test/coord_sys/tc_url_reader.rb +19 -19
- data/test/geos_capi/tc_factory.rb +21 -21
- data/test/geos_capi/tc_geometry_collection.rb +15 -15
- data/test/geos_capi/tc_line_string.rb +15 -15
- data/test/geos_capi/tc_misc.rb +33 -22
- data/test/geos_capi/tc_multi_line_string.rb +15 -15
- data/test/geos_capi/tc_multi_point.rb +15 -15
- data/test/geos_capi/tc_multi_polygon.rb +15 -15
- data/test/geos_capi/tc_parsing_unparsing.rb +19 -19
- data/test/geos_capi/tc_point.rb +21 -21
- data/test/geos_capi/tc_polygon.rb +19 -19
- data/test/geos_capi/tc_zmfactory.rb +17 -17
- data/test/geos_ffi/tc_factory.rb +21 -21
- data/test/geos_ffi/tc_geometry_collection.rb +15 -15
- data/test/geos_ffi/tc_line_string.rb +15 -15
- data/test/geos_ffi/tc_misc.rb +49 -15
- data/test/geos_ffi/tc_multi_line_string.rb +15 -15
- data/test/geos_ffi/tc_multi_point.rb +15 -15
- data/test/geos_ffi/tc_multi_polygon.rb +15 -15
- data/test/geos_ffi/tc_parsing_unparsing.rb +19 -19
- data/test/geos_ffi/tc_point.rb +21 -21
- data/test/geos_ffi/tc_polygon.rb +19 -19
- data/test/geos_ffi/tc_zmfactory.rb +17 -17
- data/test/projected_geographic/tc_geometry_collection.rb +15 -15
- data/test/projected_geographic/tc_line_string.rb +15 -15
- data/test/projected_geographic/tc_multi_line_string.rb +15 -15
- data/test/projected_geographic/tc_multi_point.rb +15 -15
- data/test/projected_geographic/tc_multi_polygon.rb +15 -15
- data/test/projected_geographic/tc_point.rb +23 -23
- data/test/projected_geographic/tc_polygon.rb +15 -15
- data/test/simple_cartesian/tc_calculations.rb +31 -31
- data/test/simple_cartesian/tc_geometry_collection.rb +17 -17
- data/test/simple_cartesian/tc_line_string.rb +17 -17
- data/test/simple_cartesian/tc_multi_line_string.rb +17 -17
- data/test/simple_cartesian/tc_multi_point.rb +17 -17
- data/test/simple_cartesian/tc_multi_polygon.rb +17 -17
- data/test/simple_cartesian/tc_point.rb +21 -21
- data/test/simple_cartesian/tc_polygon.rb +17 -17
- data/test/simple_mercator/tc_geometry_collection.rb +15 -15
- data/test/simple_mercator/tc_line_string.rb +15 -15
- data/test/simple_mercator/tc_multi_line_string.rb +15 -15
- data/test/simple_mercator/tc_multi_point.rb +15 -15
- data/test/simple_mercator/tc_multi_polygon.rb +15 -15
- data/test/simple_mercator/tc_point.rb +23 -23
- data/test/simple_mercator/tc_polygon.rb +15 -15
- data/test/simple_mercator/tc_window.rb +50 -50
- data/test/spherical_geographic/tc_calculations.rb +47 -47
- data/test/spherical_geographic/tc_geometry_collection.rb +17 -17
- data/test/spherical_geographic/tc_line_string.rb +17 -17
- data/test/spherical_geographic/tc_multi_line_string.rb +17 -17
- data/test/spherical_geographic/tc_multi_point.rb +17 -17
- data/test/spherical_geographic/tc_multi_polygon.rb +17 -17
- data/test/spherical_geographic/tc_point.rb +23 -23
- data/test/spherical_geographic/tc_polygon.rb +17 -17
- data/test/tc_cartesian_analysis.rb +23 -23
- data/test/tc_mixins.rb +39 -39
- data/test/tc_oneoff.rb +15 -15
- data/test/tc_types.rb +17 -17
- data/test/wkrep/tc_wkb_generator.rb +67 -67
- data/test/wkrep/tc_wkb_parser.rb +73 -73
- data/test/wkrep/tc_wkt_generator.rb +75 -75
- data/test/wkrep/tc_wkt_parser.rb +97 -97
- metadata +3 -3
data/lib/rgeo/feature/polygon.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Polygon feature interface
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010 Daniel Azuma
|
7
|
-
#
|
6
|
+
# Copyright 2010-2012 Daniel Azuma
|
7
|
+
#
|
8
8
|
# All rights reserved.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# Redistribution and use in source and binary forms, with or without
|
11
11
|
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# * Redistributions of source code must retain the above copyright notice,
|
14
14
|
# this list of conditions and the following disclaimer.
|
15
15
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# * Neither the name of the copyright holder, nor the names of any other
|
19
19
|
# contributors to this software, may be used to endorse or promote products
|
20
20
|
# derived from this software without specific prior written permission.
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
23
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
24
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
@@ -35,106 +35,106 @@
|
|
35
35
|
|
36
36
|
|
37
37
|
module RGeo
|
38
|
-
|
38
|
+
|
39
39
|
module Feature
|
40
|
-
|
41
|
-
|
40
|
+
|
41
|
+
|
42
42
|
# == SFS 1.1 Description
|
43
|
-
#
|
43
|
+
#
|
44
44
|
# A Polygon is a planar Surface defined by 1 exterior boundary and 0 or
|
45
45
|
# more interior boundaries. Each interior boundary defines a hole in
|
46
46
|
# the Polygon.
|
47
|
-
#
|
47
|
+
#
|
48
48
|
# The assertions for Polygons (the rules that define valid Polygons)
|
49
49
|
# are as follows:
|
50
|
-
#
|
50
|
+
#
|
51
51
|
# (a) Polygons are topologically closed;
|
52
|
-
#
|
52
|
+
#
|
53
53
|
# (b) The boundary of a Polygon consists of a set of LinearRings that
|
54
54
|
# make up its exterior and interior boundaries;
|
55
|
-
#
|
55
|
+
#
|
56
56
|
# (c) No two Rings in the boundary cross and the Rings in the boundary
|
57
57
|
# of a Polygon may intersect at a Point but only as a tangent;
|
58
|
-
#
|
58
|
+
#
|
59
59
|
# (d) A Polygon may not have cut lines, spikes or punctures;
|
60
|
-
#
|
60
|
+
#
|
61
61
|
# (e) The interior of every Polygon is a connected point set;
|
62
|
-
#
|
62
|
+
#
|
63
63
|
# (f) The exterior of a Polygon with 1 or more holes is not connected.
|
64
64
|
# Each hole defines a connected component of the exterior.
|
65
|
-
#
|
65
|
+
#
|
66
66
|
# In the above assertions, interior, closure and exterior have the
|
67
67
|
# standard topological definitions. The combination of (a) and (c) make
|
68
68
|
# a Polygon a regular closed Point set.
|
69
|
-
#
|
69
|
+
#
|
70
70
|
# Polygons are simple geometric objects.
|
71
|
-
#
|
71
|
+
#
|
72
72
|
# == Notes
|
73
|
-
#
|
73
|
+
#
|
74
74
|
# Polygon is defined as a module and is provided primarily
|
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
78
|
# class method (or === operator) defined in the Type module.
|
79
|
-
|
79
|
+
|
80
80
|
module Polygon
|
81
|
-
|
81
|
+
|
82
82
|
include Surface
|
83
83
|
extend Type
|
84
|
-
|
85
|
-
|
84
|
+
|
85
|
+
|
86
86
|
# === SFS 1.1 Description
|
87
|
-
#
|
87
|
+
#
|
88
88
|
# Returns the exterior ring of this Polygon.
|
89
|
-
#
|
89
|
+
#
|
90
90
|
# === Notes
|
91
|
-
#
|
91
|
+
#
|
92
92
|
# Returns an object that supports the LinearRing interface.
|
93
|
-
|
93
|
+
|
94
94
|
def exterior_ring
|
95
95
|
raise Error::UnsupportedOperation, "Method Polygon#exterior_ring not defined."
|
96
96
|
end
|
97
|
-
|
98
|
-
|
97
|
+
|
98
|
+
|
99
99
|
# === SFS 1.1 Description
|
100
|
-
#
|
100
|
+
#
|
101
101
|
# Returns the number of interiorRings in this Polygon.
|
102
|
-
#
|
102
|
+
#
|
103
103
|
# === Notes
|
104
|
-
#
|
104
|
+
#
|
105
105
|
# Returns an integer.
|
106
|
-
|
106
|
+
|
107
107
|
def num_interior_rings
|
108
108
|
raise Error::UnsupportedOperation, "Method Polygon#num_interior_rings not defined."
|
109
109
|
end
|
110
|
-
|
111
|
-
|
110
|
+
|
111
|
+
|
112
112
|
# === SFS 1.1 Description
|
113
|
-
#
|
113
|
+
#
|
114
114
|
# Returns the Nth interiorRing for this Polygon as a LineString.
|
115
|
-
#
|
115
|
+
#
|
116
116
|
# === Notes
|
117
|
-
#
|
117
|
+
#
|
118
118
|
# Returns an object that supports the LinearRing interface, or nil
|
119
119
|
# if the given N is out of range. N is zero-based.
|
120
120
|
# Does not support negative indexes.
|
121
|
-
|
121
|
+
|
122
122
|
def interior_ring_n(n_)
|
123
123
|
raise Error::UnsupportedOperation, "Method Polygon#interior_ring_n not defined."
|
124
124
|
end
|
125
|
-
|
126
|
-
|
125
|
+
|
126
|
+
|
127
127
|
# Returns the interior rings as a (possibly empty) array of objects
|
128
128
|
# that support the LinearRing interface.
|
129
|
-
|
129
|
+
|
130
130
|
def interior_rings
|
131
131
|
raise Error::UnsupportedOperation, "Method Polygon#interior_rings not defined."
|
132
132
|
end
|
133
|
-
|
134
|
-
|
133
|
+
|
134
|
+
|
135
135
|
end
|
136
|
-
|
137
|
-
|
136
|
+
|
137
|
+
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
end
|
data/lib/rgeo/feature/surface.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Surface feature interface
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010 Daniel Azuma
|
7
|
-
#
|
6
|
+
# Copyright 2010-2012 Daniel Azuma
|
7
|
+
#
|
8
8
|
# All rights reserved.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# Redistribution and use in source and binary forms, with or without
|
11
11
|
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# * Redistributions of source code must retain the above copyright notice,
|
14
14
|
# this list of conditions and the following disclaimer.
|
15
15
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# * Neither the name of the copyright holder, nor the names of any other
|
19
19
|
# contributors to this software, may be used to endorse or promote products
|
20
20
|
# derived from this software without specific prior written permission.
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
23
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
24
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
@@ -35,87 +35,87 @@
|
|
35
35
|
|
36
36
|
|
37
37
|
module RGeo
|
38
|
-
|
38
|
+
|
39
39
|
module Feature
|
40
|
-
|
41
|
-
|
40
|
+
|
41
|
+
|
42
42
|
# == SFS 1.1 Description
|
43
|
-
#
|
43
|
+
#
|
44
44
|
# A Surface is a 2-dimensional geometric object.
|
45
|
-
#
|
45
|
+
#
|
46
46
|
# A simple Surface consists of a single "patch" that is associated with
|
47
47
|
# one "exterior boundary" and 0 or more "interior" boundaries. Simple
|
48
48
|
# Surfaces in 3-dimensional space are isomorphic to planar Surfaces.
|
49
49
|
# Polyhedral Surfaces are formed by "stitching" together simple
|
50
50
|
# Surfaces along their boundaries, polyhedral Surfaces in 3-dimensional
|
51
51
|
# space may not be planar as a whole.
|
52
|
-
#
|
52
|
+
#
|
53
53
|
# The boundary of a simple Surface is the set of closed Curves
|
54
54
|
# corresponding to its "exterior" and "interior" boundaries.
|
55
|
-
#
|
55
|
+
#
|
56
56
|
# The only instantiable subclass of Surface defined in this
|
57
57
|
# specification, Polygon, is a simple Surface that is planar.
|
58
|
-
#
|
58
|
+
#
|
59
59
|
# == Notes
|
60
|
-
#
|
60
|
+
#
|
61
61
|
# Surface is defined as a module and is provided primarily
|
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
65
|
# class method (or === operator) defined in the Type module.
|
66
|
-
#
|
66
|
+
#
|
67
67
|
# Some implementations may support higher dimensional points.
|
68
|
-
|
68
|
+
|
69
69
|
module Surface
|
70
|
-
|
70
|
+
|
71
71
|
include Geometry
|
72
72
|
extend Type
|
73
|
-
|
74
|
-
|
73
|
+
|
74
|
+
|
75
75
|
# === SFS 1.1 Description
|
76
|
-
#
|
76
|
+
#
|
77
77
|
# The area of this Surface, as measured in the spatial reference
|
78
78
|
# system of this Surface.
|
79
|
-
#
|
79
|
+
#
|
80
80
|
# === Notes
|
81
|
-
#
|
81
|
+
#
|
82
82
|
# Returns a floating-point scalar value.
|
83
|
-
|
83
|
+
|
84
84
|
def area
|
85
85
|
raise Error::UnsupportedOperation, "Method Surface#area not defined."
|
86
86
|
end
|
87
|
-
|
88
|
-
|
87
|
+
|
88
|
+
|
89
89
|
# === SFS 1.1 Description
|
90
|
-
#
|
90
|
+
#
|
91
91
|
# The mathematical centroid for this Surface as a Point. The result
|
92
92
|
# is not guaranteed to be on this Surface.
|
93
|
-
#
|
93
|
+
#
|
94
94
|
# === Notes
|
95
|
-
#
|
95
|
+
#
|
96
96
|
# Returns an object that supports the Point interface.
|
97
|
-
|
97
|
+
|
98
98
|
def centroid
|
99
99
|
raise Error::UnsupportedOperation, "Method Surface#centroid not defined."
|
100
100
|
end
|
101
|
-
|
102
|
-
|
101
|
+
|
102
|
+
|
103
103
|
# === SFS 1.1 Description
|
104
|
-
#
|
104
|
+
#
|
105
105
|
# A Point guaranteed to be on this Surface.
|
106
|
-
#
|
106
|
+
#
|
107
107
|
# === Notes
|
108
|
-
#
|
108
|
+
#
|
109
109
|
# Returns an object that supports the Point interface.
|
110
|
-
|
110
|
+
|
111
111
|
def point_on_surface
|
112
112
|
raise Error::UnsupportedOperation, "Method Surface#point_on_surface not defined."
|
113
113
|
end
|
114
|
-
|
115
|
-
|
114
|
+
|
115
|
+
|
116
116
|
end
|
117
|
-
|
118
|
-
|
117
|
+
|
118
|
+
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
end
|
data/lib/rgeo/feature/types.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Feature type management and casting
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010 Daniel Azuma
|
7
|
-
#
|
6
|
+
# Copyright 2010-2012 Daniel Azuma
|
7
|
+
#
|
8
8
|
# All rights reserved.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# Redistribution and use in source and binary forms, with or without
|
11
11
|
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# * Redistributions of source code must retain the above copyright notice,
|
14
14
|
# this list of conditions and the following disclaimer.
|
15
15
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# * Neither the name of the copyright holder, nor the names of any other
|
19
19
|
# contributors to this software, may be used to endorse or promote products
|
20
20
|
# derived from this software without specific prior written permission.
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
23
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
24
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
@@ -35,108 +35,108 @@
|
|
35
35
|
|
36
36
|
|
37
37
|
module RGeo
|
38
|
-
|
38
|
+
|
39
39
|
module Feature
|
40
|
-
|
41
|
-
|
40
|
+
|
41
|
+
|
42
42
|
# All geometry implementations MUST include this submodule.
|
43
43
|
# This serves as a marker that may be used to test an object for
|
44
44
|
# feature-ness.
|
45
|
-
|
45
|
+
|
46
46
|
module Instance
|
47
47
|
end
|
48
|
-
|
49
|
-
|
48
|
+
|
49
|
+
|
50
50
|
# These methods are available as module methods (not instance methods)
|
51
51
|
# of the various feature types.
|
52
52
|
# For example, you may determine whether a feature object is a
|
53
53
|
# point by calling:
|
54
|
-
#
|
54
|
+
#
|
55
55
|
# ::RGeo::Feature::Point.check_type(object)
|
56
|
-
#
|
56
|
+
#
|
57
57
|
# A corresponding === operator is provided so you can use the type
|
58
58
|
# modules in a case-when clause.
|
59
|
-
#
|
59
|
+
#
|
60
60
|
# You may also use the presence of this module to determine whether
|
61
61
|
# a particular object is a feature type:
|
62
|
-
#
|
62
|
+
#
|
63
63
|
# object.kind_of?(::RGeo::Feature::Type)
|
64
|
-
|
64
|
+
|
65
65
|
module Type
|
66
|
-
|
67
|
-
|
66
|
+
|
67
|
+
|
68
68
|
# Deprecated alias for RGeo::Feature::Instance
|
69
69
|
Instance = Feature::Instance
|
70
|
-
|
71
|
-
|
70
|
+
|
71
|
+
|
72
72
|
# Returns true if the given object is this type or a subtype
|
73
73
|
# thereof, or if it is a feature object whose geometry_type is
|
74
74
|
# this type or a subtype thereof.
|
75
|
-
#
|
75
|
+
#
|
76
76
|
# Note that feature objects need not actually include this module.
|
77
|
-
|
77
|
+
|
78
78
|
def check_type(rhs_)
|
79
79
|
rhs_ = rhs_.geometry_type if rhs_.kind_of?(Feature::Instance)
|
80
80
|
rhs_.kind_of?(Type) && (rhs_ == self || rhs_.include?(self))
|
81
81
|
end
|
82
82
|
alias_method :===, :check_type
|
83
|
-
|
84
|
-
|
83
|
+
|
84
|
+
|
85
85
|
# Returns true if this type is the same type or a subtype of the
|
86
86
|
# given type.
|
87
|
-
|
87
|
+
|
88
88
|
def subtype_of?(type_)
|
89
89
|
self == type_ || self.include?(type_)
|
90
90
|
end
|
91
|
-
|
92
|
-
|
91
|
+
|
92
|
+
|
93
93
|
# Returns the supertype of this type. The supertype of Geometry
|
94
94
|
# is nil.
|
95
|
-
|
95
|
+
|
96
96
|
def supertype
|
97
97
|
@supertype
|
98
98
|
end
|
99
|
-
|
100
|
-
|
99
|
+
|
100
|
+
|
101
101
|
# Iterates over the known immediate subtypes of this type.
|
102
|
-
|
102
|
+
|
103
103
|
def each_immediate_subtype(&block_)
|
104
104
|
@subtypes.each(&block_) if @subtypes
|
105
105
|
end
|
106
|
-
|
107
|
-
|
106
|
+
|
107
|
+
|
108
108
|
# Returns the OpenGIS type name of this type.
|
109
|
-
|
109
|
+
|
110
110
|
def type_name
|
111
111
|
self.name.sub('RGeo::Feature::', '')
|
112
112
|
end
|
113
|
-
|
114
|
-
|
113
|
+
|
114
|
+
|
115
115
|
def _add_subtype(type_) # :nodoc:
|
116
116
|
(@subtypes ||= []) << type_
|
117
117
|
end
|
118
|
-
|
119
|
-
|
118
|
+
|
119
|
+
|
120
120
|
def self.extended(type_) # :nodoc:
|
121
121
|
supertype_ = type_.included_modules.find{ |m_| m_.kind_of?(self) }
|
122
122
|
type_.instance_variable_set(:@supertype, supertype_)
|
123
123
|
supertype_._add_subtype(type_) if supertype_
|
124
124
|
end
|
125
|
-
|
126
|
-
|
125
|
+
|
126
|
+
|
127
127
|
end
|
128
|
-
|
129
|
-
|
128
|
+
|
129
|
+
|
130
130
|
class << self
|
131
|
-
|
132
|
-
|
131
|
+
|
132
|
+
|
133
133
|
# Cast the given object according to the given parameters, if
|
134
134
|
# possible, and return the resulting object. If the requested cast
|
135
135
|
# is not possible, nil is returned.
|
136
|
-
#
|
136
|
+
#
|
137
137
|
# Parameters may be provided as a hash, or as separate arguments.
|
138
138
|
# Hash keys are as follows:
|
139
|
-
#
|
139
|
+
#
|
140
140
|
# [<tt>:factory</tt>]
|
141
141
|
# Set the factory to the given factory. If this argument is not
|
142
142
|
# given, the original object's factory is kept.
|
@@ -172,16 +172,16 @@ module RGeo
|
|
172
172
|
# passed as symbols, and their effect is the same as setting their
|
173
173
|
# values to true. You can even combine separate arguments and hash
|
174
174
|
# arguments. For example, the following three calls are equivalent:
|
175
|
-
#
|
175
|
+
#
|
176
176
|
# RGeo::Feature.cast(geom, :type => RGeo::Feature::Point, :project => true)
|
177
177
|
# RGeo::Feature.cast(geom, RGeo::Feature::Point, :project => true)
|
178
178
|
# RGeo::Feature.cast(geom, RGeo::Feature::Point, :project)
|
179
|
-
#
|
179
|
+
#
|
180
180
|
# RGeo provides a default casting algorithm. Individual feature
|
181
181
|
# implementation factories may override this and customize the
|
182
182
|
# casting behavior by defining the override_cast method. See
|
183
183
|
# ::RGeo::Feature::Factory#override_cast for more details.
|
184
|
-
|
184
|
+
|
185
185
|
def cast(obj_, *params_)
|
186
186
|
# Interpret params
|
187
187
|
factory_ = obj_.factory
|
@@ -204,13 +204,13 @@ module RGeo
|
|
204
204
|
project_ = opts_[:project]
|
205
205
|
nfactory_ = opts_.delete(:factory) || factory_
|
206
206
|
ntype_ = opts_.delete(:type) || type_
|
207
|
-
|
207
|
+
|
208
208
|
# Let the factory override
|
209
209
|
if nfactory_.respond_to?(:override_cast)
|
210
210
|
override_ = nfactory_.override_cast(obj_, ntype_, opts_)
|
211
211
|
return override_ unless override_ == false
|
212
212
|
end
|
213
|
-
|
213
|
+
|
214
214
|
# Default algorithm
|
215
215
|
ntype_ = type_ if keep_subtype_ && type_.include?(ntype_)
|
216
216
|
if ntype_ == type_
|
@@ -322,11 +322,11 @@ module RGeo
|
|
322
322
|
end
|
323
323
|
end
|
324
324
|
end
|
325
|
-
|
326
|
-
|
325
|
+
|
326
|
+
|
327
327
|
end
|
328
|
-
|
329
|
-
|
328
|
+
|
329
|
+
|
330
330
|
end
|
331
|
-
|
331
|
+
|
332
332
|
end
|