rgeo 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +29 -0
- data/ext/geos_c_impl/Makefile_2.2.3 +260 -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 +19 -43
- data/ext/geos_c_impl/geometry.c +24 -0
- data/ext/geos_c_impl/geometry_collection.c +99 -1
- data/ext/geos_c_impl/geos_c_impl_2.2.3.bundle +0 -0
- data/ext/geos_c_impl/line_string.c +38 -0
- data/ext/geos_c_impl/mkmf.log +123 -0
- data/ext/geos_c_impl/point.c +27 -0
- data/ext/geos_c_impl/polygon.c +26 -0
- data/ext/proj4_c_impl/Makefile_2.2.3 +260 -0
- data/ext/proj4_c_impl/extconf.rb +32 -32
- data/ext/proj4_c_impl/mkmf.log +47 -0
- data/ext/proj4_c_impl/proj4_c_impl_2.2.3.bundle +0 -0
- data/lib/rgeo.rb +10 -11
- data/lib/rgeo/cartesian.rb +7 -12
- data/lib/rgeo/cartesian/analysis.rb +13 -26
- data/lib/rgeo/cartesian/bounding_box.rb +45 -114
- data/lib/rgeo/cartesian/calculations.rb +3 -21
- data/lib/rgeo/cartesian/factory.rb +101 -122
- data/lib/rgeo/cartesian/feature_classes.rb +9 -59
- data/lib/rgeo/cartesian/feature_methods.rb +15 -45
- data/lib/rgeo/cartesian/interface.rb +6 -17
- data/lib/rgeo/coord_sys.rb +9 -15
- data/lib/rgeo/coord_sys/cs/entities.rb +84 -330
- data/lib/rgeo/coord_sys/cs/factories.rb +2 -32
- data/lib/rgeo/coord_sys/cs/wkt_parser.rb +52 -80
- data/lib/rgeo/coord_sys/proj4.rb +28 -67
- data/lib/rgeo/coord_sys/proj4_c_impl.bundle +0 -0
- data/lib/rgeo/coord_sys/srs_database/interface.rb +4 -24
- data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +20 -38
- data/lib/rgeo/coord_sys/srs_database/sr_org.rb +6 -22
- data/lib/rgeo/coord_sys/srs_database/url_reader.rb +6 -21
- data/lib/rgeo/error.rb +0 -6
- data/lib/rgeo/feature.rb +18 -23
- data/lib/rgeo/feature/curve.rb +0 -14
- data/lib/rgeo/feature/factory.rb +13 -38
- data/lib/rgeo/feature/factory_generator.rb +4 -16
- data/lib/rgeo/feature/geometry.rb +18 -60
- data/lib/rgeo/feature/geometry_collection.rb +3 -17
- data/lib/rgeo/feature/line.rb +0 -10
- data/lib/rgeo/feature/line_string.rb +1 -13
- data/lib/rgeo/feature/linear_ring.rb +0 -9
- data/lib/rgeo/feature/mixins.rb +11 -36
- data/lib/rgeo/feature/multi_curve.rb +0 -11
- data/lib/rgeo/feature/multi_line_string.rb +0 -9
- data/lib/rgeo/feature/multi_point.rb +0 -9
- data/lib/rgeo/feature/multi_polygon.rb +0 -9
- data/lib/rgeo/feature/multi_surface.rb +0 -12
- data/lib/rgeo/feature/point.rb +0 -13
- data/lib/rgeo/feature/polygon.rb +1 -14
- data/lib/rgeo/feature/surface.rb +0 -12
- data/lib/rgeo/feature/types.rb +19 -61
- data/lib/rgeo/geographic.rb +10 -15
- data/lib/rgeo/geographic/factory.rb +126 -147
- data/lib/rgeo/geographic/interface.rb +67 -81
- data/lib/rgeo/geographic/proj4_projector.rb +13 -37
- data/lib/rgeo/geographic/projected_feature_classes.rb +7 -66
- data/lib/rgeo/geographic/projected_feature_methods.rb +15 -80
- data/lib/rgeo/geographic/projected_window.rb +15 -67
- data/lib/rgeo/geographic/simple_mercator_projector.rb +32 -56
- data/lib/rgeo/geographic/spherical_feature_classes.rb +9 -68
- data/lib/rgeo/geographic/spherical_feature_methods.rb +18 -51
- data/lib/rgeo/geographic/spherical_math.rb +26 -51
- data/lib/rgeo/geos.rb +23 -20
- data/lib/rgeo/geos/capi_factory.rb +125 -131
- data/lib/rgeo/geos/capi_feature_classes.rb +21 -88
- data/lib/rgeo/geos/ffi_factory.rb +90 -143
- data/lib/rgeo/geos/ffi_feature_classes.rb +8 -63
- data/lib/rgeo/geos/ffi_feature_methods.rb +46 -162
- data/lib/rgeo/geos/geos_c_impl.bundle +0 -0
- data/lib/rgeo/geos/interface.rb +4 -23
- data/lib/rgeo/geos/utils.rb +4 -19
- data/lib/rgeo/geos/zm_factory.rb +82 -131
- data/lib/rgeo/geos/zm_feature_classes.rb +8 -63
- data/lib/rgeo/geos/zm_feature_methods.rb +34 -107
- data/lib/rgeo/impl_helper.rb +8 -13
- data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +27 -71
- data/lib/rgeo/impl_helper/basic_geometry_methods.rb +10 -28
- data/lib/rgeo/impl_helper/basic_line_string_methods.rb +21 -57
- data/lib/rgeo/impl_helper/basic_point_methods.rb +12 -30
- data/lib/rgeo/impl_helper/basic_polygon_methods.rb +9 -28
- data/lib/rgeo/impl_helper/math.rb +4 -10
- data/lib/rgeo/impl_helper/utils.rb +2 -10
- data/lib/rgeo/version.rb +1 -1
- data/lib/rgeo/wkrep.rb +4 -9
- data/lib/rgeo/wkrep/wkb_generator.rb +22 -46
- data/lib/rgeo/wkrep/wkb_parser.rb +25 -52
- data/lib/rgeo/wkrep/wkt_generator.rb +39 -69
- data/lib/rgeo/wkrep/wkt_parser.rb +52 -89
- data/lib/rgeo/yaml.rb +1 -7
- data/test/common/factory_tests.rb +4 -19
- data/test/common/geometry_collection_tests.rb +6 -39
- data/test/common/line_string_tests.rb +10 -39
- data/test/common/multi_line_string_tests.rb +10 -30
- data/test/common/multi_point_tests.rb +15 -34
- data/test/common/multi_polygon_tests.rb +26 -28
- data/test/common/point_tests.rb +37 -59
- data/test/common/polygon_tests.rb +16 -25
- data/test/coord_sys/tc_ogc_cs.rb +151 -186
- data/test/coord_sys/tc_proj4.rb +35 -60
- data/test/coord_sys/tc_proj4_srs_data.rb +15 -24
- data/test/coord_sys/tc_sr_org.rb +11 -19
- data/test/coord_sys/tc_url_reader.rb +13 -23
- data/test/geos_capi/tc_factory.rb +7 -16
- data/test/geos_capi/tc_geometry_collection.rb +6 -14
- data/test/geos_capi/tc_line_string.rb +7 -15
- data/test/geos_capi/tc_misc.rb +26 -41
- data/test/geos_capi/tc_multi_line_string.rb +6 -14
- data/test/geos_capi/tc_multi_point.rb +7 -15
- data/test/geos_capi/tc_multi_polygon.rb +8 -18
- data/test/geos_capi/tc_parsing_unparsing.rb +11 -21
- data/test/geos_capi/tc_point.rb +12 -26
- data/test/geos_capi/tc_polygon.rb +52 -17
- data/test/geos_capi/tc_zmfactory.rb +7 -18
- data/test/geos_ffi/tc_factory.rb +7 -16
- data/test/geos_ffi/tc_geometry_collection.rb +7 -15
- data/test/geos_ffi/tc_line_string.rb +7 -15
- data/test/geos_ffi/tc_misc.rb +8 -18
- data/test/geos_ffi/tc_multi_line_string.rb +7 -15
- data/test/geos_ffi/tc_multi_point.rb +8 -16
- data/test/geos_ffi/tc_multi_polygon.rb +9 -18
- data/test/geos_ffi/tc_parsing_unparsing.rb +14 -24
- data/test/geos_ffi/tc_point.rb +13 -28
- data/test/geos_ffi/tc_polygon.rb +7 -17
- data/test/geos_ffi/tc_zmfactory.rb +8 -19
- data/test/projected_geographic/tc_factory.rb +7 -15
- data/test/projected_geographic/tc_geometry_collection.rb +7 -15
- data/test/projected_geographic/tc_line_string.rb +7 -15
- data/test/projected_geographic/tc_multi_line_string.rb +7 -16
- data/test/projected_geographic/tc_multi_point.rb +8 -17
- data/test/projected_geographic/tc_multi_polygon.rb +8 -16
- data/test/projected_geographic/tc_point.rb +11 -23
- data/test/projected_geographic/tc_polygon.rb +7 -15
- data/test/simple_cartesian/tc_calculations.rb +6 -22
- data/test/simple_cartesian/tc_factory.rb +7 -16
- data/test/simple_cartesian/tc_geometry_collection.rb +6 -15
- data/test/simple_cartesian/tc_line_string.rb +6 -15
- data/test/simple_cartesian/tc_multi_line_string.rb +6 -15
- data/test/simple_cartesian/tc_multi_point.rb +7 -16
- data/test/simple_cartesian/tc_multi_polygon.rb +7 -16
- data/test/simple_cartesian/tc_point.rb +10 -21
- data/test/simple_cartesian/tc_polygon.rb +6 -15
- data/test/simple_mercator/tc_factory.rb +6 -14
- data/test/simple_mercator/tc_geometry_collection.rb +6 -14
- data/test/simple_mercator/tc_line_string.rb +6 -14
- data/test/simple_mercator/tc_multi_line_string.rb +6 -15
- data/test/simple_mercator/tc_multi_point.rb +7 -16
- data/test/simple_mercator/tc_multi_polygon.rb +7 -15
- data/test/simple_mercator/tc_point.rb +11 -24
- data/test/simple_mercator/tc_polygon.rb +6 -14
- data/test/simple_mercator/tc_window.rb +10 -34
- data/test/spherical_geographic/tc_calculations.rb +5 -32
- data/test/spherical_geographic/tc_factory.rb +6 -15
- data/test/spherical_geographic/tc_geometry_collection.rb +6 -15
- data/test/spherical_geographic/tc_line_string.rb +6 -15
- data/test/spherical_geographic/tc_multi_line_string.rb +6 -15
- data/test/spherical_geographic/tc_multi_point.rb +7 -16
- data/test/spherical_geographic/tc_multi_polygon.rb +7 -16
- data/test/spherical_geographic/tc_point.rb +10 -22
- data/test/spherical_geographic/tc_polygon.rb +6 -15
- data/test/tc_cartesian_analysis.rb +4 -16
- data/test/tc_cartesian_bbox.rb +7 -21
- data/test/tc_mixins.rb +8 -25
- data/test/tc_oneoff.rb +5 -13
- data/test/tc_types.rb +7 -16
- data/test/wkrep/tc_wkb_generator.rb +63 -97
- data/test/wkrep/tc_wkb_parser.rb +63 -100
- data/test/wkrep/tc_wkt_generator.rb +54 -92
- data/test/wkrep/tc_wkt_parser.rb +84 -133
- metadata +39 -9
- data/lib/rgeo/coord_sys/srs_database/active_record_table.rb +0 -166
- data/test/coord_sys/tc_active_record_table.rb +0 -79
@@ -5,13 +5,8 @@
|
|
5
5
|
# -----------------------------------------------------------------------------
|
6
6
|
|
7
7
|
module RGeo
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
module BasicPointMethods # :nodoc:
|
13
|
-
|
14
|
-
|
8
|
+
module ImplHelper # :nodoc:
|
9
|
+
module BasicPointMethods # :nodoc:
|
15
10
|
def initialize(factory_, x_, y_, *extra_)
|
16
11
|
_set_factory(factory_)
|
17
12
|
@x = x_.to_f
|
@@ -24,88 +19,73 @@ module RGeo
|
|
24
19
|
_validate_geometry
|
25
20
|
end
|
26
21
|
|
27
|
-
|
28
22
|
def x
|
29
23
|
@x
|
30
24
|
end
|
31
25
|
|
32
|
-
|
33
26
|
def y
|
34
27
|
@y
|
35
28
|
end
|
36
29
|
|
37
|
-
|
38
30
|
def z
|
39
31
|
@z
|
40
32
|
end
|
41
33
|
|
42
|
-
|
43
34
|
def m
|
44
35
|
@m
|
45
36
|
end
|
46
37
|
|
47
|
-
|
48
38
|
def dimension
|
49
39
|
0
|
50
40
|
end
|
51
41
|
|
52
|
-
|
53
42
|
def geometry_type
|
54
43
|
Feature::Point
|
55
44
|
end
|
56
45
|
|
57
|
-
|
58
46
|
def is_empty?
|
59
47
|
false
|
60
48
|
end
|
61
49
|
|
62
|
-
|
63
50
|
def is_simple?
|
64
51
|
true
|
65
52
|
end
|
66
53
|
|
67
|
-
|
68
54
|
def envelope
|
69
55
|
self
|
70
56
|
end
|
71
57
|
|
72
|
-
|
73
58
|
def boundary
|
74
59
|
factory.collection([])
|
75
60
|
end
|
76
61
|
|
77
|
-
|
78
62
|
def convex_hull
|
79
63
|
self
|
80
64
|
end
|
81
65
|
|
82
|
-
|
83
66
|
def equals?(rhs_)
|
84
|
-
return false unless rhs_.is_a?(self.class) && rhs_.factory ==
|
67
|
+
return false unless rhs_.is_a?(self.class) && rhs_.factory == factory
|
85
68
|
case rhs_
|
86
69
|
when Feature::Point
|
87
70
|
rhs_.x == @x && rhs_.y == @y
|
88
71
|
when Feature::LineString
|
89
|
-
rhs_.num_points > 0 && rhs_.points.all?{ |elem_| equals?(elem_) }
|
72
|
+
rhs_.num_points > 0 && rhs_.points.all? { |elem_| equals?(elem_) }
|
90
73
|
when Feature::GeometryCollection
|
91
|
-
rhs_.num_geometries > 0 && rhs_.all?{ |elem_| equals?(elem_) }
|
74
|
+
rhs_.num_geometries > 0 && rhs_.all? { |elem_| equals?(elem_) }
|
92
75
|
else
|
93
76
|
false
|
94
77
|
end
|
95
78
|
end
|
96
79
|
|
97
|
-
|
98
80
|
def rep_equals?(rhs_)
|
99
81
|
rhs_.is_a?(self.class) && rhs_.factory.eql?(@factory) && @x == rhs_.x && @y == rhs_.y && @z == rhs_.z && @m == rhs_.m
|
100
82
|
end
|
101
83
|
|
102
|
-
|
103
84
|
def hash
|
104
85
|
@hash ||= [factory, geometry_type, @x, @y, @z, @m].hash
|
105
86
|
end
|
106
87
|
|
107
|
-
|
108
|
-
def _copy_state_from(obj_) # :nodoc:
|
88
|
+
def _copy_state_from(obj_) # :nodoc:
|
109
89
|
super
|
110
90
|
@x = obj_.x
|
111
91
|
@y = obj_.y
|
@@ -113,10 +93,12 @@ module RGeo
|
|
113
93
|
@m = obj_.m
|
114
94
|
end
|
115
95
|
|
116
|
-
|
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
|
117
102
|
end
|
118
|
-
|
119
|
-
|
120
103
|
end
|
121
|
-
|
122
104
|
end
|
@@ -5,13 +5,8 @@
|
|
5
5
|
# -----------------------------------------------------------------------------
|
6
6
|
|
7
7
|
module RGeo
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
module BasicPolygonMethods # :nodoc:
|
13
|
-
|
14
|
-
|
8
|
+
module ImplHelper # :nodoc:
|
9
|
+
module BasicPolygonMethods # :nodoc:
|
15
10
|
def initialize(factory_, exterior_ring_, interior_rings_)
|
16
11
|
_set_factory(factory_)
|
17
12
|
@exterior_ring = Feature.cast(exterior_ring_, factory_, Feature::LinearRing)
|
@@ -28,79 +23,65 @@ module RGeo
|
|
28
23
|
_validate_geometry
|
29
24
|
end
|
30
25
|
|
31
|
-
|
32
26
|
def exterior_ring
|
33
27
|
@exterior_ring
|
34
28
|
end
|
35
29
|
|
36
|
-
|
37
30
|
def num_interior_rings
|
38
31
|
@interior_rings.size
|
39
32
|
end
|
40
33
|
|
41
|
-
|
42
34
|
def interior_ring_n(n_)
|
43
35
|
n_ < 0 ? nil : @interior_rings[n_]
|
44
36
|
end
|
45
37
|
|
46
|
-
|
47
38
|
def interior_rings
|
48
39
|
@interior_rings.dup
|
49
40
|
end
|
50
41
|
|
51
|
-
|
52
42
|
def dimension
|
53
43
|
2
|
54
44
|
end
|
55
45
|
|
56
|
-
|
57
46
|
def geometry_type
|
58
47
|
Feature::Polygon
|
59
48
|
end
|
60
49
|
|
61
|
-
|
62
50
|
def is_empty?
|
63
51
|
@exterior_ring.is_empty?
|
64
52
|
end
|
65
53
|
|
66
|
-
|
67
54
|
def boundary
|
68
55
|
array_ = []
|
69
|
-
unless @exterior_ring.is_empty?
|
70
|
-
array_ << @exterior_ring
|
71
|
-
end
|
56
|
+
array_ << @exterior_ring unless @exterior_ring.is_empty?
|
72
57
|
array_.concat(@interior_rings)
|
73
58
|
factory.multi_line_string(array_)
|
74
59
|
end
|
75
60
|
|
76
|
-
|
77
61
|
def rep_equals?(rhs_)
|
78
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
|
79
|
-
rhs_.interior_rings.each_with_index{ |r_, i_| return false unless @interior_rings[i_].rep_equals?(r_) }
|
63
|
+
rhs_.interior_rings.each_with_index { |r_, i_| return false unless @interior_rings[i_].rep_equals?(r_) }
|
80
64
|
else
|
81
65
|
false
|
82
66
|
end
|
83
67
|
end
|
84
68
|
|
85
|
-
|
86
69
|
def hash
|
87
70
|
@hash ||= begin
|
88
71
|
hash_ = [geometry_type, @exterior_ring].hash
|
89
|
-
@interior_rings.inject(hash_){ |h_, r_| (
|
72
|
+
@interior_rings.inject(hash_) { |h_, r_| (1_664_525 * h_ + r_.hash).hash }
|
90
73
|
end
|
91
74
|
end
|
92
75
|
|
93
|
-
|
94
|
-
def _copy_state_from(obj_) # :nodoc:
|
76
|
+
def _copy_state_from(obj_) # :nodoc:
|
95
77
|
super
|
96
78
|
@exterior_ring = obj_.exterior_ring
|
97
79
|
@interior_rings = obj_.interior_rings
|
98
80
|
end
|
99
81
|
|
100
|
-
|
82
|
+
def coordinates
|
83
|
+
([@exterior_ring] + @interior_rings).map(&:coordinates)
|
84
|
+
end
|
101
85
|
end
|
102
|
-
|
103
|
-
|
104
86
|
end
|
105
|
-
|
106
87
|
end
|
@@ -5,16 +5,10 @@
|
|
5
5
|
# -----------------------------------------------------------------------------
|
6
6
|
|
7
7
|
module RGeo
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
RADIANS_PER_DEGREE = ::Math::PI/180.0
|
14
|
-
DEGREES_PER_RADIAN = 180.0/::Math::PI
|
15
|
-
|
8
|
+
module ImplHelper # :nodoc:
|
9
|
+
module Math # :nodoc:
|
10
|
+
RADIANS_PER_DEGREE = ::Math::PI / 180.0
|
11
|
+
DEGREES_PER_RADIAN = 180.0 / ::Math::PI
|
16
12
|
end
|
17
|
-
|
18
13
|
end
|
19
|
-
|
20
14
|
end
|
@@ -5,13 +5,9 @@
|
|
5
5
|
# -----------------------------------------------------------------------------
|
6
6
|
|
7
7
|
module RGeo
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
module Utils # :nodoc:
|
12
|
-
|
8
|
+
module ImplHelper # :nodoc:
|
9
|
+
module Utils # :nodoc:
|
13
10
|
class << self
|
14
|
-
|
15
11
|
def stringize_hash(hash_)
|
16
12
|
nhash_ = {}
|
17
13
|
hash_.each do |k_, v_|
|
@@ -27,11 +23,7 @@ module RGeo
|
|
27
23
|
end
|
28
24
|
nhash_
|
29
25
|
end
|
30
|
-
|
31
26
|
end
|
32
|
-
|
33
27
|
end
|
34
|
-
|
35
28
|
end
|
36
|
-
|
37
29
|
end
|
data/lib/rgeo/version.rb
CHANGED
data/lib/rgeo/wkrep.rb
CHANGED
@@ -5,8 +5,6 @@
|
|
5
5
|
# -----------------------------------------------------------------------------
|
6
6
|
|
7
7
|
module RGeo
|
8
|
-
|
9
|
-
|
10
8
|
# This module contains implementations of the OpenGIS well-known
|
11
9
|
# representations: the WKT (well-known text representation) and the
|
12
10
|
# WKB (well-known binary representation), as defined in the Simple
|
@@ -30,13 +28,10 @@ module RGeo
|
|
30
28
|
|
31
29
|
module WKRep
|
32
30
|
end
|
33
|
-
|
34
|
-
|
35
31
|
end
|
36
32
|
|
37
|
-
|
38
33
|
# Implementation files
|
39
|
-
require
|
40
|
-
require
|
41
|
-
require
|
42
|
-
require
|
34
|
+
require "rgeo/wkrep/wkt_parser"
|
35
|
+
require "rgeo/wkrep/wkt_generator"
|
36
|
+
require "rgeo/wkrep/wkb_parser"
|
37
|
+
require "rgeo/wkrep/wkb_generator"
|
@@ -5,10 +5,7 @@
|
|
5
5
|
# -----------------------------------------------------------------------------
|
6
6
|
|
7
7
|
module RGeo
|
8
|
-
|
9
8
|
module WKRep
|
10
|
-
|
11
|
-
|
12
9
|
# This class provides the functionality of serializing a geometry as
|
13
10
|
# WKB (well-known binary) format. You may also customize the
|
14
11
|
# serializer to generate PostGIS EWKB extensions to the output, or to
|
@@ -42,8 +39,6 @@ module RGeo
|
|
42
39
|
# big endian (XDR), or network byte order. Default is false.
|
43
40
|
|
44
41
|
class WKBGenerator
|
45
|
-
|
46
|
-
|
47
42
|
# :stopdoc:
|
48
43
|
TYPE_CODES = {
|
49
44
|
Feature::Point => 1,
|
@@ -54,15 +49,14 @@ module RGeo
|
|
54
49
|
Feature::MultiPoint => 4,
|
55
50
|
Feature::MultiLineString => 5,
|
56
51
|
Feature::MultiPolygon => 6,
|
57
|
-
Feature::GeometryCollection => 7
|
52
|
+
Feature::GeometryCollection => 7
|
58
53
|
}.freeze
|
59
54
|
# :startdoc:
|
60
55
|
|
61
|
-
|
62
56
|
# Create and configure a WKB generator. See the WKBGenerator
|
63
57
|
# documentation for the options that can be passed.
|
64
58
|
|
65
|
-
def initialize(opts_={})
|
59
|
+
def initialize(opts_ = {})
|
66
60
|
@type_format = opts_[:type_format] || :wkb11
|
67
61
|
@emit_ewkb_srid = @type_format == :ewkb ?
|
68
62
|
(opts_[:emit_ewkb_srid] ? true : false) : nil
|
@@ -70,11 +64,8 @@ module RGeo
|
|
70
64
|
@little_endian = opts_[:little_endian] ? true : false
|
71
65
|
end
|
72
66
|
|
73
|
-
|
74
67
|
# Returns the format for type codes. See WKBGenerator for details.
|
75
|
-
|
76
|
-
@type_format
|
77
|
-
end
|
68
|
+
attr_reader :type_format
|
78
69
|
|
79
70
|
# Returns whether SRID is embedded. See WKBGenerator for details.
|
80
71
|
def emit_ewkb_srid?
|
@@ -93,17 +84,15 @@ module RGeo
|
|
93
84
|
@little_endian
|
94
85
|
end
|
95
86
|
|
96
|
-
|
97
|
-
def _properties # :nodoc:
|
87
|
+
def _properties # :nodoc:
|
98
88
|
{
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
89
|
+
"type_format" => @type_format.to_s,
|
90
|
+
"emit_ewkb_srid" => @emit_ewkb_srid,
|
91
|
+
"hex_format" => @hex_format,
|
92
|
+
"little_endian" => @little_endian
|
103
93
|
}
|
104
94
|
end
|
105
95
|
|
106
|
-
|
107
96
|
# Generate and return the WKB format for the given geometry object,
|
108
97
|
# according to the current settings.
|
109
98
|
|
@@ -122,8 +111,7 @@ module RGeo
|
|
122
111
|
_finish_emitter
|
123
112
|
end
|
124
113
|
|
125
|
-
|
126
|
-
def _generate_feature(obj_, toplevel_=false) # :nodoc:
|
114
|
+
def _generate_feature(obj_, toplevel_ = false) # :nodoc:
|
127
115
|
_emit_byte(@little_endian ? 1 : 0)
|
128
116
|
type_ = obj_.geometry_type
|
129
117
|
type_code_ = TYPE_CODES[type_]
|
@@ -155,25 +143,24 @@ module RGeo
|
|
155
143
|
else
|
156
144
|
_emit_integer(1 + obj_.num_interior_rings)
|
157
145
|
_emit_line_string_coords(exterior_ring_)
|
158
|
-
obj_.interior_rings.each{ |r_| _emit_line_string_coords(r_) }
|
146
|
+
obj_.interior_rings.each { |r_| _emit_line_string_coords(r_) }
|
159
147
|
end
|
160
148
|
elsif type_ == Feature::GeometryCollection
|
161
149
|
_emit_integer(obj_.num_geometries)
|
162
|
-
obj_.each{ |g_| _generate_feature(g_) }
|
150
|
+
obj_.each { |g_| _generate_feature(g_) }
|
163
151
|
elsif type_ == Feature::MultiPoint
|
164
152
|
_emit_integer(obj_.num_geometries)
|
165
|
-
obj_.each{ |g_| _generate_feature(g_) }
|
153
|
+
obj_.each { |g_| _generate_feature(g_) }
|
166
154
|
elsif type_ == Feature::MultiLineString
|
167
155
|
_emit_integer(obj_.num_geometries)
|
168
|
-
obj_.each{ |g_| _generate_feature(g_) }
|
156
|
+
obj_.each { |g_| _generate_feature(g_) }
|
169
157
|
elsif type_ == Feature::MultiPolygon
|
170
158
|
_emit_integer(obj_.num_geometries)
|
171
|
-
obj_.each{ |g_| _generate_feature(g_) }
|
159
|
+
obj_.each { |g_| _generate_feature(g_) }
|
172
160
|
end
|
173
161
|
end
|
174
162
|
|
175
|
-
|
176
|
-
def _point_coords(obj_, array_=[]) # :nodoc:
|
163
|
+
def _point_coords(obj_, array_ = []) # :nodoc:
|
177
164
|
array_ << obj_.x
|
178
165
|
array_ << obj_.y
|
179
166
|
array_ << obj_.z if @cur_has_z
|
@@ -181,45 +168,34 @@ module RGeo
|
|
181
168
|
array_
|
182
169
|
end
|
183
170
|
|
184
|
-
|
185
|
-
def _emit_line_string_coords(obj_) # :nodoc:
|
171
|
+
def _emit_line_string_coords(obj_) # :nodoc:
|
186
172
|
array_ = []
|
187
|
-
obj_.points.each{ |p_| _point_coords(p_, array_) }
|
173
|
+
obj_.points.each { |p_| _point_coords(p_, array_) }
|
188
174
|
_emit_integer(obj_.num_points)
|
189
175
|
_emit_doubles(array_)
|
190
176
|
end
|
191
177
|
|
192
|
-
|
193
|
-
def _start_emitter # :nodoc:
|
178
|
+
def _start_emitter # :nodoc:
|
194
179
|
@cur_array = []
|
195
180
|
end
|
196
181
|
|
197
|
-
|
198
|
-
def _emit_byte(value_) # :nodoc:
|
182
|
+
def _emit_byte(value_) # :nodoc:
|
199
183
|
@cur_array << [value_].pack("C")
|
200
184
|
end
|
201
185
|
|
202
|
-
|
203
186
|
def _emit_integer(value_) # :nodoc:
|
204
|
-
@cur_array << [value_].pack(@little_endian ?
|
187
|
+
@cur_array << [value_].pack(@little_endian ? "V" : "N")
|
205
188
|
end
|
206
189
|
|
207
|
-
|
208
190
|
def _emit_doubles(array_) # :nodoc:
|
209
|
-
@cur_array << array_.pack(@little_endian ?
|
191
|
+
@cur_array << array_.pack(@little_endian ? "E*" : "G*")
|
210
192
|
end
|
211
193
|
|
212
|
-
|
213
|
-
def _finish_emitter # :nodoc:
|
194
|
+
def _finish_emitter # :nodoc:
|
214
195
|
str_ = @cur_array.join
|
215
196
|
@cur_array = nil
|
216
197
|
@hex_format ? str_.unpack("H*")[0] : str_
|
217
198
|
end
|
218
|
-
|
219
|
-
|
220
199
|
end
|
221
|
-
|
222
|
-
|
223
200
|
end
|
224
|
-
|
225
201
|
end
|