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,80 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# GEOS implementation additions written in Ruby
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
module RGeo
|
8
|
+
module Geos
|
9
|
+
class ZMPointImpl # :nodoc:
|
10
|
+
include ZMGeometryMethods
|
11
|
+
include ZMPointMethods
|
12
|
+
|
13
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::Point).include_in_class(self, true)
|
14
|
+
end
|
15
|
+
|
16
|
+
class ZMLineStringImpl # :nodoc:
|
17
|
+
include ZMGeometryMethods
|
18
|
+
include ZMLineStringMethods
|
19
|
+
|
20
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::LineString).include_in_class(self, true)
|
21
|
+
end
|
22
|
+
|
23
|
+
class ZMLinearRingImpl # :nodoc:
|
24
|
+
include ZMGeometryMethods
|
25
|
+
include ZMLineStringMethods
|
26
|
+
|
27
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::LinearRing).include_in_class(self, true)
|
28
|
+
end
|
29
|
+
|
30
|
+
class ZMLineImpl # :nodoc:
|
31
|
+
include ZMGeometryMethods
|
32
|
+
include ZMLineStringMethods
|
33
|
+
|
34
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::Line).include_in_class(self, true)
|
35
|
+
end
|
36
|
+
|
37
|
+
class ZMPolygonImpl # :nodoc:
|
38
|
+
include ZMGeometryMethods
|
39
|
+
include ZMPolygonMethods
|
40
|
+
|
41
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::Polygon).include_in_class(self, true)
|
42
|
+
end
|
43
|
+
|
44
|
+
class ZMGeometryCollectionImpl # :nodoc:
|
45
|
+
include ZMGeometryMethods
|
46
|
+
include ZMGeometryCollectionMethods
|
47
|
+
|
48
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::GeometryCollection).include_in_class(self, true)
|
49
|
+
end
|
50
|
+
|
51
|
+
class ZMMultiPointImpl # :nodoc:
|
52
|
+
include ZMGeometryMethods
|
53
|
+
include ZMGeometryCollectionMethods
|
54
|
+
|
55
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPoint).include_in_class(self, true)
|
56
|
+
end
|
57
|
+
|
58
|
+
class ZMMultiLineStringImpl # :nodoc:
|
59
|
+
include ZMGeometryMethods
|
60
|
+
include ZMGeometryCollectionMethods
|
61
|
+
include ZMMultiLineStringMethods
|
62
|
+
|
63
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::MultiLineString).include_in_class(self, true)
|
64
|
+
end
|
65
|
+
|
66
|
+
class ZMMultiPolygonImpl # :nodoc:
|
67
|
+
include ZMGeometryMethods
|
68
|
+
include ZMGeometryCollectionMethods
|
69
|
+
include ZMMultiPolygonMethods
|
70
|
+
|
71
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPolygon).include_in_class(self, true)
|
72
|
+
end
|
73
|
+
|
74
|
+
class ZMGeometryImpl # :nodoc:
|
75
|
+
include ZMGeometryMethods
|
76
|
+
|
77
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::Geometry).include_in_class(self, true)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,344 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# GEOS implementation additions written in Ruby
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
module RGeo
|
8
|
+
module Geos
|
9
|
+
module ZMGeometryMethods # :nodoc:
|
10
|
+
include Feature::Instance
|
11
|
+
|
12
|
+
def initialize(factory_, zgeometry_, mgeometry_)
|
13
|
+
@factory = factory_
|
14
|
+
@zgeometry = zgeometry_
|
15
|
+
@mgeometry = mgeometry_
|
16
|
+
end
|
17
|
+
|
18
|
+
def inspect # :nodoc:
|
19
|
+
"#<#{self.class}:0x#{object_id.to_s(16)} #{as_text.inspect}>"
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s # :nodoc:
|
23
|
+
as_text
|
24
|
+
end
|
25
|
+
|
26
|
+
def hash
|
27
|
+
@factory.hash ^ @zgeometry.hash ^ @mgeometry.hash
|
28
|
+
end
|
29
|
+
|
30
|
+
def factory
|
31
|
+
@factory
|
32
|
+
end
|
33
|
+
|
34
|
+
def z_geometry
|
35
|
+
@zgeometry
|
36
|
+
end
|
37
|
+
|
38
|
+
def m_geometry
|
39
|
+
@mgeometry
|
40
|
+
end
|
41
|
+
|
42
|
+
def dimension
|
43
|
+
@zgeometry.dimension
|
44
|
+
end
|
45
|
+
|
46
|
+
def geometry_type
|
47
|
+
@zgeometry.geometry_type
|
48
|
+
end
|
49
|
+
|
50
|
+
def srid
|
51
|
+
@factory.srid
|
52
|
+
end
|
53
|
+
|
54
|
+
def envelope
|
55
|
+
@factory._create_feature(nil, @zgeometry.envelope, @mgeometry.envelope)
|
56
|
+
end
|
57
|
+
|
58
|
+
def as_text
|
59
|
+
@factory.instance_variable_get(:@wkt_generator).generate(self)
|
60
|
+
end
|
61
|
+
|
62
|
+
def as_binary
|
63
|
+
@factory.instance_variable_get(:@wkb_generator).generate(self)
|
64
|
+
end
|
65
|
+
|
66
|
+
def is_empty?
|
67
|
+
@zgeometry.is_empty?
|
68
|
+
end
|
69
|
+
|
70
|
+
def is_simple?
|
71
|
+
@zgeometry.is_simple?
|
72
|
+
end
|
73
|
+
|
74
|
+
def boundary
|
75
|
+
@factory._create_feature(nil, @zgeometry.boundary, @mgeometry.boundary)
|
76
|
+
end
|
77
|
+
|
78
|
+
def equals?(rhs_)
|
79
|
+
@zgeometry.equals?(::RGeo::Feature.cast(rhs_, self).z_geometry)
|
80
|
+
end
|
81
|
+
|
82
|
+
def disjoint?(rhs_)
|
83
|
+
@zgeometry.disjoint?(::RGeo::Feature.cast(rhs_, self).z_geometry)
|
84
|
+
end
|
85
|
+
|
86
|
+
def intersects?(rhs_)
|
87
|
+
@zgeometry.intersects?(::RGeo::Feature.cast(rhs_, self).z_geometry)
|
88
|
+
end
|
89
|
+
|
90
|
+
def touches?(rhs_)
|
91
|
+
@zgeometry.touches?(::RGeo::Feature.cast(rhs_, self).z_geometry)
|
92
|
+
end
|
93
|
+
|
94
|
+
def crosses?(rhs_)
|
95
|
+
@zgeometry.crosses?(::RGeo::Feature.cast(rhs_, self).z_geometry)
|
96
|
+
end
|
97
|
+
|
98
|
+
def within?(rhs_)
|
99
|
+
@zgeometry.within?(::RGeo::Feature.cast(rhs_, self).z_geometry)
|
100
|
+
end
|
101
|
+
|
102
|
+
def contains?(rhs_)
|
103
|
+
@zgeometry.contains?(::RGeo::Feature.cast(rhs_, self).z_geometry)
|
104
|
+
end
|
105
|
+
|
106
|
+
def overlaps?(rhs_)
|
107
|
+
@zgeometry.overlaps?(::RGeo::Feature.cast(rhs_, self).z_geometry)
|
108
|
+
end
|
109
|
+
|
110
|
+
def relate?(rhs_, pattern_)
|
111
|
+
@zgeometry.relate?(::RGeo::Feature.cast(rhs_, self).z_geometry, pattern_)
|
112
|
+
end
|
113
|
+
alias_method :relate, :relate? # DEPRECATED
|
114
|
+
|
115
|
+
def distance(rhs_)
|
116
|
+
@zgeometry.distance(::RGeo::Feature.cast(rhs_, self).z_geometry)
|
117
|
+
end
|
118
|
+
|
119
|
+
def buffer(distance_)
|
120
|
+
@factory._create_feature(nil, @zgeometry.buffer(distance_), @mgeometry.buffer(distance_))
|
121
|
+
end
|
122
|
+
|
123
|
+
def convex_hull
|
124
|
+
@factory._create_feature(nil, @zgeometry.convex_hull, @mgeometry.convex_hull)
|
125
|
+
end
|
126
|
+
|
127
|
+
def intersection(rhs_)
|
128
|
+
rhs_ = ::RGeo::Feature.cast(rhs_, self)
|
129
|
+
@factory._create_feature(nil, @zgeometry.intersection(rhs_.z_geometry), @mgeometry.intersection(rhs_.m_geometry))
|
130
|
+
end
|
131
|
+
|
132
|
+
def union(rhs_)
|
133
|
+
rhs_ = ::RGeo::Feature.cast(rhs_, self)
|
134
|
+
@factory._create_feature(nil, @zgeometry.union(rhs_.z_geometry), @mgeometry.union(rhs_.m_geometry))
|
135
|
+
end
|
136
|
+
|
137
|
+
def difference(rhs_)
|
138
|
+
rhs_ = ::RGeo::Feature.cast(rhs_, self)
|
139
|
+
@factory._create_feature(nil, @zgeometry.difference(rhs_.z_geometry), @mgeometry.difference(rhs_.m_geometry))
|
140
|
+
end
|
141
|
+
|
142
|
+
def sym_difference(rhs_)
|
143
|
+
rhs_ = ::RGeo::Feature.cast(rhs_, self)
|
144
|
+
@factory._create_feature(nil, @zgeometry.sym_difference(rhs_.z_geometry), @mgeometry.sym_difference(rhs_.m_geometry))
|
145
|
+
end
|
146
|
+
|
147
|
+
def rep_equals?(rhs_)
|
148
|
+
rhs_ = ::RGeo::Feature.cast(rhs_, self)
|
149
|
+
rhs_.is_a?(self.class) && @factory.eql?(rhs_.factory) && @zgeometry.rep_equals?(rhs_.z_geometry) && @mgeometry.rep_equals?(rhs_.m_geometry)
|
150
|
+
end
|
151
|
+
|
152
|
+
alias_method :eql?, :rep_equals?
|
153
|
+
alias_method :==, :equals?
|
154
|
+
|
155
|
+
alias_method :-, :difference
|
156
|
+
alias_method :+, :union
|
157
|
+
alias_method :*, :intersection
|
158
|
+
|
159
|
+
def _copy_state_from(obj_) # :nodoc:
|
160
|
+
@factory = obj_.factory
|
161
|
+
@zgeometry = obj_.z_geometry
|
162
|
+
@mgeometry = obj_.m_geometry
|
163
|
+
end
|
164
|
+
|
165
|
+
def marshal_dump # :nodoc:
|
166
|
+
[@factory, @factory._marshal_wkb_generator.generate(self)]
|
167
|
+
end
|
168
|
+
|
169
|
+
def marshal_load(data_) # :nodoc:
|
170
|
+
_copy_state_from(data_[0]._marshal_wkb_parser.parse(data_[1]))
|
171
|
+
end
|
172
|
+
|
173
|
+
def encode_with(coder_) # :nodoc:
|
174
|
+
coder_["factory"] = @factory
|
175
|
+
coder_["wkt"] = @factory._psych_wkt_generator.generate(self)
|
176
|
+
end
|
177
|
+
|
178
|
+
def init_with(coder_) # :nodoc:
|
179
|
+
_copy_state_from(coder_["factory"]._psych_wkt_parser.parse(coder_["wkt"]))
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
module ZMPointMethods # :nodoc:
|
184
|
+
def x
|
185
|
+
@zgeometry.x
|
186
|
+
end
|
187
|
+
|
188
|
+
def y
|
189
|
+
@zgeometry.y
|
190
|
+
end
|
191
|
+
|
192
|
+
def z
|
193
|
+
@zgeometry.z
|
194
|
+
end
|
195
|
+
|
196
|
+
def m
|
197
|
+
@mgeometry.m
|
198
|
+
end
|
199
|
+
|
200
|
+
def coordinates
|
201
|
+
[x, y].tap do |coords|
|
202
|
+
coords << z if @factory.property(:has_z_coordinate)
|
203
|
+
coords << m if @factory.property(:has_m_coordinate)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
module ZMLineStringMethods # :nodoc:
|
209
|
+
def length
|
210
|
+
@zgeometry.length
|
211
|
+
end
|
212
|
+
|
213
|
+
def start_point
|
214
|
+
point_n(0)
|
215
|
+
end
|
216
|
+
|
217
|
+
def end_point
|
218
|
+
point_n(num_points - 1)
|
219
|
+
end
|
220
|
+
|
221
|
+
def is_closed?
|
222
|
+
@zgeometry.is_closed?
|
223
|
+
end
|
224
|
+
|
225
|
+
def is_ring?
|
226
|
+
@zgeometry.is_ring?
|
227
|
+
end
|
228
|
+
|
229
|
+
def num_points
|
230
|
+
@zgeometry.num_points
|
231
|
+
end
|
232
|
+
|
233
|
+
def point_n(n_)
|
234
|
+
@factory._create_feature(ZMPointImpl, @zgeometry.point_n(n_), @mgeometry.point_n(n_))
|
235
|
+
end
|
236
|
+
|
237
|
+
def points
|
238
|
+
result_ = []
|
239
|
+
zpoints_ = @zgeometry.points
|
240
|
+
mpoints_ = @mgeometry.points
|
241
|
+
zpoints_.size.times do |i_|
|
242
|
+
result_ << @factory._create_feature(ZMPointImpl, zpoints_[i_], mpoints_[i_])
|
243
|
+
end
|
244
|
+
result_
|
245
|
+
end
|
246
|
+
|
247
|
+
def coordinates
|
248
|
+
points.map(&:coordinates)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
module ZMPolygonMethods # :nodoc:
|
253
|
+
def area
|
254
|
+
@zgeometry.area
|
255
|
+
end
|
256
|
+
|
257
|
+
def centroid
|
258
|
+
@factory._create_feature(ZMPointImpl, @zgeometry.centroid, @mgeometry.centroid)
|
259
|
+
end
|
260
|
+
|
261
|
+
def point_on_surface
|
262
|
+
@factory._create_feature(ZMPointImpl, @zgeometry.centroid, @mgeometry.centroid)
|
263
|
+
end
|
264
|
+
|
265
|
+
def exterior_ring
|
266
|
+
@factory._create_feature(ZMLineStringImpl, @zgeometry.exterior_ring, @mgeometry.exterior_ring)
|
267
|
+
end
|
268
|
+
|
269
|
+
def num_interior_rings
|
270
|
+
@zgeometry.num_interior_rings
|
271
|
+
end
|
272
|
+
|
273
|
+
def interior_ring_n(n_)
|
274
|
+
@factory._create_feature(ZMLineStringImpl, @zgeometry.interior_ring_n(n_), @mgeometry.interior_ring_n(n_))
|
275
|
+
end
|
276
|
+
|
277
|
+
def interior_rings
|
278
|
+
result_ = []
|
279
|
+
zrings_ = @zgeometry.interior_rings
|
280
|
+
mrings_ = @mgeometry.interior_rings
|
281
|
+
zrings_.size.times do |i_|
|
282
|
+
result_ << @factory._create_feature(ZMLineStringImpl, zrings_[i_], mrings_[i_])
|
283
|
+
end
|
284
|
+
result_
|
285
|
+
end
|
286
|
+
|
287
|
+
def coordinates
|
288
|
+
([exterior_ring] + interior_rings).map(&:coordinates)
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
module ZMGeometryCollectionMethods # :nodoc:
|
293
|
+
def num_geometries
|
294
|
+
@zgeometry.num_geometries
|
295
|
+
end
|
296
|
+
alias_method :size, :num_geometries
|
297
|
+
|
298
|
+
def geometry_n(n_)
|
299
|
+
@factory._create_feature(nil, @zgeometry.geometry_n(n_), @mgeometry.geometry_n(n_))
|
300
|
+
end
|
301
|
+
alias_method :[], :geometry_n
|
302
|
+
|
303
|
+
def each
|
304
|
+
num_geometries.times do |i_|
|
305
|
+
yield geometry_n(i_)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
include ::Enumerable
|
310
|
+
end
|
311
|
+
|
312
|
+
module ZMMultiLineStringMethods # :nodoc:
|
313
|
+
def length
|
314
|
+
@zgeometry.length
|
315
|
+
end
|
316
|
+
|
317
|
+
def is_closed?
|
318
|
+
@zgeometry.is_closed?
|
319
|
+
end
|
320
|
+
|
321
|
+
def coordinates
|
322
|
+
each.map(&:coordinates)
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
module ZMMultiPolygonMethods # :nodoc:
|
327
|
+
def area
|
328
|
+
@zgeometry.area
|
329
|
+
end
|
330
|
+
|
331
|
+
def centroid
|
332
|
+
@factory._create_feature(ZMPointImpl, @zgeometry.centroid, @mgeometry.centroid)
|
333
|
+
end
|
334
|
+
|
335
|
+
def point_on_surface
|
336
|
+
@factory._create_feature(ZMPointImpl, @zgeometry.centroid, @mgeometry.centroid)
|
337
|
+
end
|
338
|
+
|
339
|
+
def coordinates
|
340
|
+
each.map(&:coordinates)
|
341
|
+
end
|
342
|
+
end
|
343
|
+
end
|
344
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Implementation helpers namespace for RGeo
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
module RGeo
|
8
|
+
module ImplHelper # :nodoc:
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# Implementation files
|
13
|
+
require "rgeo/impl_helper/utils"
|
14
|
+
require "rgeo/impl_helper/math"
|
15
|
+
require "rgeo/impl_helper/basic_geometry_methods"
|
16
|
+
require "rgeo/impl_helper/basic_geometry_collection_methods"
|
17
|
+
require "rgeo/impl_helper/basic_point_methods"
|
18
|
+
require "rgeo/impl_helper/basic_line_string_methods"
|
19
|
+
require "rgeo/impl_helper/basic_polygon_methods"
|
@@ -0,0 +1,185 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Common methods for GeometryCollection features
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
module RGeo
|
8
|
+
module ImplHelper # :nodoc:
|
9
|
+
module BasicGeometryCollectionMethods # :nodoc:
|
10
|
+
def initialize(factory_, elements_)
|
11
|
+
_set_factory(factory_)
|
12
|
+
@elements = elements_.map do |elem_|
|
13
|
+
elem_ = Feature.cast(elem_, factory_)
|
14
|
+
raise Error::InvalidGeometry, "Could not cast #{elem_}" unless elem_
|
15
|
+
elem_
|
16
|
+
end
|
17
|
+
_validate_geometry
|
18
|
+
end
|
19
|
+
|
20
|
+
def num_geometries
|
21
|
+
@elements.size
|
22
|
+
end
|
23
|
+
|
24
|
+
def geometry_n(n_)
|
25
|
+
n_ < 0 ? nil : @elements[n_]
|
26
|
+
end
|
27
|
+
|
28
|
+
def [](n_)
|
29
|
+
@elements[n_]
|
30
|
+
end
|
31
|
+
|
32
|
+
def each(&block_)
|
33
|
+
@elements.each(&block_)
|
34
|
+
end
|
35
|
+
|
36
|
+
def dimension
|
37
|
+
unless defined?(@dimension)
|
38
|
+
@dimension = -1
|
39
|
+
@elements.each do |elem_|
|
40
|
+
dim_ = elem_.dimension
|
41
|
+
@dimension = dim_ if @dimension < dim_
|
42
|
+
end
|
43
|
+
end
|
44
|
+
@dimension
|
45
|
+
end
|
46
|
+
|
47
|
+
def geometry_type
|
48
|
+
Feature::GeometryCollection
|
49
|
+
end
|
50
|
+
|
51
|
+
def is_empty?
|
52
|
+
@elements.size == 0
|
53
|
+
end
|
54
|
+
|
55
|
+
def rep_equals?(rhs_)
|
56
|
+
if rhs_.is_a?(self.class) && rhs_.factory.eql?(@factory) && @elements.size == rhs_.num_geometries
|
57
|
+
rhs_.each_with_index { |p_, i_| return false unless @elements[i_].rep_equals?(p_) }
|
58
|
+
else
|
59
|
+
false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def hash
|
64
|
+
@hash ||= begin
|
65
|
+
hash_ = [factory, geometry_type].hash
|
66
|
+
@elements.inject(hash_) { |h_, g_| (1_664_525 * h_ + g_.hash).hash }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def _copy_state_from(obj_) # :nodoc:
|
71
|
+
super
|
72
|
+
@elements = obj_._elements
|
73
|
+
end
|
74
|
+
|
75
|
+
def _elements # :nodoc:
|
76
|
+
@elements
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
module BasicMultiLineStringMethods # :nodoc:
|
81
|
+
def initialize(factory_, elements_)
|
82
|
+
_set_factory(factory_)
|
83
|
+
@elements = elements_.map do |elem_|
|
84
|
+
elem_ = Feature.cast(elem_, factory_, Feature::LineString, :keep_subtype)
|
85
|
+
raise Error::InvalidGeometry, "Could not cast #{elem_}" unless elem_
|
86
|
+
elem_
|
87
|
+
end
|
88
|
+
_validate_geometry
|
89
|
+
end
|
90
|
+
|
91
|
+
def geometry_type
|
92
|
+
Feature::MultiLineString
|
93
|
+
end
|
94
|
+
|
95
|
+
def is_closed?
|
96
|
+
all?(&:is_closed?)
|
97
|
+
end
|
98
|
+
|
99
|
+
def length
|
100
|
+
@elements.inject(0.0) { |sum_, obj_| sum_ + obj_.length }
|
101
|
+
end
|
102
|
+
|
103
|
+
def _add_boundary(hash_, point_) # :nodoc:
|
104
|
+
hval_ = [point_.x, point_.y].hash
|
105
|
+
(hash_[hval_] ||= [point_, 0])[1] += 1
|
106
|
+
end
|
107
|
+
|
108
|
+
def boundary
|
109
|
+
hash_ = {}
|
110
|
+
@elements.each do |line_|
|
111
|
+
if !line_.is_empty? && !line_.is_closed?
|
112
|
+
_add_boundary(hash_, line_.start_point)
|
113
|
+
_add_boundary(hash_, line_.end_point)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
array_ = []
|
117
|
+
hash_.each do |_hval_, data_|
|
118
|
+
array_ << data_[0] if data_[1].odd?
|
119
|
+
end
|
120
|
+
factory.multi_point([array_])
|
121
|
+
end
|
122
|
+
|
123
|
+
def coordinates
|
124
|
+
@elements.map(&:coordinates)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
module BasicMultiPointMethods # :nodoc:
|
129
|
+
def initialize(factory_, elements_)
|
130
|
+
_set_factory(factory_)
|
131
|
+
@elements = elements_.map do |elem_|
|
132
|
+
elem_ = Feature.cast(elem_, factory_, Feature::Point, :keep_subtype)
|
133
|
+
raise Error::InvalidGeometry, "Could not cast #{elem_}" unless elem_
|
134
|
+
elem_
|
135
|
+
end
|
136
|
+
_validate_geometry
|
137
|
+
end
|
138
|
+
|
139
|
+
def geometry_type
|
140
|
+
Feature::MultiPoint
|
141
|
+
end
|
142
|
+
|
143
|
+
def boundary
|
144
|
+
factory.collection([])
|
145
|
+
end
|
146
|
+
|
147
|
+
def coordinates
|
148
|
+
@elements.map(&:coordinates)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
module BasicMultiPolygonMethods # :nodoc:
|
153
|
+
def initialize(factory_, elements_)
|
154
|
+
_set_factory(factory_)
|
155
|
+
@elements = elements_.map do |elem_|
|
156
|
+
elem_ = Feature.cast(elem_, factory_, Feature::Polygon, :keep_subtype)
|
157
|
+
raise Error::InvalidGeometry, "Could not cast #{elem_}" unless elem_
|
158
|
+
elem_
|
159
|
+
end
|
160
|
+
_validate_geometry
|
161
|
+
end
|
162
|
+
|
163
|
+
def geometry_type
|
164
|
+
Feature::MultiPolygon
|
165
|
+
end
|
166
|
+
|
167
|
+
def area
|
168
|
+
@elements.inject(0.0) { |sum_, obj_| sum_ + obj_.area }
|
169
|
+
end
|
170
|
+
|
171
|
+
def boundary
|
172
|
+
array_ = []
|
173
|
+
@elements.each do |poly_|
|
174
|
+
array_ << poly_.exterior_ring unless poly_.is_empty?
|
175
|
+
array_.concat(poly_.interior_rings)
|
176
|
+
end
|
177
|
+
factory.multi_line_string(array_)
|
178
|
+
end
|
179
|
+
|
180
|
+
def coordinates
|
181
|
+
@elements.map(&:coordinates)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|