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,61 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Basic methods used by geometry objects
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
module RGeo
|
8
|
+
module ImplHelper # :nodoc:
|
9
|
+
module BasicGeometryMethods # :nodoc:
|
10
|
+
include Feature::Instance
|
11
|
+
|
12
|
+
def inspect # :nodoc:
|
13
|
+
"#<#{self.class}:0x#{object_id.to_s(16)} #{as_text.inspect}>"
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s # :nodoc:
|
17
|
+
as_text
|
18
|
+
end
|
19
|
+
|
20
|
+
def _validate_geometry # :nodoc:
|
21
|
+
end
|
22
|
+
|
23
|
+
def _set_factory(factory_) # :nodoc:
|
24
|
+
@factory = factory_
|
25
|
+
end
|
26
|
+
|
27
|
+
def factory
|
28
|
+
@factory
|
29
|
+
end
|
30
|
+
|
31
|
+
def as_text
|
32
|
+
@factory._generate_wkt(self)
|
33
|
+
end
|
34
|
+
|
35
|
+
def as_binary
|
36
|
+
@factory._generate_wkb(self)
|
37
|
+
end
|
38
|
+
|
39
|
+
def _copy_state_from(obj_) # :nodoc:
|
40
|
+
@factory = obj_.factory
|
41
|
+
end
|
42
|
+
|
43
|
+
def marshal_dump # :nodoc:
|
44
|
+
[@factory, @factory._marshal_wkb_generator.generate(self)]
|
45
|
+
end
|
46
|
+
|
47
|
+
def marshal_load(data_) # :nodoc:
|
48
|
+
_copy_state_from(data_[0]._marshal_wkb_parser.parse(data_[1]))
|
49
|
+
end
|
50
|
+
|
51
|
+
def encode_with(coder_) # :nodoc:
|
52
|
+
coder_["factory"] = @factory
|
53
|
+
coder_["wkt"] = @factory._psych_wkt_generator.generate(self)
|
54
|
+
end
|
55
|
+
|
56
|
+
def init_with(coder_) # :nodoc:
|
57
|
+
_copy_state_from(coder_["factory"]._psych_wkt_parser.parse(coder_["wkt"]))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Common methods for LineString features
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
module RGeo
|
8
|
+
module ImplHelper # :nodoc:
|
9
|
+
module BasicLineStringMethods # :nodoc:
|
10
|
+
def initialize(factory_, points_)
|
11
|
+
_set_factory(factory_)
|
12
|
+
@points = points_.map do |elem_|
|
13
|
+
elem_ = Feature.cast(elem_, factory_, Feature::Point)
|
14
|
+
raise Error::InvalidGeometry, "Could not cast #{elem_}" unless elem_
|
15
|
+
elem_
|
16
|
+
end
|
17
|
+
_validate_geometry
|
18
|
+
end
|
19
|
+
|
20
|
+
def _validate_geometry
|
21
|
+
if @points.size == 1
|
22
|
+
raise Error::InvalidGeometry, "LineString cannot have 1 point"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def num_points
|
27
|
+
@points.size
|
28
|
+
end
|
29
|
+
|
30
|
+
def point_n(n_)
|
31
|
+
n_ < 0 ? nil : @points[n_]
|
32
|
+
end
|
33
|
+
|
34
|
+
def points
|
35
|
+
@points.dup
|
36
|
+
end
|
37
|
+
|
38
|
+
def dimension
|
39
|
+
1
|
40
|
+
end
|
41
|
+
|
42
|
+
def geometry_type
|
43
|
+
Feature::LineString
|
44
|
+
end
|
45
|
+
|
46
|
+
def is_empty?
|
47
|
+
@points.size == 0
|
48
|
+
end
|
49
|
+
|
50
|
+
def boundary
|
51
|
+
array_ = []
|
52
|
+
array_ << @points.first << @points.last if !is_empty? && !is_closed?
|
53
|
+
factory.multi_point([array_])
|
54
|
+
end
|
55
|
+
|
56
|
+
def start_point
|
57
|
+
@points.first
|
58
|
+
end
|
59
|
+
|
60
|
+
def end_point
|
61
|
+
@points.last
|
62
|
+
end
|
63
|
+
|
64
|
+
def is_closed?
|
65
|
+
unless defined?(@is_closed)
|
66
|
+
@is_closed = @points.size > 2 && @points.first == @points.last
|
67
|
+
end
|
68
|
+
@is_closed
|
69
|
+
end
|
70
|
+
|
71
|
+
def is_ring?
|
72
|
+
is_closed? && is_simple?
|
73
|
+
end
|
74
|
+
|
75
|
+
def rep_equals?(rhs_)
|
76
|
+
if rhs_.is_a?(self.class) && rhs_.factory.eql?(@factory) && @points.size == rhs_.num_points
|
77
|
+
rhs_.points.each_with_index { |p_, i_| return false unless @points[i_].rep_equals?(p_) }
|
78
|
+
else
|
79
|
+
false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def hash
|
84
|
+
@hash ||= begin
|
85
|
+
hash_ = [factory, geometry_type].hash
|
86
|
+
@points.inject(hash_) { |h_, p_| (1_664_525 * h_ + p_.hash).hash }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def _copy_state_from(obj_) # :nodoc:
|
91
|
+
super
|
92
|
+
@points = obj_.points
|
93
|
+
end
|
94
|
+
|
95
|
+
def coordinates
|
96
|
+
@points.map(&:coordinates)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
module BasicLineMethods # :nodoc:
|
101
|
+
def initialize(factory_, start_, end_)
|
102
|
+
_set_factory(factory_)
|
103
|
+
cstart_ = Feature.cast(start_, factory_, Feature::Point)
|
104
|
+
unless cstart_
|
105
|
+
raise Error::InvalidGeometry, "Could not cast start: #{start_}"
|
106
|
+
end
|
107
|
+
cend_ = Feature.cast(end_, factory_, Feature::Point)
|
108
|
+
raise Error::InvalidGeometry, "Could not cast end: #{end_}" unless cend_
|
109
|
+
@points = [cstart_, cend_]
|
110
|
+
_validate_geometry
|
111
|
+
end
|
112
|
+
|
113
|
+
def _validate_geometry # :nodoc:
|
114
|
+
super
|
115
|
+
if @points.size > 2
|
116
|
+
raise Error::InvalidGeometry, "Line must have 0 or 2 points"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def geometry_type
|
121
|
+
Feature::Line
|
122
|
+
end
|
123
|
+
|
124
|
+
def coordinates
|
125
|
+
@points.map(&:coordinates)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
module BasicLinearRingMethods # :nodoc:
|
130
|
+
def _validate_geometry # :nodoc:
|
131
|
+
super
|
132
|
+
if @points.size > 0
|
133
|
+
@points << @points.first if @points.first != @points.last
|
134
|
+
@points = @points.chunk {|x| x}.map(&:first)
|
135
|
+
if !@factory.property(:uses_lenient_assertions) && !is_ring?
|
136
|
+
raise Error::InvalidGeometry, "LinearRing failed ring test"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def geometry_type
|
142
|
+
Feature::LinearRing
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Common methods for Point features
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
module RGeo
|
8
|
+
module ImplHelper # :nodoc:
|
9
|
+
module BasicPointMethods # :nodoc:
|
10
|
+
def initialize(factory_, x_, y_, *extra_)
|
11
|
+
_set_factory(factory_)
|
12
|
+
@x = x_.to_f
|
13
|
+
@y = y_.to_f
|
14
|
+
@z = factory_.property(:has_z_coordinate) ? extra_.shift.to_f : nil
|
15
|
+
@m = factory_.property(:has_m_coordinate) ? extra_.shift.to_f : nil
|
16
|
+
if extra_.size > 0
|
17
|
+
raise ::ArgumentError, "Too many arguments for point initializer"
|
18
|
+
end
|
19
|
+
_validate_geometry
|
20
|
+
end
|
21
|
+
|
22
|
+
def x
|
23
|
+
@x
|
24
|
+
end
|
25
|
+
|
26
|
+
def y
|
27
|
+
@y
|
28
|
+
end
|
29
|
+
|
30
|
+
def z
|
31
|
+
@z
|
32
|
+
end
|
33
|
+
|
34
|
+
def m
|
35
|
+
@m
|
36
|
+
end
|
37
|
+
|
38
|
+
def dimension
|
39
|
+
0
|
40
|
+
end
|
41
|
+
|
42
|
+
def geometry_type
|
43
|
+
Feature::Point
|
44
|
+
end
|
45
|
+
|
46
|
+
def is_empty?
|
47
|
+
false
|
48
|
+
end
|
49
|
+
|
50
|
+
def is_simple?
|
51
|
+
true
|
52
|
+
end
|
53
|
+
|
54
|
+
def envelope
|
55
|
+
self
|
56
|
+
end
|
57
|
+
|
58
|
+
def boundary
|
59
|
+
factory.collection([])
|
60
|
+
end
|
61
|
+
|
62
|
+
def convex_hull
|
63
|
+
self
|
64
|
+
end
|
65
|
+
|
66
|
+
def equals?(rhs_)
|
67
|
+
return false unless rhs_.is_a?(self.class) && rhs_.factory == factory
|
68
|
+
case rhs_
|
69
|
+
when Feature::Point
|
70
|
+
rhs_.x == @x && rhs_.y == @y
|
71
|
+
when Feature::LineString
|
72
|
+
rhs_.num_points > 0 && rhs_.points.all? { |elem_| equals?(elem_) }
|
73
|
+
when Feature::GeometryCollection
|
74
|
+
rhs_.num_geometries > 0 && rhs_.all? { |elem_| equals?(elem_) }
|
75
|
+
else
|
76
|
+
false
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def rep_equals?(rhs_)
|
81
|
+
rhs_.is_a?(self.class) && rhs_.factory.eql?(@factory) && @x == rhs_.x && @y == rhs_.y && @z == rhs_.z && @m == rhs_.m
|
82
|
+
end
|
83
|
+
|
84
|
+
def hash
|
85
|
+
@hash ||= [factory, geometry_type, @x, @y, @z, @m].hash
|
86
|
+
end
|
87
|
+
|
88
|
+
def _copy_state_from(obj_) # :nodoc:
|
89
|
+
super
|
90
|
+
@x = obj_.x
|
91
|
+
@y = obj_.y
|
92
|
+
@z = obj_.z
|
93
|
+
@m = obj_.m
|
94
|
+
end
|
95
|
+
|
96
|
+
def coordinates
|
97
|
+
[x, y].tap do |coords|
|
98
|
+
coords << z if factory.property(:has_z_coordinate)
|
99
|
+
coords << m if factory.property(:has_m_coordinate)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Common methods for Polygon features
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
module RGeo
|
8
|
+
module ImplHelper # :nodoc:
|
9
|
+
module BasicPolygonMethods # :nodoc:
|
10
|
+
def initialize(factory_, exterior_ring_, interior_rings_)
|
11
|
+
_set_factory(factory_)
|
12
|
+
@exterior_ring = Feature.cast(exterior_ring_, factory_, Feature::LinearRing)
|
13
|
+
unless @exterior_ring
|
14
|
+
raise Error::InvalidGeometry, "Failed to cast exterior ring #{exterior_ring_}"
|
15
|
+
end
|
16
|
+
@interior_rings = (interior_rings_ || []).map do |elem_|
|
17
|
+
elem_ = Feature.cast(elem_, factory_, Feature::LinearRing)
|
18
|
+
unless elem_
|
19
|
+
raise Error::InvalidGeometry, "Could not cast interior ring #{elem_}"
|
20
|
+
end
|
21
|
+
elem_
|
22
|
+
end
|
23
|
+
_validate_geometry
|
24
|
+
end
|
25
|
+
|
26
|
+
def exterior_ring
|
27
|
+
@exterior_ring
|
28
|
+
end
|
29
|
+
|
30
|
+
def num_interior_rings
|
31
|
+
@interior_rings.size
|
32
|
+
end
|
33
|
+
|
34
|
+
def interior_ring_n(n_)
|
35
|
+
n_ < 0 ? nil : @interior_rings[n_]
|
36
|
+
end
|
37
|
+
|
38
|
+
def interior_rings
|
39
|
+
@interior_rings.dup
|
40
|
+
end
|
41
|
+
|
42
|
+
def dimension
|
43
|
+
2
|
44
|
+
end
|
45
|
+
|
46
|
+
def geometry_type
|
47
|
+
Feature::Polygon
|
48
|
+
end
|
49
|
+
|
50
|
+
def is_empty?
|
51
|
+
@exterior_ring.is_empty?
|
52
|
+
end
|
53
|
+
|
54
|
+
def boundary
|
55
|
+
array_ = []
|
56
|
+
array_ << @exterior_ring unless @exterior_ring.is_empty?
|
57
|
+
array_.concat(@interior_rings)
|
58
|
+
factory.multi_line_string(array_)
|
59
|
+
end
|
60
|
+
|
61
|
+
def rep_equals?(rhs_)
|
62
|
+
if rhs_.is_a?(self.class) && rhs_.factory.eql?(@factory) && @exterior_ring.rep_equals?(rhs_.exterior_ring) && @interior_rings.size == rhs_.num_interior_rings
|
63
|
+
rhs_.interior_rings.each_with_index { |r_, i_| return false unless @interior_rings[i_].rep_equals?(r_) }
|
64
|
+
else
|
65
|
+
false
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def hash
|
70
|
+
@hash ||= begin
|
71
|
+
hash_ = [geometry_type, @exterior_ring].hash
|
72
|
+
@interior_rings.inject(hash_) { |h_, r_| (1_664_525 * h_ + r_.hash).hash }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def _copy_state_from(obj_) # :nodoc:
|
77
|
+
super
|
78
|
+
@exterior_ring = obj_.exterior_ring
|
79
|
+
@interior_rings = obj_.interior_rings
|
80
|
+
end
|
81
|
+
|
82
|
+
def coordinates
|
83
|
+
([@exterior_ring] + @interior_rings).map(&:coordinates)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Math constants and tools
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
module RGeo
|
8
|
+
module ImplHelper # :nodoc:
|
9
|
+
module Math # :nodoc:
|
10
|
+
RADIANS_PER_DEGREE = ::Math::PI / 180.0
|
11
|
+
DEGREES_PER_RADIAN = 180.0 / ::Math::PI
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Math constants and tools
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
module RGeo
|
8
|
+
module ImplHelper # :nodoc:
|
9
|
+
module Utils # :nodoc:
|
10
|
+
class << self
|
11
|
+
def stringize_hash(hash_)
|
12
|
+
nhash_ = {}
|
13
|
+
hash_.each do |k_, v_|
|
14
|
+
nhash_[k_.is_a?(::Symbol) ? k_.to_s : k_] = v_.is_a?(::Symbol) ? v_.to_s : v_
|
15
|
+
end
|
16
|
+
nhash_
|
17
|
+
end
|
18
|
+
|
19
|
+
def symbolize_hash(hash_)
|
20
|
+
nhash_ = {}
|
21
|
+
hash_.each do |k_, v_|
|
22
|
+
nhash_[k_.is_a?(::String) ? k_.to_sym : k_] = v_.is_a?(::String) ? v_.to_sym : v_
|
23
|
+
end
|
24
|
+
nhash_
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|