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,113 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Core calculations in the plane
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
module RGeo
|
8
|
+
module Cartesian
|
9
|
+
# Represents a line segment in the plane.
|
10
|
+
|
11
|
+
class Segment # :nodoc:
|
12
|
+
def initialize(start_, end_)
|
13
|
+
@s = start_
|
14
|
+
@e = end_
|
15
|
+
@sx = @s.x
|
16
|
+
@sy = @s.y
|
17
|
+
@ex = @e.x
|
18
|
+
@ey = @e.y
|
19
|
+
@dx = @ex - @sx
|
20
|
+
@dy = @ey - @sy
|
21
|
+
@lensq = @dx * @dx + @dy * @dy
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_reader :s
|
25
|
+
attr_reader :e
|
26
|
+
attr_reader :dx
|
27
|
+
attr_reader :dy
|
28
|
+
|
29
|
+
def to_s
|
30
|
+
"#{@s} - #{@e}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def eql?(rhs_)
|
34
|
+
rhs_.is_a?(Segment) && @s == rhs_.s && @e == rhs_.e
|
35
|
+
end
|
36
|
+
alias_method :==, :eql?
|
37
|
+
|
38
|
+
def degenerate?
|
39
|
+
@lensq == 0
|
40
|
+
end
|
41
|
+
|
42
|
+
# Returns a negative value if the point is to the left,
|
43
|
+
# a positive value if the point is to the right, or
|
44
|
+
# 0 if the point is collinear to the segment.
|
45
|
+
|
46
|
+
def side(p_)
|
47
|
+
px_ = p_.x
|
48
|
+
py_ = p_.y
|
49
|
+
(@sx - px_) * (@ey - py_) - (@sy - py_) * (@ex - px_)
|
50
|
+
end
|
51
|
+
|
52
|
+
def tproj(p_)
|
53
|
+
if @lensq == 0
|
54
|
+
nil
|
55
|
+
else
|
56
|
+
(@dx * (p_.x - @sx) + @dy * (p_.y - @sy)) / @lensq
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def contains_point?(p_)
|
61
|
+
if side(p_) == 0
|
62
|
+
t_ = tproj(p_)
|
63
|
+
t_ && t_ >= 0.0 && t_ <= 1.0
|
64
|
+
else
|
65
|
+
false
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def intersects_segment?(seg_)
|
70
|
+
s2_ = seg_.s
|
71
|
+
# Handle degenerate cases
|
72
|
+
if seg_.degenerate?
|
73
|
+
if @lensq == 0
|
74
|
+
return @s == s2_
|
75
|
+
else
|
76
|
+
return contains_point?(s2_)
|
77
|
+
end
|
78
|
+
elsif @lensq == 0
|
79
|
+
return seg_.contains_point?(@s)
|
80
|
+
end
|
81
|
+
# Both segments have nonzero length.
|
82
|
+
sx2_ = s2_.x
|
83
|
+
sy2_ = s2_.y
|
84
|
+
dx2_ = seg_.dx
|
85
|
+
dy2_ = seg_.dy
|
86
|
+
denom_ = @dx * dy2_ - @dy * dx2_
|
87
|
+
if denom_ == 0
|
88
|
+
# Segments are parallel. Make sure they are collinear.
|
89
|
+
return false unless side(s2_) == 0
|
90
|
+
# 1-D check.
|
91
|
+
ts_ = (@dx * (sx2_ - @sx) + @dy * (sy2_ - @sy)) / @lensq
|
92
|
+
te_ = (@dx * (sx2_ + dx2_ - @sx) + @dy * (sy2_ + dy2_ - @sy)) / @lensq
|
93
|
+
if ts_ < te_
|
94
|
+
te_ >= 0.0 && ts_ <= 1.0
|
95
|
+
else
|
96
|
+
ts_ >= 0.0 && te_ <= 1.0
|
97
|
+
end
|
98
|
+
else
|
99
|
+
# Segments are not parallel. Check the intersection of their
|
100
|
+
# containing lines.
|
101
|
+
t_ = (dy2_ * (sx2_ - @sx) + dx2_ * (@sy - sy2_)) / denom_
|
102
|
+
return false if t_ < 0.0 || t_ > 1.0
|
103
|
+
t2_ = (@dy * (sx2_ - @sx) + @dx * (@sy - sy2_)) / denom_
|
104
|
+
t2_ >= 0.0 && t2_ <= 1.0
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def length
|
109
|
+
::Math.sqrt(@lensq)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,347 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Geographic data factory implementation
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
module RGeo
|
8
|
+
module Cartesian
|
9
|
+
# This class implements the factory for the simple cartesian
|
10
|
+
# implementation.
|
11
|
+
|
12
|
+
class Factory
|
13
|
+
include Feature::Factory::Instance
|
14
|
+
|
15
|
+
# Create a new simple cartesian factory.
|
16
|
+
#
|
17
|
+
# See ::RGeo::Cartesian.simple_factory for a list of supported options.
|
18
|
+
|
19
|
+
def initialize(opts_ = {})
|
20
|
+
@has_z = opts_[:has_z_coordinate] ? true : false
|
21
|
+
@has_m = opts_[:has_m_coordinate] ? true : false
|
22
|
+
@proj4 = opts_[:proj4]
|
23
|
+
if CoordSys::Proj4.supported?
|
24
|
+
if @proj4.is_a?(::String) || @proj4.is_a?(::Hash)
|
25
|
+
@proj4 = CoordSys::Proj4.create(@proj4)
|
26
|
+
end
|
27
|
+
else
|
28
|
+
@proj4 = nil
|
29
|
+
end
|
30
|
+
srid_ = opts_[:srid]
|
31
|
+
@coord_sys = opts_[:coord_sys]
|
32
|
+
if @coord_sys.is_a?(::String)
|
33
|
+
@coord_sys = begin
|
34
|
+
CoordSys::CS.create_from_wkt(@coord_sys)
|
35
|
+
rescue
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
if (!@proj4 || !@coord_sys) && srid_ && (db_ = opts_[:srs_database])
|
40
|
+
entry_ = db_.get(srid_.to_i)
|
41
|
+
if entry_
|
42
|
+
@proj4 ||= entry_.proj4
|
43
|
+
@coord_sys ||= entry_.coord_sys
|
44
|
+
end
|
45
|
+
end
|
46
|
+
srid_ ||= @coord_sys.authority_code if @coord_sys
|
47
|
+
@srid = srid_.to_i
|
48
|
+
@lenient_assertions = opts_[:uses_lenient_assertions] ? true : false
|
49
|
+
@buffer_resolution = opts_[:buffer_resolution].to_i
|
50
|
+
@buffer_resolution = 1 if @buffer_resolution < 1
|
51
|
+
|
52
|
+
wkt_generator_ = opts_[:wkt_generator]
|
53
|
+
case wkt_generator_
|
54
|
+
when ::Hash
|
55
|
+
@wkt_generator = WKRep::WKTGenerator.new(wkt_generator_)
|
56
|
+
else
|
57
|
+
@wkt_generator = WKRep::WKTGenerator.new(convert_case: :upper)
|
58
|
+
end
|
59
|
+
wkb_generator_ = opts_[:wkb_generator]
|
60
|
+
case wkb_generator_
|
61
|
+
when ::Hash
|
62
|
+
@wkb_generator = WKRep::WKBGenerator.new(wkb_generator_)
|
63
|
+
else
|
64
|
+
@wkb_generator = WKRep::WKBGenerator.new
|
65
|
+
end
|
66
|
+
wkt_parser_ = opts_[:wkt_parser]
|
67
|
+
case wkt_parser_
|
68
|
+
when ::Hash
|
69
|
+
@wkt_parser = WKRep::WKTParser.new(self, wkt_parser_)
|
70
|
+
else
|
71
|
+
@wkt_parser = WKRep::WKTParser.new(self)
|
72
|
+
end
|
73
|
+
wkb_parser_ = opts_[:wkb_parser]
|
74
|
+
case wkb_parser_
|
75
|
+
when ::Hash
|
76
|
+
@wkb_parser = WKRep::WKBParser.new(self, wkb_parser_)
|
77
|
+
else
|
78
|
+
@wkb_parser = WKRep::WKBParser.new(self)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Equivalence test.
|
83
|
+
|
84
|
+
def eql?(rhs_)
|
85
|
+
rhs_.is_a?(self.class) && @srid == rhs_.srid &&
|
86
|
+
@has_z == rhs_.property(:has_z_coordinate) &&
|
87
|
+
@has_m == rhs_.property(:has_m_coordinate) &&
|
88
|
+
@proj4.eql?(rhs_.proj4)
|
89
|
+
end
|
90
|
+
alias_method :==, :eql?
|
91
|
+
|
92
|
+
# Standard hash code
|
93
|
+
|
94
|
+
def hash
|
95
|
+
@hash ||= [@srid, @has_z, @has_m, @proj4].hash
|
96
|
+
end
|
97
|
+
|
98
|
+
# Marshal support
|
99
|
+
|
100
|
+
def marshal_dump # :nodoc:
|
101
|
+
hash_ = {
|
102
|
+
"hasz" => @has_z,
|
103
|
+
"hasm" => @has_m,
|
104
|
+
"srid" => @srid,
|
105
|
+
"wktg" => @wkt_generator._properties,
|
106
|
+
"wkbg" => @wkb_generator._properties,
|
107
|
+
"wktp" => @wkt_parser._properties,
|
108
|
+
"wkbp" => @wkb_parser._properties,
|
109
|
+
"lena" => @lenient_assertions,
|
110
|
+
"bufr" => @buffer_resolution
|
111
|
+
}
|
112
|
+
hash_["proj4"] = @proj4.marshal_dump if @proj4
|
113
|
+
hash_["cs"] = @coord_sys.to_wkt if @coord_sys
|
114
|
+
hash_
|
115
|
+
end
|
116
|
+
|
117
|
+
def marshal_load(data_) # :nodoc:
|
118
|
+
if CoordSys::Proj4.supported? && (proj4_data_ = data_["proj4"])
|
119
|
+
proj4_ = CoordSys::Proj4.allocate
|
120
|
+
proj4_.marshal_load(proj4_data_)
|
121
|
+
else
|
122
|
+
proj4_ = nil
|
123
|
+
end
|
124
|
+
if (coord_sys_data_ = data_["cs"])
|
125
|
+
coord_sys_ = CoordSys::CS.create_from_wkt(coord_sys_data_)
|
126
|
+
else
|
127
|
+
coord_sys_ = nil
|
128
|
+
end
|
129
|
+
initialize(
|
130
|
+
has_z_coordinate: data_["hasz"],
|
131
|
+
has_m_coordinate: data_["hasm"],
|
132
|
+
srid: data_["srid"],
|
133
|
+
wkt_generator: ImplHelper::Utils.symbolize_hash(data_["wktg"]),
|
134
|
+
wkb_generator: ImplHelper::Utils.symbolize_hash(data_["wkbg"]),
|
135
|
+
wkt_parser: ImplHelper::Utils.symbolize_hash(data_["wktp"]),
|
136
|
+
wkb_parser: ImplHelper::Utils.symbolize_hash(data_["wkbp"]),
|
137
|
+
uses_lenient_assertions: data_["lena"],
|
138
|
+
buffer_resolution: data_["bufr"],
|
139
|
+
proj4: proj4_,
|
140
|
+
coord_sys: coord_sys_
|
141
|
+
)
|
142
|
+
end
|
143
|
+
|
144
|
+
# Psych support
|
145
|
+
|
146
|
+
def encode_with(coder_) # :nodoc:
|
147
|
+
coder_["has_z_coordinate"] = @has_z
|
148
|
+
coder_["has_m_coordinate"] = @has_m
|
149
|
+
coder_["srid"] = @srid
|
150
|
+
coder_["lenient_assertions"] = @lenient_assertions
|
151
|
+
coder_["buffer_resolution"] = @buffer_resolution
|
152
|
+
coder_["wkt_generator"] = @wkt_generator._properties
|
153
|
+
coder_["wkb_generator"] = @wkb_generator._properties
|
154
|
+
coder_["wkt_parser"] = @wkt_parser._properties
|
155
|
+
coder_["wkb_parser"] = @wkb_parser._properties
|
156
|
+
if @proj4
|
157
|
+
str_ = @proj4.original_str || @proj4.canonical_str
|
158
|
+
coder_["proj4"] = @proj4.radians? ? { "proj4" => str_, "radians" => true } : str_
|
159
|
+
end
|
160
|
+
coder_["coord_sys"] = @coord_sys.to_wkt if @coord_sys
|
161
|
+
end
|
162
|
+
|
163
|
+
def init_with(coder_) # :nodoc:
|
164
|
+
if (proj4_data_ = coder_["proj4"])
|
165
|
+
if proj4_data_.is_a?(::Hash)
|
166
|
+
proj4_ = CoordSys::Proj4.create(proj4_data_["proj4"], radians: proj4_data_["radians"])
|
167
|
+
else
|
168
|
+
proj4_ = CoordSys::Proj4.create(proj4_data_.to_s)
|
169
|
+
end
|
170
|
+
else
|
171
|
+
proj4_ = nil
|
172
|
+
end
|
173
|
+
if (coord_sys_data_ = coder_["cs"])
|
174
|
+
coord_sys_ = CoordSys::CS.create_from_wkt(coord_sys_data_.to_s)
|
175
|
+
else
|
176
|
+
coord_sys_ = nil
|
177
|
+
end
|
178
|
+
initialize(
|
179
|
+
has_z_coordinate: coder_["has_z_coordinate"],
|
180
|
+
has_m_coordinate: coder_["has_m_coordinate"],
|
181
|
+
srid: coder_["srid"],
|
182
|
+
wkt_generator: ImplHelper::Utils.symbolize_hash(coder_["wkt_generator"]),
|
183
|
+
wkb_generator: ImplHelper::Utils.symbolize_hash(coder_["wkb_generator"]),
|
184
|
+
wkt_parser: ImplHelper::Utils.symbolize_hash(coder_["wkt_parser"]),
|
185
|
+
wkb_parser: ImplHelper::Utils.symbolize_hash(coder_["wkb_parser"]),
|
186
|
+
uses_lenient_assertions: coder_["lenient_assertions"],
|
187
|
+
buffer_resolution: coder_["buffer_resolution"],
|
188
|
+
proj4: proj4_,
|
189
|
+
coord_sys: coord_sys_
|
190
|
+
)
|
191
|
+
end
|
192
|
+
|
193
|
+
# Returns the SRID.
|
194
|
+
|
195
|
+
attr_reader :srid
|
196
|
+
|
197
|
+
# See ::RGeo::Feature::Factory#property
|
198
|
+
|
199
|
+
def property(name_)
|
200
|
+
case name_
|
201
|
+
when :has_z_coordinate
|
202
|
+
@has_z
|
203
|
+
when :has_m_coordinate
|
204
|
+
@has_m
|
205
|
+
when :uses_lenient_assertions
|
206
|
+
@lenient_assertions
|
207
|
+
when :buffer_resolution
|
208
|
+
@buffer_resolution
|
209
|
+
when :is_cartesian
|
210
|
+
true
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
# See ::RGeo::Feature::Factory#parse_wkt
|
215
|
+
|
216
|
+
def parse_wkt(str_)
|
217
|
+
@wkt_parser.parse(str_)
|
218
|
+
end
|
219
|
+
|
220
|
+
# See ::RGeo::Feature::Factory#parse_wkb
|
221
|
+
|
222
|
+
def parse_wkb(str_)
|
223
|
+
@wkb_parser.parse(str_)
|
224
|
+
end
|
225
|
+
|
226
|
+
# See ::RGeo::Feature::Factory#point
|
227
|
+
|
228
|
+
def point(x_, y_, *extra_)
|
229
|
+
PointImpl.new(self, x_, y_, *extra_)
|
230
|
+
rescue
|
231
|
+
nil
|
232
|
+
end
|
233
|
+
|
234
|
+
# See ::RGeo::Feature::Factory#line_string
|
235
|
+
|
236
|
+
def line_string(points_)
|
237
|
+
LineStringImpl.new(self, points_)
|
238
|
+
rescue
|
239
|
+
nil
|
240
|
+
end
|
241
|
+
|
242
|
+
# See ::RGeo::Feature::Factory#line
|
243
|
+
|
244
|
+
def line(start_, end_)
|
245
|
+
LineImpl.new(self, start_, end_)
|
246
|
+
rescue
|
247
|
+
nil
|
248
|
+
end
|
249
|
+
|
250
|
+
# See ::RGeo::Feature::Factory#linear_ring
|
251
|
+
|
252
|
+
def linear_ring(points_)
|
253
|
+
LinearRingImpl.new(self, points_)
|
254
|
+
rescue
|
255
|
+
nil
|
256
|
+
end
|
257
|
+
|
258
|
+
# See ::RGeo::Feature::Factory#polygon
|
259
|
+
|
260
|
+
def polygon(outer_ring_, inner_rings_ = nil)
|
261
|
+
PolygonImpl.new(self, outer_ring_, inner_rings_)
|
262
|
+
rescue
|
263
|
+
nil
|
264
|
+
end
|
265
|
+
|
266
|
+
# See ::RGeo::Feature::Factory#collection
|
267
|
+
|
268
|
+
def collection(elems_)
|
269
|
+
GeometryCollectionImpl.new(self, elems_)
|
270
|
+
rescue
|
271
|
+
nil
|
272
|
+
end
|
273
|
+
|
274
|
+
# See ::RGeo::Feature::Factory#multi_point
|
275
|
+
|
276
|
+
def multi_point(elems_)
|
277
|
+
MultiPointImpl.new(self, elems_)
|
278
|
+
rescue
|
279
|
+
nil
|
280
|
+
end
|
281
|
+
|
282
|
+
# See ::RGeo::Feature::Factory#multi_line_string
|
283
|
+
|
284
|
+
def multi_line_string(elems_)
|
285
|
+
MultiLineStringImpl.new(self, elems_)
|
286
|
+
rescue
|
287
|
+
nil
|
288
|
+
end
|
289
|
+
|
290
|
+
# See ::RGeo::Feature::Factory#multi_polygon
|
291
|
+
|
292
|
+
def multi_polygon(elems_)
|
293
|
+
MultiPolygonImpl.new(self, elems_)
|
294
|
+
rescue
|
295
|
+
nil
|
296
|
+
end
|
297
|
+
|
298
|
+
# See ::RGeo::Feature::Factory#proj4
|
299
|
+
|
300
|
+
attr_reader :proj4
|
301
|
+
|
302
|
+
# See ::RGeo::Feature::Factory#coord_sys
|
303
|
+
|
304
|
+
attr_reader :coord_sys
|
305
|
+
|
306
|
+
def _generate_wkt(obj_) # :nodoc:
|
307
|
+
@wkt_generator.generate(obj_)
|
308
|
+
end
|
309
|
+
|
310
|
+
def _generate_wkb(obj_) # :nodoc:
|
311
|
+
@wkb_generator.generate(obj_)
|
312
|
+
end
|
313
|
+
|
314
|
+
def _marshal_wkb_generator # :nodoc:
|
315
|
+
unless defined?(@marshal_wkb_generator)
|
316
|
+
@marshal_wkb_generator = ::RGeo::WKRep::WKBGenerator.new(
|
317
|
+
type_format: :wkb12)
|
318
|
+
end
|
319
|
+
@marshal_wkb_generator
|
320
|
+
end
|
321
|
+
|
322
|
+
def _marshal_wkb_parser # :nodoc:
|
323
|
+
unless defined?(@marshal_wkb_parser)
|
324
|
+
@marshal_wkb_parser = ::RGeo::WKRep::WKBParser.new(self,
|
325
|
+
support_wkb12: true)
|
326
|
+
end
|
327
|
+
@marshal_wkb_parser
|
328
|
+
end
|
329
|
+
|
330
|
+
def _psych_wkt_generator # :nodoc:
|
331
|
+
unless defined?(@psych_wkt_generator)
|
332
|
+
@psych_wkt_generator = ::RGeo::WKRep::WKTGenerator.new(
|
333
|
+
tag_format: :wkt12)
|
334
|
+
end
|
335
|
+
@psych_wkt_generator
|
336
|
+
end
|
337
|
+
|
338
|
+
def _psych_wkt_parser # :nodoc:
|
339
|
+
unless defined?(@psych_wkt_parser)
|
340
|
+
@psych_wkt_parser = ::RGeo::WKRep::WKTParser.new(self,
|
341
|
+
support_wkt12: true, support_ewkt: true)
|
342
|
+
end
|
343
|
+
@psych_wkt_parser
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|