georuby 2.3.0 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -9
- data/Rakefile +13 -14
- data/lib/geo_ruby/ewk.rb +2 -0
- data/lib/geo_ruby/{simple_features → ewk}/ewkb_parser.rb +206 -218
- data/lib/geo_ruby/ewk/ewkt_parser.rb +321 -0
- data/lib/geo_ruby/geojson.rb +27 -32
- data/lib/geo_ruby/georss.rb +88 -66
- data/lib/geo_ruby/gpx.rb +113 -1
- data/lib/geo_ruby/kml.rb +43 -31
- data/lib/geo_ruby/shp.rb +1 -0
- data/lib/geo_ruby/shp4r/dbf.rb +7 -3
- data/lib/geo_ruby/shp4r/shp.rb +297 -284
- data/lib/geo_ruby/simple_features.rb +2 -6
- data/lib/geo_ruby/simple_features/circle.rb +15 -13
- data/lib/geo_ruby/simple_features/envelope.rb +84 -77
- data/lib/geo_ruby/simple_features/geometry.rb +89 -69
- data/lib/geo_ruby/simple_features/geometry_collection.rb +46 -43
- data/lib/geo_ruby/simple_features/geometry_factory.rb +50 -47
- data/lib/geo_ruby/simple_features/helper.rb +14 -14
- data/lib/geo_ruby/simple_features/line_string.rb +94 -97
- data/lib/geo_ruby/simple_features/linear_ring.rb +4 -9
- data/lib/geo_ruby/simple_features/multi_line_string.rb +18 -21
- data/lib/geo_ruby/simple_features/multi_point.rb +18 -20
- data/lib/geo_ruby/simple_features/multi_polygon.rb +19 -25
- data/lib/geo_ruby/simple_features/point.rb +134 -128
- data/lib/geo_ruby/simple_features/polygon.rb +60 -59
- data/lib/geo_ruby/version.rb +1 -1
- data/spec/data/geojson/feature.json +9 -0
- data/spec/data/geojson/feature_collection.json +3 -4
- data/spec/geo_ruby/{simple_features → ewk}/ewkb_parser_spec.rb +56 -57
- data/spec/geo_ruby/{simple_features → ewk}/ewkt_parser_spec.rb +62 -63
- data/spec/geo_ruby/geojson_spec.rb +34 -17
- data/spec/geo_ruby/georss_spec.rb +76 -64
- data/spec/geo_ruby/{gpx4r/gpx_spec.rb → gpx_spec.rb} +25 -25
- data/spec/geo_ruby/kml_spec.rb +40 -36
- data/spec/geo_ruby/shp4r/shp_spec.rb +51 -51
- data/spec/geo_ruby/simple_features/circle_spec.rb +2 -2
- data/spec/geo_ruby/simple_features/envelope_spec.rb +8 -8
- data/spec/geo_ruby/simple_features/geometry_collection_spec.rb +26 -26
- data/spec/geo_ruby/simple_features/geometry_factory_spec.rb +5 -5
- data/spec/geo_ruby/simple_features/geometry_spec.rb +8 -8
- data/spec/geo_ruby/simple_features/line_string_spec.rb +102 -102
- data/spec/geo_ruby/simple_features/linear_ring_spec.rb +7 -7
- data/spec/geo_ruby/simple_features/multi_line_string_spec.rb +20 -20
- data/spec/geo_ruby/simple_features/multi_point_spec.rb +16 -16
- data/spec/geo_ruby/simple_features/multi_polygon_spec.rb +19 -19
- data/spec/geo_ruby/simple_features/point_spec.rb +180 -174
- data/spec/geo_ruby/simple_features/polygon_spec.rb +55 -56
- data/spec/geo_ruby_spec.rb +4 -4
- data/spec/spec_helper.rb +19 -13
- metadata +10 -9
- data/lib/geo_ruby/gpx4r/gpx.rb +0 -118
- data/lib/geo_ruby/simple_features/ewkt_parser.rb +0 -336
@@ -2,119 +2,118 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
2
2
|
|
3
3
|
describe GeoRuby::SimpleFeatures::Polygon do
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe 'Instance Methods' do
|
6
6
|
|
7
|
-
let(:poly) { GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256) }
|
7
|
+
let(:poly) { GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0], [4, 0], [4, 4], [0, 4], [0, 0]], [[1, 1], [3, 1], [3, 3], [1, 3], [1, 1]]], 256) }
|
8
8
|
|
9
|
-
it
|
9
|
+
it 'should check if contains point' do
|
10
10
|
expect(poly.contains_point?(GeoRuby::SimpleFeatures::Point.from_x_y(3, 3))).to be_truthy
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'should check if not contains point' do
|
14
14
|
expect(poly.contains_point?(GeoRuby::SimpleFeatures::Point.from_x_y(5, 5))).to be_falsey
|
15
15
|
end
|
16
16
|
|
17
17
|
end
|
18
18
|
|
19
|
-
describe
|
20
|
-
#no test of the binary representation for linear_rings : always with polygons and like line_string
|
21
|
-
it
|
22
|
-
linear_ring1 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[12.4
|
23
|
-
linear_ring2 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]],256)
|
24
|
-
point1 = GeoRuby::SimpleFeatures::Point.from_x_y(12.4
|
25
|
-
point2 = GeoRuby::SimpleFeatures::Point.from_x_y(45.4,41.6,256)
|
26
|
-
point3 = GeoRuby::SimpleFeatures::Point.from_x_y(4.456,1.0698,256)
|
27
|
-
point4 = GeoRuby::SimpleFeatures::Point.from_x_y(12.4
|
28
|
-
point5 = GeoRuby::SimpleFeatures::Point.from_x_y(2.4,5.3,256)
|
29
|
-
point6 = GeoRuby::SimpleFeatures::Point.from_x_y(5.4,1.4263,256)
|
30
|
-
point7 = GeoRuby::SimpleFeatures::Point.from_x_y(14.46,1.06,256)
|
31
|
-
point8 = GeoRuby::SimpleFeatures::Point.from_x_y(2.4,5.3,256)
|
32
|
-
|
33
|
-
polygon = GeoRuby::SimpleFeatures::Polygon
|
19
|
+
describe 'tu converted' do
|
20
|
+
# no test of the binary representation for linear_rings : always with polygons and like line_string
|
21
|
+
it 'should test_polygon_creation' do
|
22
|
+
linear_ring1 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[12.4, -45.3], [45.4, 41.6], [4.456, 1.0698], [12.4, -45.3]], 256)
|
23
|
+
linear_ring2 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[2.4, 5.3], [5.4, 1.4263], [14.46, 1.06], [2.4, 5.3]], 256)
|
24
|
+
point1 = GeoRuby::SimpleFeatures::Point.from_x_y(12.4, -45.3, 256)
|
25
|
+
point2 = GeoRuby::SimpleFeatures::Point.from_x_y(45.4, 41.6, 256)
|
26
|
+
point3 = GeoRuby::SimpleFeatures::Point.from_x_y(4.456, 1.0698, 256)
|
27
|
+
point4 = GeoRuby::SimpleFeatures::Point.from_x_y(12.4, -45.3, 256)
|
28
|
+
point5 = GeoRuby::SimpleFeatures::Point.from_x_y(2.4, 5.3, 256)
|
29
|
+
point6 = GeoRuby::SimpleFeatures::Point.from_x_y(5.4, 1.4263, 256)
|
30
|
+
point7 = GeoRuby::SimpleFeatures::Point.from_x_y(14.46, 1.06, 256)
|
31
|
+
point8 = GeoRuby::SimpleFeatures::Point.from_x_y(2.4, 5.3, 256)
|
32
|
+
|
33
|
+
polygon = GeoRuby::SimpleFeatures::Polygon.new(256)
|
34
34
|
expect(polygon.length).to be_zero
|
35
35
|
|
36
36
|
polygon << linear_ring1
|
37
37
|
expect(polygon.length).to eql(1)
|
38
38
|
expect(polygon[0]).to eq(linear_ring1)
|
39
39
|
|
40
|
-
#the validity of the hole is not checked : just for the sake of example
|
40
|
+
# the validity of the hole is not checked : just for the sake of example
|
41
41
|
polygon << linear_ring2
|
42
42
|
expect(polygon.length).to eql(2)
|
43
43
|
expect(polygon[1]).to eq(linear_ring2)
|
44
44
|
|
45
|
-
polygon = GeoRuby::SimpleFeatures::Polygon.from_linear_rings([linear_ring1,linear_ring2],256)
|
45
|
+
polygon = GeoRuby::SimpleFeatures::Polygon.from_linear_rings([linear_ring1, linear_ring2], 256)
|
46
46
|
expect(polygon.class).to eql(GeoRuby::SimpleFeatures::Polygon)
|
47
47
|
expect(polygon.length).to eql(2)
|
48
48
|
expect(polygon[0]).to eq(linear_ring1)
|
49
49
|
expect(polygon[1]).to eq(linear_ring2)
|
50
50
|
|
51
|
-
polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4
|
51
|
+
polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4, -45.3], [45.4, 41.6], [4.456, 1.0698], [12.4, -45.3]], [[2.4, 5.3], [5.4, 1.4263], [14.46, 1.06], [2.4, 5.3]]], 256)
|
52
52
|
expect(polygon.class).to eql(GeoRuby::SimpleFeatures::Polygon)
|
53
53
|
expect(polygon.length).to eql(2)
|
54
54
|
expect(polygon[0]).to eq(linear_ring1)
|
55
55
|
expect(polygon[1]).to eq(linear_ring2)
|
56
56
|
|
57
|
-
polygon = GeoRuby::SimpleFeatures::Polygon.from_points([[point1,point2,point3,point4],[point5,point6,point7,point8]],256)
|
57
|
+
polygon = GeoRuby::SimpleFeatures::Polygon.from_points([[point1, point2, point3, point4], [point5, point6, point7, point8]], 256)
|
58
58
|
expect(polygon.length).to eql(2)
|
59
59
|
expect(polygon[0]).to eq(linear_ring1)
|
60
60
|
expect(polygon[1]).to eq(linear_ring2)
|
61
61
|
|
62
|
-
polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4
|
62
|
+
polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4, -45.3, 15.2], [45.4, 41.6, 2.4], [4.456, 1.0698, 5.6], [12.4, -45.3, 6.1]], [[2.4, 5.3, 4.5], [5.4, 1.4263, 4.2], [14.46, 1.06, 123.1], [2.4, 5.3, 4.4]]], 256, true)
|
63
63
|
expect(polygon.class).to eql(GeoRuby::SimpleFeatures::Polygon)
|
64
64
|
expect(polygon.length).to eql(2)
|
65
65
|
|
66
|
-
linear_ring1 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[12.4
|
67
|
-
linear_ring2 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[2.4,5.3,4.5],[5.4,1.4263,4.2],[14.46,1.06,123.1],[2.4,5.3,4.4]],256,true)
|
66
|
+
linear_ring1 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[12.4, -45.3, 15.2], [45.4, 41.6, 2.4], [4.456, 1.0698, 5.6], [12.4, -45.3, 6.1]], 256, true)
|
67
|
+
linear_ring2 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[2.4, 5.3, 4.5], [5.4, 1.4263, 4.2], [14.46, 1.06, 123.1], [2.4, 5.3, 4.4]], 256, true)
|
68
68
|
expect(polygon[0]).to eq(linear_ring1)
|
69
69
|
expect(polygon[1]).to eq(linear_ring2)
|
70
70
|
end
|
71
71
|
|
72
|
-
it
|
73
|
-
bbox = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4
|
72
|
+
it 'bbox' do
|
73
|
+
bbox = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4, -45.3, 15.2], [45.4, 41.6, 2.4], [4.456, 1.0698, 5.6], [12.4, -45.3, 6.1]], [[2.4, 5.3, 4.5], [5.4, 1.4263, 4.2], [14.46, 1.06, 123.1], [2.4, 5.3, 4.4]]], 256, true).bounding_box
|
74
74
|
expect(bbox.length).to eql(2)
|
75
|
-
expect(bbox[0]).to eq(GeoRuby::SimpleFeatures::Point.from_x_y_z(4.456
|
76
|
-
expect(bbox[1]).to eq(GeoRuby::SimpleFeatures::Point.from_x_y_z(45.4,41.6,123.1))
|
75
|
+
expect(bbox[0]).to eq(GeoRuby::SimpleFeatures::Point.from_x_y_z(4.456, -45.3, 2.4))
|
76
|
+
expect(bbox[1]).to eq(GeoRuby::SimpleFeatures::Point.from_x_y_z(45.4, 41.6, 123.1))
|
77
77
|
end
|
78
78
|
|
79
|
+
it 'test_polygon_equal' do
|
80
|
+
polygon1 = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4, -45.3], [45.4, 41.6], [4.456, 1.0698], [12.4, -45.3]], [[2.4, 5.3], [5.4, 1.4263], [14.46, 1.06], [2.4, 5.3]]], 256)
|
81
|
+
polygon2 = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4, -45.3], [45.4, 41.6], [4.456, 1.0698], [12.4, -45.3]], [[2.4, 5.3], [5.4, 1.4263], [14.46, 1.06]]])
|
82
|
+
point = GeoRuby::SimpleFeatures::Point.from_x_y(12.4, -45.3, 123)
|
79
83
|
|
80
|
-
|
81
|
-
polygon1 = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256)
|
82
|
-
polygon2 = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06]]])
|
83
|
-
point = GeoRuby::SimpleFeatures::Point.from_x_y(12.4,-45.3,123)
|
84
|
-
|
85
|
-
expect(polygon1).to eq(GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256))
|
84
|
+
expect(polygon1).to eq(GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4, -45.3], [45.4, 41.6], [4.456, 1.0698], [12.4, -45.3]], [[2.4, 5.3], [5.4, 1.4263], [14.46, 1.06], [2.4, 5.3]]], 256))
|
86
85
|
expect(polygon1).not_to eq(polygon2)
|
87
86
|
expect(polygon1).not_to eq(point)
|
88
87
|
end
|
89
88
|
|
90
|
-
it
|
91
|
-
polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)
|
92
|
-
#taken from PostGIS answer
|
93
|
-
expect(polygon.as_hex_ewkb).to eql(
|
89
|
+
it 'test_polygon_binary' do
|
90
|
+
polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0], [4, 0], [4, 4], [0, 4], [0, 0]], [[1, 1], [3, 1], [3, 3], [1, 3], [1, 1]]], 256)
|
91
|
+
# taken from PostGIS answer
|
92
|
+
expect(polygon.as_hex_ewkb).to eql('0103000020000100000200000005000000000000000000000000000000000000000000000000001040000000000000000000000000000010400000000000001040000000000000000000000000000010400000000000000000000000000000000005000000000000000000F03F000000000000F03F0000000000000840000000000000F03F00000000000008400000000000000840000000000000F03F0000000000000840000000000000F03F000000000000F03F')
|
94
93
|
|
95
|
-
polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,true)
|
96
|
-
#taken from PostGIS answer
|
97
|
-
expect(polygon.as_hex_ewkb).to eql(
|
94
|
+
polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0, 2], [4, 0, 2], [4, 4, 2], [0, 4, 2], [0, 0, 2]], [[1, 1, 2], [3, 1, 2], [3, 3, 2], [1, 3, 2], [1, 1, 2]]], 256, true)
|
95
|
+
# taken from PostGIS answer
|
96
|
+
expect(polygon.as_hex_ewkb).to eql('01030000A000010000020000000500000000000000000000000000000000000000000000000000004000000000000010400000000000000000000000000000004000000000000010400000000000001040000000000000004000000000000000000000000000001040000000000000004000000000000000000000000000000000000000000000004005000000000000000000F03F000000000000F03F00000000000000400000000000000840000000000000F03F0000000000000040000000000000084000000000000008400000000000000040000000000000F03F00000000000008400000000000000040000000000000F03F000000000000F03F0000000000000040')
|
98
97
|
|
99
|
-
polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,false,true)
|
100
|
-
expect(polygon.as_hex_ewkb).to eql(
|
98
|
+
polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0, 2], [4, 0, 2], [4, 4, 2], [0, 4, 2], [0, 0, 2]], [[1, 1, 2], [3, 1, 2], [3, 3, 2], [1, 3, 2], [1, 1, 2]]], 256, false, true)
|
99
|
+
expect(polygon.as_hex_ewkb).to eql('010300006000010000020000000500000000000000000000000000000000000000000000000000004000000000000010400000000000000000000000000000004000000000000010400000000000001040000000000000004000000000000000000000000000001040000000000000004000000000000000000000000000000000000000000000004005000000000000000000F03F000000000000F03F00000000000000400000000000000840000000000000F03F0000000000000040000000000000084000000000000008400000000000000040000000000000F03F00000000000008400000000000000040000000000000F03F000000000000F03F0000000000000040')
|
101
100
|
|
102
|
-
polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,2
|
103
|
-
expect(polygon.as_hex_ewkb).to eql(
|
101
|
+
polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0, 2, -45.1], [4, 0, 2, 5], [4, 4, 2, 4.67], [0, 4, 2, 1.34], [0, 0, 2, -45.1]], [[1, 1, 2, 12.3], [3, 1, 2, 123], [3, 3, 2, 12.2], [1, 3, 2, 12], [1, 1, 2, 12.3]]], 256, true, true)
|
102
|
+
expect(polygon.as_hex_ewkb).to eql('01030000E0000100000200000005000000000000000000000000000000000000000000000000000040CDCCCCCCCC8C46C00000000000001040000000000000000000000000000000400000000000001440000000000000104000000000000010400000000000000040AE47E17A14AE1240000000000000000000000000000010400000000000000040713D0AD7A370F53F000000000000000000000000000000000000000000000040CDCCCCCCCC8C46C005000000000000000000F03F000000000000F03F00000000000000409A999999999928400000000000000840000000000000F03F00000000000000400000000000C05E400000000000000840000000000000084000000000000000406666666666662840000000000000F03F000000000000084000000000000000400000000000002840000000000000F03F000000000000F03F00000000000000409A99999999992840')
|
104
103
|
end
|
105
104
|
|
106
|
-
it
|
107
|
-
polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)
|
108
|
-
expect(polygon.as_ewkt).to eql(
|
105
|
+
it 'should test_polygon_text' do
|
106
|
+
polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0], [4, 0], [4, 4], [0, 4], [0, 0]], [[1, 1], [3, 1], [3, 3], [1, 3], [1, 1]]], 256)
|
107
|
+
expect(polygon.as_ewkt).to eql('SRID=256;POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1,3 1,3 3,1 3,1 1))')
|
109
108
|
|
110
|
-
polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,true)
|
111
|
-
expect(polygon.as_ewkt).to eql(
|
109
|
+
polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0, 2], [4, 0, 2], [4, 4, 2], [0, 4, 2], [0, 0, 2]], [[1, 1, 2], [3, 1, 2], [3, 3, 2], [1, 3, 2], [1, 1, 2]]], 256, true)
|
110
|
+
expect(polygon.as_ewkt).to eql('SRID=256;POLYGON((0 0 2,4 0 2,4 4 2,0 4 2,0 0 2),(1 1 2,3 1 2,3 3 2,1 3 2,1 1 2))')
|
112
111
|
|
113
|
-
polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,false,true)
|
114
|
-
expect(polygon.as_ewkt).to eql(
|
112
|
+
polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0, 2], [4, 0, 2], [4, 4, 2], [0, 4, 2], [0, 0, 2]], [[1, 1, 2], [3, 1, 2], [3, 3, 2], [1, 3, 2], [1, 1, 2]]], 256, false, true)
|
113
|
+
expect(polygon.as_ewkt).to eql('SRID=256;POLYGONM((0 0 2,4 0 2,4 4 2,0 4 2,0 0 2),(1 1 2,3 1 2,3 3 2,1 3 2,1 1 2))')
|
115
114
|
|
116
|
-
polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,2
|
117
|
-
expect(polygon.as_ewkt).to eql(
|
115
|
+
polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0, 2, -45.1], [4, 0, 2, 5], [4, 4, 2, 4.67], [0, 4, 2, 1.34], [0, 0, 2, -45.1]], [[1, 1, 2, 12.3], [3, 1, 2, 123], [3, 3, 2, 12.2], [1, 3, 2, 12], [1, 1, 2, 12.3]]], 256, true, true)
|
116
|
+
expect(polygon.as_ewkt).to eql('SRID=256;POLYGON((0 0 2 -45.1,4 0 2 5,4 4 2 4.67,0 4 2 1.34,0 0 2 -45.1),(1 1 2 12.3,3 1 2 123,3 3 2 12.2,1 3 2 12,1 1 2 12.3))')
|
118
117
|
end
|
119
118
|
|
120
119
|
end
|
data/spec/geo_ruby_spec.rb
CHANGED
@@ -3,18 +3,18 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
3
3
|
# Time to add your specs!
|
4
4
|
# http://rspec.info/
|
5
5
|
describe GeoRuby do
|
6
|
-
|
7
|
-
it
|
6
|
+
|
7
|
+
it 'should instantiate Geometry' do
|
8
8
|
@geo = GeoRuby::SimpleFeatures::Geometry.new
|
9
9
|
expect(@geo.class).to eql(::GeoRuby::SimpleFeatures::Geometry)
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it 'should instantiate Point' do
|
13
13
|
@point = GeoRuby::SimpleFeatures::Point.new
|
14
14
|
expect(@point).to be_instance_of(::GeoRuby::SimpleFeatures::Point)
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'should instantiate Line' do
|
18
18
|
@line = GeoRuby::SimpleFeatures::LineString.new
|
19
19
|
expect(@line).to be_instance_of(::GeoRuby::SimpleFeatures::LineString)
|
20
20
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,38 +3,39 @@ require 'rubygems'
|
|
3
3
|
# Must require active_spport/core_ext/object and then json/pure
|
4
4
|
# or the json module gets clobbered and geojson output
|
5
5
|
# becomes invalid... ie. it never calls class specific to_json
|
6
|
-
#require 'active_support/core_ext/object'
|
7
|
-
#require 'json/pure'
|
6
|
+
# require 'active_support/core_ext/object'
|
7
|
+
# require 'json/pure'
|
8
8
|
|
9
9
|
require 'rspec'
|
10
10
|
|
11
11
|
require 'geo_ruby'
|
12
|
+
require 'geo_ruby/ewk'
|
12
13
|
require 'geo_ruby/shp'
|
13
14
|
require 'geo_ruby/gpx'
|
14
|
-
require 'geo_ruby/geojson'
|
15
|
-
require 'geo_ruby/georss'
|
16
15
|
require 'geo_ruby/kml'
|
16
|
+
require 'geo_ruby/georss'
|
17
|
+
require 'geo_ruby/geojson'
|
17
18
|
|
18
|
-
if ENV[
|
19
|
+
if ENV['CI']
|
19
20
|
require 'coveralls'
|
20
21
|
Coveralls.wear!
|
21
22
|
end
|
22
23
|
|
23
24
|
module GeorubyMatchers
|
24
|
-
|
25
25
|
class BeGeometric
|
26
|
-
|
27
26
|
def matches?(actual)
|
28
|
-
actual.ancestors.include?(actual) || actual.
|
27
|
+
actual.ancestors.include?(actual) || actual.is_a?('Geometry')
|
29
28
|
end
|
30
29
|
|
31
|
-
def failure_message
|
30
|
+
def failure_message
|
31
|
+
"expected #{@actual.inspect} to be some geom"
|
32
|
+
end
|
32
33
|
end
|
33
34
|
|
34
35
|
class BeAPoint
|
35
36
|
include RSpec::Matchers
|
36
37
|
|
37
|
-
def initialize(expect=nil)
|
38
|
+
def initialize(expect = nil)
|
38
39
|
@expect = expect
|
39
40
|
end
|
40
41
|
|
@@ -42,7 +43,7 @@ module GeorubyMatchers
|
|
42
43
|
if @expect
|
43
44
|
[:x, :y, :z, :m].each_with_index do |c, i|
|
44
45
|
next unless val = @expect[i]
|
45
|
-
if val.
|
46
|
+
if val.is_a? Numeric
|
46
47
|
expect(actual.send(c)).to be_within(0.1).of(val)
|
47
48
|
else
|
48
49
|
expect(actual.send(c)).to eql(val)
|
@@ -52,8 +53,13 @@ module GeorubyMatchers
|
|
52
53
|
expect(actual).to be_instance_of(GeoRuby::SimpleFeatures::Point)
|
53
54
|
end
|
54
55
|
|
55
|
-
def failure_message
|
56
|
-
|
56
|
+
def failure_message
|
57
|
+
"expected #{@expect} but received #{@actual.inspect}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def failure_message_when_negated
|
61
|
+
"expected something else then '#{@expect}' but got '#{@actual}'"
|
62
|
+
end
|
57
63
|
end
|
58
64
|
|
59
65
|
def be_a_point(*args)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: georuby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guilhem Vellut
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-
|
14
|
+
date: 2014-12-06 00:00:00.000000000 Z
|
15
15
|
dependencies: []
|
16
16
|
description: GeoRuby provides geometric data types from the OGC 'Simple Features'
|
17
17
|
specification.
|
@@ -23,10 +23,12 @@ files:
|
|
23
23
|
- README.md
|
24
24
|
- Rakefile
|
25
25
|
- lib/geo_ruby.rb
|
26
|
+
- lib/geo_ruby/ewk.rb
|
27
|
+
- lib/geo_ruby/ewk/ewkb_parser.rb
|
28
|
+
- lib/geo_ruby/ewk/ewkt_parser.rb
|
26
29
|
- lib/geo_ruby/geojson.rb
|
27
30
|
- lib/geo_ruby/georss.rb
|
28
31
|
- lib/geo_ruby/gpx.rb
|
29
|
-
- lib/geo_ruby/gpx4r/gpx.rb
|
30
32
|
- lib/geo_ruby/kml.rb
|
31
33
|
- lib/geo_ruby/shp.rb
|
32
34
|
- lib/geo_ruby/shp4r/dbf.rb
|
@@ -34,8 +36,6 @@ files:
|
|
34
36
|
- lib/geo_ruby/simple_features.rb
|
35
37
|
- lib/geo_ruby/simple_features/circle.rb
|
36
38
|
- lib/geo_ruby/simple_features/envelope.rb
|
37
|
-
- lib/geo_ruby/simple_features/ewkb_parser.rb
|
38
|
-
- lib/geo_ruby/simple_features/ewkt_parser.rb
|
39
39
|
- lib/geo_ruby/simple_features/geometry.rb
|
40
40
|
- lib/geo_ruby/simple_features/geometry_collection.rb
|
41
41
|
- lib/geo_ruby/simple_features/geometry_factory.rb
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- lib/geo_ruby/simple_features/polygon.rb
|
50
50
|
- lib/geo_ruby/version.rb
|
51
51
|
- lib/georuby.rb
|
52
|
+
- spec/data/geojson/feature.json
|
52
53
|
- spec/data/geojson/feature_collection.json
|
53
54
|
- spec/data/georss/atom.xml
|
54
55
|
- spec/data/georss/gml.xml
|
@@ -72,15 +73,15 @@ files:
|
|
72
73
|
- spec/data/polyline.dbf
|
73
74
|
- spec/data/polyline.shp
|
74
75
|
- spec/data/polyline.shx
|
76
|
+
- spec/geo_ruby/ewk/ewkb_parser_spec.rb
|
77
|
+
- spec/geo_ruby/ewk/ewkt_parser_spec.rb
|
75
78
|
- spec/geo_ruby/geojson_spec.rb
|
76
79
|
- spec/geo_ruby/georss_spec.rb
|
77
|
-
- spec/geo_ruby/
|
80
|
+
- spec/geo_ruby/gpx_spec.rb
|
78
81
|
- spec/geo_ruby/kml_spec.rb
|
79
82
|
- spec/geo_ruby/shp4r/shp_spec.rb
|
80
83
|
- spec/geo_ruby/simple_features/circle_spec.rb
|
81
84
|
- spec/geo_ruby/simple_features/envelope_spec.rb
|
82
|
-
- spec/geo_ruby/simple_features/ewkb_parser_spec.rb
|
83
|
-
- spec/geo_ruby/simple_features/ewkt_parser_spec.rb
|
84
85
|
- spec/geo_ruby/simple_features/geometry_collection_spec.rb
|
85
86
|
- spec/geo_ruby/simple_features/geometry_factory_spec.rb
|
86
87
|
- spec/geo_ruby/simple_features/geometry_spec.rb
|
@@ -113,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
114
|
version: '0'
|
114
115
|
requirements: []
|
115
116
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.
|
117
|
+
rubygems_version: 2.4.3
|
117
118
|
signing_key:
|
118
119
|
specification_version: 4
|
119
120
|
summary: Ruby data holder for OGC Simple Features
|
data/lib/geo_ruby/gpx4r/gpx.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "nokogiri"
|
3
|
-
|
4
|
-
module GeoRuby
|
5
|
-
module Gpx4r
|
6
|
-
|
7
|
-
#An interface to GPX files
|
8
|
-
class GpxFile
|
9
|
-
attr_reader :record_count, :file_root #:xmin, :ymin, :xmax, :ymax, :zmin, :zmax, :mmin, :mmax, :file_length
|
10
|
-
|
11
|
-
include Enumerable
|
12
|
-
|
13
|
-
# Opens a GPX file. Both "abc.shp" and "abc" are accepted.
|
14
|
-
def initialize(file, *opts) #with_z = true, with_m = true)
|
15
|
-
@file_root = file.gsub(/\.gpx$/i,"")
|
16
|
-
raise MalformedGpxException.new("Missing GPX File") unless
|
17
|
-
File.exists? @file_root + ".gpx"
|
18
|
-
@points, @envelope = [], nil
|
19
|
-
@gpx = File.open(@file_root + ".gpx", "rb")
|
20
|
-
opt = opts.inject({}) { |o, h| h.merge(o) }
|
21
|
-
parse_file(opt[:with_z], opt[:with_m])
|
22
|
-
end
|
23
|
-
|
24
|
-
#force the reopening of the files compsing the shp. Close before calling this.
|
25
|
-
def reload!
|
26
|
-
initialize(@file_root)
|
27
|
-
end
|
28
|
-
|
29
|
-
#opens a GPX "file". If a block is given, the GpxFile object is yielded to it and is closed upon return. Else a call to <tt>open</tt> is equivalent to <tt>GpxFile.new(...)</tt>.
|
30
|
-
def self.open(file, *opts)
|
31
|
-
gpxfile = GpxFile.new(file, *opts)
|
32
|
-
if block_given?
|
33
|
-
yield gpxfile
|
34
|
-
# gpxfile.close
|
35
|
-
else
|
36
|
-
gpxfile
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
#Closes a gpxfile
|
41
|
-
def close
|
42
|
-
@gpx.close
|
43
|
-
end
|
44
|
-
|
45
|
-
#Tests if the file has no record
|
46
|
-
def empty?
|
47
|
-
record_count == 0
|
48
|
-
end
|
49
|
-
|
50
|
-
#Goes through each record
|
51
|
-
def each
|
52
|
-
(0...record_count).each do |i|
|
53
|
-
yield get_record(i)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
alias :each_record :each
|
57
|
-
|
58
|
-
#Returns record +i+
|
59
|
-
def [](i)
|
60
|
-
get_record(i)
|
61
|
-
end
|
62
|
-
|
63
|
-
#Returns all the records
|
64
|
-
def records
|
65
|
-
@points
|
66
|
-
end
|
67
|
-
|
68
|
-
# Return the GPX file as LineString
|
69
|
-
def as_line_string
|
70
|
-
GeoRuby::SimpleFeatures::LineString.from_points(@points)
|
71
|
-
end
|
72
|
-
alias :as_polyline :as_line_string
|
73
|
-
|
74
|
-
# Return the GPX file as a Polygon
|
75
|
-
# If the GPX isn't closed, a line from the first
|
76
|
-
# to the last point will be created to close it.
|
77
|
-
def as_polygon
|
78
|
-
GeoRuby::SimpleFeatures::Polygon.from_points([@points[0] == @points[-1] ? @points : @points.push(@points[0].clone)])
|
79
|
-
end
|
80
|
-
|
81
|
-
# Return GPX Envelope
|
82
|
-
def envelope
|
83
|
-
@envelope ||= as_polygon.envelope
|
84
|
-
end
|
85
|
-
|
86
|
-
private
|
87
|
-
|
88
|
-
def get_record(i)
|
89
|
-
@points[i]
|
90
|
-
end
|
91
|
-
|
92
|
-
# wpt => waypoint => TODO?
|
93
|
-
# rte(pt) => route
|
94
|
-
# trk(pt) => track /
|
95
|
-
def parse_file(with_z, with_m)
|
96
|
-
data = @gpx.read
|
97
|
-
@file_mode = data =~ /trkpt/ ? "//trkpt" : (data =~ /wpt/ ? "//wpt" : "//rtept")
|
98
|
-
Nokogiri.HTML(data).search(@file_mode).each do |tp|
|
99
|
-
z = z.inner_text.to_f if with_z && z = tp.at("ele")
|
100
|
-
m = m.inner_text if with_m && m = tp.at("time")
|
101
|
-
@points << GeoRuby::SimpleFeatures::Point.from_coordinates([tp["lon"].to_f, tp["lat"].to_f, z, m],4326,with_z, with_m)
|
102
|
-
end
|
103
|
-
close
|
104
|
-
@record_count = @points.length
|
105
|
-
self.envelope
|
106
|
-
rescue => e
|
107
|
-
raise MalformedGpxException.new("Bad GPX. Error: #{e}")
|
108
|
-
# trackpoint.at("gpxdata:hr").nil? # heartrate
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
class MalformedGpxException < StandardError
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|