georuby 2.2.1 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -8
- data/lib/geo_ruby/geojson.rb +8 -6
- data/lib/geo_ruby/simple_features/geometry.rb +11 -0
- data/lib/geo_ruby/simple_features/geometry_collection.rb +1 -9
- data/lib/geo_ruby/simple_features/line_string.rb +8 -13
- data/lib/geo_ruby/simple_features/multi_line_string.rb +2 -10
- data/lib/geo_ruby/simple_features/multi_point.rb +1 -9
- data/lib/geo_ruby/simple_features/multi_polygon.rb +0 -7
- data/lib/geo_ruby/simple_features/point.rb +11 -14
- data/lib/geo_ruby/simple_features/polygon.rb +1 -9
- data/lib/geo_ruby/version.rb +1 -1
- data/spec/geo_ruby/geojson_spec.rb +25 -25
- data/spec/geo_ruby/georss_spec.rb +63 -63
- data/spec/geo_ruby/gpx4r/gpx_spec.rb +34 -34
- data/spec/geo_ruby/kml_spec.rb +27 -27
- data/spec/geo_ruby/shp4r/shp_spec.rb +46 -46
- data/spec/geo_ruby/simple_features/circle_spec.rb +1 -1
- data/spec/geo_ruby/simple_features/envelope_spec.rb +15 -15
- data/spec/geo_ruby/simple_features/ewkb_parser_spec.rb +56 -56
- data/spec/geo_ruby/simple_features/ewkt_parser_spec.rb +68 -68
- data/spec/geo_ruby/simple_features/geometry_collection_spec.rb +18 -18
- data/spec/geo_ruby/simple_features/geometry_spec.rb +10 -10
- data/spec/geo_ruby/simple_features/line_string_spec.rb +80 -71
- data/spec/geo_ruby/simple_features/linear_ring_spec.rb +3 -3
- data/spec/geo_ruby/simple_features/multi_line_string_spec.rb +15 -15
- data/spec/geo_ruby/simple_features/multi_point_spec.rb +10 -10
- data/spec/geo_ruby/simple_features/multi_polygon_spec.rb +13 -13
- data/spec/geo_ruby/simple_features/point_spec.rb +139 -131
- data/spec/geo_ruby/simple_features/polygon_spec.rb +36 -36
- data/spec/geo_ruby_spec.rb +3 -3
- data/spec/spec_helper.rb +4 -4
- metadata +52 -52
@@ -6,24 +6,24 @@ describe GeoRuby::SimpleFeatures::GeometryCollection do
|
|
6
6
|
geometry_collection = GeoRuby::SimpleFeatures::GeometryCollection::new(256)
|
7
7
|
geometry_collection << GeoRuby::SimpleFeatures::Point.from_x_y(4.67,45.4,256)
|
8
8
|
|
9
|
-
geometry_collection.length.
|
10
|
-
geometry_collection[0].
|
9
|
+
expect(geometry_collection.length).to eql(1)
|
10
|
+
expect(geometry_collection[0]).to eq(GeoRuby::SimpleFeatures::Point.from_x_y(4.67,45.4,256))
|
11
11
|
|
12
12
|
geometry_collection[0]=GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)
|
13
13
|
geometry_collection << 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)
|
14
|
-
geometry_collection.length.
|
15
|
-
geometry_collection[0].
|
14
|
+
expect(geometry_collection.length).to eql(2)
|
15
|
+
expect(geometry_collection[0]).to eq(GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256))
|
16
16
|
|
17
17
|
geometry_collection = GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y(4.67,45.4,256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256)
|
18
|
-
geometry_collection.class.
|
19
|
-
geometry_collection.srid.
|
20
|
-
geometry_collection.length.
|
21
|
-
geometry_collection[1].
|
18
|
+
expect(geometry_collection.class).to eql(GeoRuby::SimpleFeatures::GeometryCollection)
|
19
|
+
expect(geometry_collection.srid).to eql(256)
|
20
|
+
expect(geometry_collection.length).to eql(2)
|
21
|
+
expect(geometry_collection[1]).to eq(GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256))
|
22
22
|
|
23
23
|
bbox = geometry_collection.bounding_box
|
24
|
-
bbox.length.
|
25
|
-
bbox[0].
|
26
|
-
bbox[1].
|
24
|
+
expect(bbox.length).to eql(2)
|
25
|
+
expect(bbox[0]).to eq(GeoRuby::SimpleFeatures::Point.from_x_y(4.67,12.45))
|
26
|
+
expect(bbox[1]).to eq(GeoRuby::SimpleFeatures::Point.from_x_y(67.55,54))
|
27
27
|
end
|
28
28
|
|
29
29
|
it "test_geometry_collection_equal" do
|
@@ -31,25 +31,25 @@ describe GeoRuby::SimpleFeatures::GeometryCollection do
|
|
31
31
|
geometry_collection2 = GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y(4.67,45.4,256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256),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)],256,true)
|
32
32
|
line_string=GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)
|
33
33
|
|
34
|
-
geometry_collection1.
|
35
|
-
geometry_collection2.
|
36
|
-
line_string.
|
34
|
+
expect(geometry_collection1).to eq(GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y(4.67,45.4,256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256))
|
35
|
+
expect(geometry_collection2).not_to eq(geometry_collection1)
|
36
|
+
expect(line_string).not_to eq(geometry_collection1)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "test_geometry_collection_binary" do
|
40
40
|
geometry_collection = GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y(4.67,45.4,256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256)
|
41
|
-
geometry_collection.as_hex_ewkb.
|
41
|
+
expect(geometry_collection.as_hex_ewkb).to eql("010700002000010000020000000101000000AE47E17A14AE12403333333333B34640010200000002000000CDCCCCCCCCCC16406666666666E628403333333333E350400000000000004B40")
|
42
42
|
|
43
43
|
geometry_collection = GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y_z_m(4.67,45.4,45.67,2.3,256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45,4.56,98.3],[67.55,54,12.2,3.4]],256,true, true)],256,true, true)
|
44
|
-
geometry_collection.as_hex_ewkb.
|
44
|
+
expect(geometry_collection.as_hex_ewkb).to eql("01070000E0000100000200000001010000C0AE47E17A14AE12403333333333B34640F6285C8FC2D54640666666666666024001020000C002000000CDCCCCCCCCCC16406666666666E628403D0AD7A3703D124033333333339358403333333333E350400000000000004B4066666666666628403333333333330B40")
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should test_geometry_collection_text" do
|
48
48
|
geometry_collection = GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y(4.67,45.4,256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256)
|
49
|
-
geometry_collection.as_ewkt.
|
49
|
+
expect(geometry_collection.as_ewkt).to eql("SRID=256;GEOMETRYCOLLECTION(POINT(4.67 45.4),LINESTRING(5.7 12.45,67.55 54))")
|
50
50
|
|
51
51
|
geometry_collection = GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y_m(4.67,45.4,45.6,256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45,5.6],[67.55,54,6.7]],256,false,true)],256,false,true)
|
52
|
-
geometry_collection.as_ewkt.
|
52
|
+
expect(geometry_collection.as_ewkt).to eql("SRID=256;GEOMETRYCOLLECTIONM(POINTM(4.67 45.4 45.6),LINESTRINGM(5.7 12.45 5.6,67.55 54 6.7))")
|
53
53
|
end
|
54
54
|
|
55
55
|
end
|
@@ -9,29 +9,29 @@ describe GeoRuby::SimpleFeatures::Geometry do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should have a default srid" do
|
12
|
-
subject.srid.
|
12
|
+
expect(subject.srid).to eql(4326) #Geometry.default_srid)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should change srid" do
|
16
16
|
geo = GeoRuby::SimpleFeatures::Geometry.new(225)
|
17
|
-
geo.srid.
|
17
|
+
expect(geo.srid).to eql(225)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should instantiate from hex ewkb" do
|
21
21
|
point = GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb("01010000207B000000CDCCCCCCCCCC28406666666666A64640")
|
22
|
-
point.class.
|
23
|
-
point.x.
|
22
|
+
expect(point.class).to eq(GeoRuby::SimpleFeatures::Point)
|
23
|
+
expect(point.x).to be_within(0.1).of(12.4)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should output as_ewkb" do
|
27
|
-
subject.
|
28
|
-
subject.
|
29
|
-
subject.as_ewkb.
|
27
|
+
allow(subject).to receive(:binary_geometry_type).and_return(1)
|
28
|
+
allow(subject).to receive(:binary_representation).and_return(1)
|
29
|
+
expect(subject.as_ewkb).to eql("\001\001\000\000 \346\020\000\000\001")
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should output as_ewkb (utf8 issue)" do
|
33
|
-
subject.
|
34
|
-
subject.
|
35
|
-
subject.as_ewkb.
|
33
|
+
allow(subject).to receive(:binary_geometry_type).and_return(1)
|
34
|
+
allow(subject).to receive(:binary_representation).and_return(1)
|
35
|
+
expect(subject.as_ewkb).to eql("\x01\x01\x00\x00 \xE6\x10\x00\x00\x01")
|
36
36
|
end
|
37
37
|
end
|
@@ -6,8 +6,8 @@ module LineSpecHelper
|
|
6
6
|
Array.new(num) { |i| mock_point(i,i) }
|
7
7
|
end
|
8
8
|
|
9
|
-
def mock_point(x=1,y=2)
|
10
|
-
double(GeoRuby::SimpleFeatures::Point, :x => x, :y => y, :text_representation => "#{x} #{y}")
|
9
|
+
def mock_point(x=1, y=2)
|
10
|
+
double(GeoRuby::SimpleFeatures::Point, :x => x, :y => y, :text_representation => "#{x} #{y}", :to_coordinates => [x, y])
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -24,15 +24,15 @@ describe GeoRuby::SimpleFeatures::LineString do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should have binary_geometry_type 2" do
|
27
|
-
line.binary_geometry_type.
|
27
|
+
expect(line.binary_geometry_type).to eql(2)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should have text_geometry_type" do
|
31
|
-
line.text_geometry_type.
|
31
|
+
expect(line.text_geometry_type).to eql("LINESTRING")
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should have a points array" do
|
35
|
-
line.points.
|
35
|
+
expect(line.points).to be_instance_of(Array)
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
@@ -42,12 +42,12 @@ describe GeoRuby::SimpleFeatures::LineString do
|
|
42
42
|
let(:line) { GeoRuby::SimpleFeatures::LineString.from_points([GeoRuby::SimpleFeatures::Point.xy(1,1), GeoRuby::SimpleFeatures::Point.xy(2,2), GeoRuby::SimpleFeatures::Point.xy(3,3)]) }
|
43
43
|
|
44
44
|
it "should check orientation" do
|
45
|
-
line.
|
45
|
+
expect(line).not_to be_clockwise
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should check orientation" do
|
49
49
|
l = GeoRuby::SimpleFeatures::LineString.from_points([GeoRuby::SimpleFeatures::Point.from_x_y(20,20), GeoRuby::SimpleFeatures::Point.from_x_y(10,10), GeoRuby::SimpleFeatures::Point.from_x_y(-10,10)])
|
50
|
-
l.
|
50
|
+
expect(l).to be_clockwise
|
51
51
|
end
|
52
52
|
|
53
53
|
end
|
@@ -58,51 +58,51 @@ describe GeoRuby::SimpleFeatures::LineString do
|
|
58
58
|
line_string = GeoRuby::SimpleFeatures::LineString::new
|
59
59
|
line_string.concat([GeoRuby::SimpleFeatures::Point.from_x_y(12.4,45.3),GeoRuby::SimpleFeatures::Point.from_x_y(45.4,41.6)])
|
60
60
|
|
61
|
-
line_string.length.
|
62
|
-
line_string[0].
|
61
|
+
expect(line_string.length).to eql(2)
|
62
|
+
expect(line_string[0]).to eq(GeoRuby::SimpleFeatures::Point.from_x_y(12.4,45.3))
|
63
63
|
|
64
64
|
point=GeoRuby::SimpleFeatures::Point.from_x_y(123,45.8777)
|
65
65
|
line_string[0]=point
|
66
|
-
line_string[0].
|
66
|
+
expect(line_string[0]).to eq(point)
|
67
67
|
|
68
68
|
points=[GeoRuby::SimpleFeatures::Point.from_x_y(123,45.8777),GeoRuby::SimpleFeatures::Point.from_x_y(45.4,41.6)]
|
69
|
-
line_string.each_index {|i| line_string[i].
|
69
|
+
line_string.each_index {|i| expect(line_string[i]).to eq(points[i]) }
|
70
70
|
|
71
71
|
point=GeoRuby::SimpleFeatures::Point.from_x_y(22.4,13.56)
|
72
72
|
line_string << point
|
73
|
-
line_string.length.
|
74
|
-
line_string[2].
|
73
|
+
expect(line_string.length).to eql(3)
|
74
|
+
expect(line_string[2]).to eql(point)
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should create" do
|
78
78
|
line_string = GeoRuby::SimpleFeatures::LineString.from_points([GeoRuby::SimpleFeatures::Point.from_x_y(12.4,-45.3),GeoRuby::SimpleFeatures::Point.from_x_y(45.4,41.6)],123)
|
79
|
-
line_string.class.
|
80
|
-
line_string.length.
|
81
|
-
line_string[0].
|
82
|
-
line_string[1].
|
79
|
+
expect(line_string.class).to eql(GeoRuby::SimpleFeatures::LineString)
|
80
|
+
expect(line_string.length).to eql(2)
|
81
|
+
expect(line_string[0]).to eq(GeoRuby::SimpleFeatures::Point.from_x_y(12.4,-45.3))
|
82
|
+
expect(line_string[1]).to eq(GeoRuby::SimpleFeatures::Point.from_x_y(45.4,41.6))
|
83
83
|
|
84
84
|
line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698]],123)
|
85
|
-
line_string.class.
|
86
|
-
line_string.length.
|
87
|
-
line_string[0].
|
88
|
-
line_string[1].
|
85
|
+
expect(line_string.class).to eql(GeoRuby::SimpleFeatures::LineString)
|
86
|
+
expect(line_string.length).to eql(3)
|
87
|
+
expect(line_string[0]).to eq(GeoRuby::SimpleFeatures::Point.from_x_y(12.4,-45.3))
|
88
|
+
expect(line_string[1]).to eq(GeoRuby::SimpleFeatures::Point.from_x_y(45.4,41.6))
|
89
89
|
|
90
90
|
line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3,123],[45.4,41.6,333],[4.456,1.0698,987]],123,true)
|
91
|
-
line_string.class.
|
92
|
-
line_string.length.
|
93
|
-
line_string[0].
|
91
|
+
expect(line_string.class).to eql(GeoRuby::SimpleFeatures::LineString)
|
92
|
+
expect(line_string.length).to eql(3)
|
93
|
+
expect(line_string[0]).to eq(GeoRuby::SimpleFeatures::Point.from_x_y_z(12.4,-45.3,123,123))
|
94
94
|
|
95
95
|
line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3,123],[45.4,41.6,333],[4.456,1.0698,987]],123,true)
|
96
|
-
line_string.class.
|
97
|
-
line_string.length.
|
98
|
-
line_string[0].
|
96
|
+
expect(line_string.class).to eql(GeoRuby::SimpleFeatures::LineString)
|
97
|
+
expect(line_string.length).to eql(3)
|
98
|
+
expect(line_string[0]).to eq(GeoRuby::SimpleFeatures::Point.from_x_y_z(12.4,-45.3,123,123))
|
99
99
|
end
|
100
100
|
|
101
101
|
it "should bbox it" do
|
102
102
|
bbox = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3,123],[45.4,41.6,333],[4.456,1.0698,987]],123,true).bounding_box
|
103
|
-
bbox.length.
|
104
|
-
bbox[0].
|
105
|
-
bbox[1].
|
103
|
+
expect(bbox.length).to eql(2)
|
104
|
+
expect(bbox[0]).to eq(GeoRuby::SimpleFeatures::Point.from_x_y_z(4.456,-45.3,123))
|
105
|
+
expect(bbox[1]).to eq(GeoRuby::SimpleFeatures::Point.from_x_y_z(45.4,41.6,987))
|
106
106
|
end
|
107
107
|
|
108
108
|
it "should test_line_string_equal" do
|
@@ -110,56 +110,56 @@ describe GeoRuby::SimpleFeatures::LineString do
|
|
110
110
|
line_string2 = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],123)
|
111
111
|
point = GeoRuby::SimpleFeatures::Point.from_x_y(12.4,-45.3,123)
|
112
112
|
|
113
|
-
line_string1.
|
114
|
-
line_string1.
|
115
|
-
line_string1.
|
113
|
+
expect(line_string1).to eq(GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698]],123))
|
114
|
+
expect(line_string1).not_to eq(line_string2)
|
115
|
+
expect(line_string1).not_to eq(point)
|
116
116
|
end
|
117
117
|
|
118
118
|
it "should test_line_string_binary" do
|
119
119
|
line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],256)
|
120
|
-
line_string.as_hex_ewkb.
|
120
|
+
expect(line_string.as_hex_ewkb).to eql("01020000200001000002000000CDCCCCCCCCCC28406666666666A646C03333333333B34640CDCCCCCCCCCC4440")
|
121
121
|
|
122
122
|
line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,true)
|
123
|
-
line_string.as_hex_ewkb.
|
123
|
+
expect(line_string.as_hex_ewkb).to eql("01020000A00001000002000000CDCCCCCCCCCC28406666666666A646C06666666666A641403333333333B34640CDCCCCCCCCCC44409A99999999992840")
|
124
124
|
|
125
125
|
line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3,35.3,45.1],[45.4,41.6,12.3,40.23]],256,true,true)
|
126
|
-
line_string.as_hex_ewkb.
|
126
|
+
expect(line_string.as_hex_ewkb).to eql("01020000E00001000002000000CDCCCCCCCCCC28406666666666A646C06666666666A64140CDCCCCCCCC8C46403333333333B34640CDCCCCCCCCCC44409A999999999928403D0AD7A3701D4440")
|
127
127
|
end
|
128
128
|
|
129
129
|
it "test_line_string_text" do
|
130
130
|
line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],256)
|
131
|
-
line_string.as_ewkt.
|
131
|
+
expect(line_string.as_ewkt).to eql("SRID=256;LINESTRING(12.4 -45.3,45.4 41.6)")
|
132
132
|
|
133
133
|
line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,true)
|
134
|
-
line_string.as_ewkt.
|
134
|
+
expect(line_string.as_ewkt).to eql("SRID=256;LINESTRING(12.4 -45.3 35.3,45.4 41.6 12.3)")
|
135
135
|
|
136
136
|
line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,false,true)
|
137
|
-
line_string.as_ewkt.
|
137
|
+
expect(line_string.as_ewkt).to eql("SRID=256;LINESTRINGM(12.4 -45.3 35.3,45.4 41.6 12.3)")
|
138
138
|
|
139
139
|
line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3,35.3,25.2],[45.4,41.6,12.3,13.75]],256,true,true)
|
140
|
-
line_string.as_ewkt.
|
140
|
+
expect(line_string.as_ewkt).to eql("SRID=256;LINESTRING(12.4 -45.3 35.3 25.2,45.4 41.6 12.3 13.75)")
|
141
141
|
end
|
142
142
|
|
143
143
|
it "should test_linear_ring_creation" do
|
144
144
|
#testing just the constructor helpers since the rest is the same as for line_string
|
145
145
|
linear_ring = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],345)
|
146
|
-
linear_ring.class.
|
147
|
-
linear_ring.length.
|
148
|
-
linear_ring.
|
149
|
-
linear_ring[1].
|
146
|
+
expect(linear_ring.class).to eql(GeoRuby::SimpleFeatures::LinearRing)
|
147
|
+
expect(linear_ring.length).to eql(4)
|
148
|
+
expect(linear_ring).to be_closed
|
149
|
+
expect(linear_ring[1]).to eq(GeoRuby::SimpleFeatures::Point.from_x_y(45.4,41.6,345))
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
153
|
describe "> Coordinates" do
|
154
154
|
|
155
155
|
before(:each) do
|
156
|
-
GeoRuby::SimpleFeatures::Point.
|
156
|
+
expect(GeoRuby::SimpleFeatures::Point).to receive(:from_coordinates).
|
157
157
|
exactly(4).with(anything, 4326, false, false).and_return(mock_point)
|
158
158
|
@line = GeoRuby::SimpleFeatures::LineString.from_coordinates([1.2,2.5,2.2,4.5])
|
159
159
|
end
|
160
160
|
|
161
161
|
it "should instantiate from coordinates" do
|
162
|
-
@line.points.length.
|
162
|
+
expect(@line.points.length).to eql(4)
|
163
163
|
end
|
164
164
|
|
165
165
|
end
|
@@ -170,35 +170,44 @@ describe GeoRuby::SimpleFeatures::LineString do
|
|
170
170
|
|
171
171
|
it "should be closed if the last point equals the first" do
|
172
172
|
line.push(line.first)
|
173
|
-
line.
|
174
|
-
line.length.
|
173
|
+
expect(line).to be_closed
|
174
|
+
expect(line.length).to eql(8)
|
175
175
|
end
|
176
176
|
|
177
177
|
it "should print the text representation" do
|
178
|
-
line.text_representation.
|
178
|
+
expect(line.text_representation).to eql("0 0,1 1,2 2,3 3,4 4,5 5,6 6")
|
179
179
|
end
|
180
180
|
|
181
181
|
it "should print the georss_simple_representation" do
|
182
|
-
line.georss_simple_representation({:geom_attr => nil}).
|
183
|
-
|
182
|
+
expect(line.georss_simple_representation({:geom_attr => nil})).
|
183
|
+
to eql("<georss:line>0 0 1 1 2 2 3 3 4 4 5 5 6 6</georss:line>\n")
|
184
184
|
end
|
185
185
|
|
186
186
|
it "should map the georss_poslist" do
|
187
|
-
line.georss_poslist.
|
187
|
+
expect(line.georss_poslist).to eql("0 0 1 1 2 2 3 3 4 4 5 5 6 6")
|
188
188
|
end
|
189
189
|
|
190
190
|
it "should print the kml_representation" do
|
191
|
-
line.kml_representation.
|
192
|
-
eql("<LineString>\n<coordinates>0,0 1,1 2,2 3,3 4,4 5,5 6,6</coordinates>\n</LineString>\n")
|
191
|
+
expect(line.kml_representation).
|
192
|
+
to eql("<LineString>\n<coordinates>0,0 1,1 2,2 3,3 4,4 5,5 6,6</coordinates>\n</LineString>\n")
|
193
193
|
end
|
194
194
|
|
195
195
|
it "should print the kml_poslist without reverse or z" do
|
196
|
-
line.kml_poslist({}).
|
196
|
+
expect(line.kml_poslist({})).to eql("0,0 1,1 2,2 3,3 4,4 5,5 6,6")
|
197
197
|
end
|
198
198
|
|
199
199
|
it "should print the kml_poslist reverse" do
|
200
|
-
line.kml_poslist({:reverse => true}).
|
200
|
+
expect(line.kml_poslist({:reverse => true})).to eql("6,6 5,5 4,4 3,3 2,2 1,1 0,0")
|
201
201
|
end
|
202
|
+
|
203
|
+
it "should print out nicely as json/geojson" do
|
204
|
+
expect(line.as_json).to eql({:type=>"LineString", :coordinates=>[[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]]})
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should print out nicely to json/geojson" do
|
208
|
+
expect(line.to_json).to eql("{\"type\":\"LineString\",\"coordinates\":[[0,0],[1,1],[2,2],[3,3],[4,4],[5,5],[6,6]]}")
|
209
|
+
end
|
210
|
+
|
202
211
|
end
|
203
212
|
|
204
213
|
describe "> Distances..." do
|
@@ -210,15 +219,15 @@ describe GeoRuby::SimpleFeatures::LineString do
|
|
210
219
|
end
|
211
220
|
|
212
221
|
it "should print the length with haversine" do
|
213
|
-
@p1.
|
214
|
-
@p2.
|
215
|
-
@line.spherical_distance.
|
222
|
+
expect(@p1).to receive(:spherical_distance).with(@p2).and_return(10)
|
223
|
+
expect(@p2).to receive(:spherical_distance).with(@p3).and_return(10)
|
224
|
+
expect(@line.spherical_distance).to eql(20)
|
216
225
|
end
|
217
226
|
|
218
227
|
it "should print lenght as euclidian" do
|
219
|
-
@p1.
|
220
|
-
@p2.
|
221
|
-
@line.euclidian_distance.
|
228
|
+
expect(@p1).to receive(:euclidian_distance).with(@p2).and_return(10)
|
229
|
+
expect(@p2).to receive(:euclidian_distance).with(@p3).and_return(10)
|
230
|
+
expect(@line.euclidian_distance).to eql(20)
|
222
231
|
end
|
223
232
|
end
|
224
233
|
|
@@ -228,31 +237,31 @@ describe GeoRuby::SimpleFeatures::LineString do
|
|
228
237
|
|
229
238
|
it "should simplify a simple linestring" do
|
230
239
|
line = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12,15],[14,17],[17, 20]], 4326)
|
231
|
-
line.simplify.
|
240
|
+
expect(line.simplify.points.size).to eq(2)
|
232
241
|
end
|
233
242
|
|
234
243
|
it "should simplify a harder linestring" do
|
235
|
-
line.simplify(6).
|
236
|
-
line.simplify(9).
|
237
|
-
line.simplify(10).
|
244
|
+
expect(line.simplify(6).points.size).to eq(6)
|
245
|
+
expect(line.simplify(9).size).to eq(4)
|
246
|
+
expect(line.simplify(10).size).to eq(3)
|
238
247
|
end
|
239
248
|
|
240
249
|
it "should barely touch it" do
|
241
|
-
line.simplify(1).
|
250
|
+
expect(line.simplify(1).points.size).to eq(7)
|
242
251
|
end
|
243
252
|
|
244
253
|
it "should simplify to five points" do
|
245
|
-
line.simplify(7).
|
254
|
+
expect(line.simplify(7).points.size).to eq(5)
|
246
255
|
end
|
247
256
|
|
248
257
|
it "should flatten it" do
|
249
|
-
line.simplify(11).
|
258
|
+
expect(line.simplify(11).points.size).to eq(2)
|
250
259
|
end
|
251
260
|
|
252
261
|
it "should be the first and last in a flatten" do
|
253
262
|
l = line.simplify(11)
|
254
|
-
l[0].
|
255
|
-
l[1].
|
263
|
+
expect(l[0]).to be_a_point(6, 0)
|
264
|
+
expect(l[1]).to be_a_point(6, 15)
|
256
265
|
end
|
257
266
|
|
258
267
|
end
|
@@ -4,7 +4,7 @@ describe GeoRuby::SimpleFeatures::LinearRing do
|
|
4
4
|
|
5
5
|
it "should instantiate" do
|
6
6
|
lr = GeoRuby::SimpleFeatures::LinearRing.new(4326)
|
7
|
-
lr.
|
7
|
+
expect(lr).to be_instance_of(GeoRuby::SimpleFeatures::LinearRing)
|
8
8
|
end
|
9
9
|
|
10
10
|
describe "Instance" do
|
@@ -12,11 +12,11 @@ describe GeoRuby::SimpleFeatures::LinearRing do
|
|
12
12
|
let(:lr) { GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[10,10],[20,45],[45,10],[10, 10]],256) }
|
13
13
|
|
14
14
|
it "should test if contains a point" do
|
15
|
-
lr.contains_point?(GeoRuby::SimpleFeatures::Point.from_x_y(21,21)).
|
15
|
+
expect(lr.contains_point?(GeoRuby::SimpleFeatures::Point.from_x_y(21,21))).to be_truthy
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should test if not contains a point" do
|
19
|
-
lr.contains_point?(GeoRuby::SimpleFeatures::Point.from_x_y(21,51)).
|
19
|
+
expect(lr.contains_point?(GeoRuby::SimpleFeatures::Point.from_x_y(21,51))).to be_falsey
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
@@ -4,32 +4,32 @@ describe GeoRuby::SimpleFeatures::MultiLineString do
|
|
4
4
|
|
5
5
|
it "test_multi_line_string_creation" do
|
6
6
|
multi_line_string1 = GeoRuby::SimpleFeatures::MultiLineString.from_line_strings([GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256)
|
7
|
-
multi_line_string1.
|
8
|
-
multi_line_string1.length.
|
9
|
-
multi_line_string1[0].
|
7
|
+
expect(multi_line_string1).to be_instance_of(GeoRuby::SimpleFeatures::MultiLineString)
|
8
|
+
expect(multi_line_string1.length).to eql(2)
|
9
|
+
expect(multi_line_string1[0]).to eq(GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256))
|
10
10
|
|
11
11
|
multi_line_string2= GeoRuby::SimpleFeatures::MultiLineString.from_coordinates([[[1.5,45.2],[-54.12312,-0.012]],[[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]]],256);
|
12
|
-
multi_line_string1.
|
13
|
-
multi_line_string1.length.
|
14
|
-
multi_line_string2[0].
|
12
|
+
expect(multi_line_string1).to be_instance_of(GeoRuby::SimpleFeatures::MultiLineString)
|
13
|
+
expect(multi_line_string1.length).to eql(2)
|
14
|
+
expect(multi_line_string2[0]).to eq(GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256))
|
15
15
|
|
16
|
-
multi_line_string2.
|
16
|
+
expect(multi_line_string2).to eq(multi_line_string2)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "test_multi_line_string_binary" do
|
20
20
|
multi_line_string = GeoRuby::SimpleFeatures::MultiLineString.from_line_strings([GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256)
|
21
|
-
multi_line_string.as_hex_ewkb.
|
21
|
+
expect(multi_line_string.as_hex_ewkb).to eql("01050000200001000002000000010200000002000000000000000000F83F9A99999999994640E4BD6A65C20F4BC0FA7E6ABC749388BF010200000003000000000000000000F83F9A99999999994640E4BD6A65C20F4BC0FA7E6ABC749388BF39B4C876BE8F46403333333333D35E40")
|
22
22
|
|
23
23
|
multi_line_string = GeoRuby::SimpleFeatures::MultiLineString.from_line_strings([GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2,1.3,1.2],[-54.12312,-0.012,1.2,4.5]],256,true,true),GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2,5.1,-4.5],[-54.12312,-0.012,-6.8,3.4],[45.123,123.3,4.5,-5.3]],256,true,true)],256,true,true)
|
24
|
-
multi_line_string.as_hex_ewkb.
|
24
|
+
expect(multi_line_string.as_hex_ewkb).to eql("0105000020000100000200000001020000C002000000000000000000F83F9A99999999994640CDCCCCCCCCCCF43F333333333333F33FE4BD6A65C20F4BC0FA7E6ABC749388BF333333333333F33F000000000000124001020000C003000000000000000000F83F9A99999999994640666666666666144000000000000012C0E4BD6A65C20F4BC0FA7E6ABC749388BF3333333333331BC03333333333330B4039B4C876BE8F46403333333333D35E40000000000000124033333333333315C0")
|
25
25
|
end
|
26
26
|
|
27
27
|
it "test_multi_line_string_text" do
|
28
28
|
multi_line_string = GeoRuby::SimpleFeatures::MultiLineString.from_line_strings([GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256)
|
29
|
-
multi_line_string.as_ewkt.
|
29
|
+
expect(multi_line_string.as_ewkt).to eql("SRID=256;MULTILINESTRING((1.5 45.2,-54.12312 -0.012),(1.5 45.2,-54.12312 -0.012,45.123 123.3))")
|
30
30
|
|
31
31
|
multi_line_string = GeoRuby::SimpleFeatures::MultiLineString.from_line_strings([GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2,1.3,1.2],[-54.12312,-0.012,1.2,4.5]],256,true,true),GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2,5.1,-4.5],[-54.12312,-0.012,-6.8,3.4],[45.123,123.3,4.5,-5.3]],256,true,true)],256,true,true)
|
32
|
-
multi_line_string.as_ewkt.
|
32
|
+
expect(multi_line_string.as_ewkt).to eql("SRID=256;MULTILINESTRING((1.5 45.2 1.3 1.2,-54.12312 -0.012 1.2 4.5),(1.5 45.2 5.1 -4.5,-54.12312 -0.012 -6.8 3.4,45.123 123.3 4.5 -5.3))")
|
33
33
|
end
|
34
34
|
|
35
35
|
describe "Some More" do
|
@@ -38,17 +38,17 @@ describe GeoRuby::SimpleFeatures::MultiLineString do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should have a accessor to all points" do
|
41
|
-
@mls.points.
|
41
|
+
expect(@mls.points).to be_instance_of(Array)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should flatten the array" do
|
45
|
-
@mls.
|
45
|
+
expect(@mls.points.size).to eq(5)
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should simplify to linestring" do
|
49
49
|
ls = @mls.to_line_string
|
50
|
-
ls.
|
51
|
-
ls.
|
50
|
+
expect(ls).to be_instance_of(GeoRuby::SimpleFeatures::LineString)
|
51
|
+
expect(ls.points.size).to eq(5)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|