geekdaily-georuby 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- data/.github/ISSUE_TEMPLATE/code-of-conduct-issue.md +10 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.gitignore +7 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +24 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/CONTRIBUTING.md +19 -0
- data/Gemfile +4 -0
- data/Guardfile +16 -0
- data/History.txt +4 -0
- data/MIT-LICENSE +7 -0
- data/README.md +237 -0
- data/Rakefile +32 -0
- data/bench.rb +35 -0
- data/georuby.gemspec +38 -0
- data/lib/geo_ruby.rb +11 -0
- data/lib/geo_ruby/ewk.rb +2 -0
- data/lib/geo_ruby/ewk/ewkb_parser.rb +206 -0
- data/lib/geo_ruby/ewk/ewkt_parser.rb +321 -0
- data/lib/geo_ruby/geojson.rb +139 -0
- data/lib/geo_ruby/georss.rb +156 -0
- data/lib/geo_ruby/gpx.rb +113 -0
- data/lib/geo_ruby/kml.rb +96 -0
- data/lib/geo_ruby/shp.rb +2 -0
- data/lib/geo_ruby/shp4r/dbf.rb +60 -0
- data/lib/geo_ruby/shp4r/shp.rb +726 -0
- data/lib/geo_ruby/simple_features.rb +21 -0
- data/lib/geo_ruby/simple_features/circle.rb +59 -0
- data/lib/geo_ruby/simple_features/envelope.rb +174 -0
- data/lib/geo_ruby/simple_features/geometry.rb +252 -0
- data/lib/geo_ruby/simple_features/geometry_collection.rb +143 -0
- data/lib/geo_ruby/simple_features/geometry_factory.rb +84 -0
- data/lib/geo_ruby/simple_features/helper.rb +18 -0
- data/lib/geo_ruby/simple_features/line_string.rb +224 -0
- data/lib/geo_ruby/simple_features/linear_ring.rb +34 -0
- data/lib/geo_ruby/simple_features/multi_line_string.rb +56 -0
- data/lib/geo_ruby/simple_features/multi_point.rb +52 -0
- data/lib/geo_ruby/simple_features/multi_polygon.rb +55 -0
- data/lib/geo_ruby/simple_features/point.rb +463 -0
- data/lib/geo_ruby/simple_features/polygon.rb +172 -0
- data/lib/geo_ruby/version.rb +3 -0
- data/lib/georuby.rb +2 -0
- data/spec/data/geojson/feature.json +9 -0
- data/spec/data/geojson/feature_collection.json +33 -0
- data/spec/data/georss/atom.xml +21 -0
- data/spec/data/georss/gml.xml +40 -0
- data/spec/data/georss/w3c.xml +22 -0
- data/spec/data/gpx/fells_loop.gpx +1077 -0
- data/spec/data/gpx/long.gpx +1642 -0
- data/spec/data/gpx/long.kml +31590 -0
- data/spec/data/gpx/long.nmea +2220 -0
- data/spec/data/gpx/short.gpx +13634 -0
- data/spec/data/gpx/short.kml +130 -0
- data/spec/data/gpx/tracktreks.gpx +706 -0
- data/spec/data/multipoint.dbf +0 -0
- data/spec/data/multipoint.shp +0 -0
- data/spec/data/multipoint.shx +0 -0
- data/spec/data/point.dbf +0 -0
- data/spec/data/point.shp +0 -0
- data/spec/data/point.shx +0 -0
- data/spec/data/polygon.dbf +0 -0
- data/spec/data/polygon.shp +0 -0
- data/spec/data/polygon.shx +0 -0
- data/spec/data/polyline.dbf +0 -0
- data/spec/data/polyline.shp +0 -0
- data/spec/data/polyline.shx +0 -0
- data/spec/geo_ruby/ewk/ewkb_parser_spec.rb +157 -0
- data/spec/geo_ruby/ewk/ewkt_parser_spec.rb +178 -0
- data/spec/geo_ruby/geojson_spec.rb +164 -0
- data/spec/geo_ruby/georss_spec.rb +238 -0
- data/spec/geo_ruby/gpx_spec.rb +103 -0
- data/spec/geo_ruby/kml_spec.rb +102 -0
- data/spec/geo_ruby/shp4r/shp_spec.rb +246 -0
- data/spec/geo_ruby/simple_features/circle_spec.rb +14 -0
- data/spec/geo_ruby/simple_features/envelope_spec.rb +47 -0
- data/spec/geo_ruby/simple_features/geometry_collection_spec.rb +55 -0
- data/spec/geo_ruby/simple_features/geometry_factory_spec.rb +11 -0
- data/spec/geo_ruby/simple_features/geometry_spec.rb +37 -0
- data/spec/geo_ruby/simple_features/line_string_spec.rb +268 -0
- data/spec/geo_ruby/simple_features/linear_ring_spec.rb +24 -0
- data/spec/geo_ruby/simple_features/multi_line_string_spec.rb +54 -0
- data/spec/geo_ruby/simple_features/multi_point_spec.rb +35 -0
- data/spec/geo_ruby/simple_features/multi_polygon_spec.rb +50 -0
- data/spec/geo_ruby/simple_features/point_spec.rb +547 -0
- data/spec/geo_ruby/simple_features/polygon_spec.rb +121 -0
- data/spec/geo_ruby_spec.rb +22 -0
- data/spec/spec_helper.rb +73 -0
- metadata +322 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
3
|
+
|
4
|
+
describe GeoRuby::SimpleFeatures::Circle do
|
5
|
+
|
6
|
+
it 'should instantiate' do
|
7
|
+
expect(subject).to be_kind_of GeoRuby::SimpleFeatures::Geometry
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'Instance' do
|
11
|
+
let(:circle) { GeoRuby::SimpleFeatures::Circle.new(4326) }
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe GeoRuby::SimpleFeatures::Envelope do
|
4
|
+
before(:each) do
|
5
|
+
@srid = 4269
|
6
|
+
@env = GeoRuby::SimpleFeatures::Envelope.from_points([GeoRuby::SimpleFeatures::Point.from_x_y(10, 20, @srid), GeoRuby::SimpleFeatures::Point.from_x_y(20, 30, @srid)], @srid)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should initialize' do
|
10
|
+
expect(@env).to be_instance_of(GeoRuby::SimpleFeatures::Envelope)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'converted tu' do
|
14
|
+
linear_ring = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[12.4, -45.3], [45.4, 41.6], [4.456, 1.0698], [12.4, -45.3]], 256)
|
15
|
+
polygon = GeoRuby::SimpleFeatures::Polygon.from_linear_rings([linear_ring], 256)
|
16
|
+
e = polygon.envelope
|
17
|
+
|
18
|
+
expect(e.lower_corner.class).to eql(GeoRuby::SimpleFeatures::Point)
|
19
|
+
expect(e.upper_corner.class).to eql(GeoRuby::SimpleFeatures::Point)
|
20
|
+
|
21
|
+
expect(e.lower_corner.x).to eql(4.456)
|
22
|
+
expect(e.lower_corner.y).to eql(-45.3)
|
23
|
+
expect(e.upper_corner.x).to eql(45.4)
|
24
|
+
expect(e.upper_corner.y).to eql(41.6)
|
25
|
+
|
26
|
+
line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[13.6, -49.3], [45.4, 44.6], [14.2, 1.09], [13.6, -49.3]], 256)
|
27
|
+
e2 = line_string.envelope
|
28
|
+
|
29
|
+
e3 = e.extend(e2)
|
30
|
+
|
31
|
+
expect(e3.lower_corner.x).to eql(4.456)
|
32
|
+
expect(e3.lower_corner.y).to eql(-49.3)
|
33
|
+
expect(e3.upper_corner.x).to eql(45.4)
|
34
|
+
expect(e3.upper_corner.y).to eql(44.6)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should have a center' do
|
38
|
+
expect(@env.center.x).to eql(15)
|
39
|
+
expect(@env.center.y).to eql(25)
|
40
|
+
expect(@env.center.srid).to eql(@env.srid)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should print a kml_representation' do
|
44
|
+
expect(@env.as_kml).to eql("<LatLonAltBox>\n<north>30</north>\n<south>20</south>\n<east>20</east>\n<west>10</west>\n</LatLonAltBox>\n")
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe GeoRuby::SimpleFeatures::GeometryCollection do
|
4
|
+
|
5
|
+
it 'should test_geometry_collection_creation' do
|
6
|
+
geometry_collection = GeoRuby::SimpleFeatures::GeometryCollection.new(256)
|
7
|
+
geometry_collection << GeoRuby::SimpleFeatures::Point.from_x_y(4.67, 45.4, 256)
|
8
|
+
|
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
|
+
|
12
|
+
geometry_collection[0] = GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7, 12.45], [67.55, 54]], 256)
|
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
|
+
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
|
+
|
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
|
+
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
|
+
|
23
|
+
bbox = geometry_collection.bounding_box
|
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
|
+
end
|
28
|
+
|
29
|
+
it 'test_geometry_collection_equal' do
|
30
|
+
geometry_collection1 = 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)
|
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
|
+
line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7, 12.45], [67.55, 54]], 256)
|
33
|
+
|
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
|
+
end
|
38
|
+
|
39
|
+
it 'test_geometry_collection_binary' do
|
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
|
+
expect(geometry_collection.as_hex_ewkb).to eql('010700002000010000020000000101000000AE47E17A14AE12403333333333B34640010200000002000000CDCCCCCCCCCC16406666666666E628403333333333E350400000000000004B40')
|
42
|
+
|
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
|
+
expect(geometry_collection.as_hex_ewkb).to eql('01070000E0000100000200000001010000C0AE47E17A14AE12403333333333B34640F6285C8FC2D54640666666666666024001020000C002000000CDCCCCCCCCCC16406666666666E628403D0AD7A3703D124033333333339358403333333333E350400000000000004B4066666666666628403333333333330B40')
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should test_geometry_collection_text' do
|
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
|
+
expect(geometry_collection.as_ewkt).to eql('SRID=256;GEOMETRYCOLLECTION(POINT(4.67 45.4),LINESTRING(5.7 12.45,67.55 54))')
|
50
|
+
|
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
|
+
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
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe GeoRuby::SimpleFeatures::GeometryFactory do
|
4
|
+
# before(:each) do
|
5
|
+
# @po = GeoRuby::SimpleFeatures::MultiPolygon.new
|
6
|
+
# end
|
7
|
+
|
8
|
+
# it "should f" do
|
9
|
+
# violated
|
10
|
+
# end
|
11
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- coding: binary -*-
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
4
|
+
|
5
|
+
describe GeoRuby::SimpleFeatures::Geometry do
|
6
|
+
|
7
|
+
it 'should instantiate' do
|
8
|
+
violated unless subject
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should have a default srid' do
|
12
|
+
expect(subject.srid).to eql(4326) # Geometry.default_srid)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should change srid' do
|
16
|
+
geo = GeoRuby::SimpleFeatures::Geometry.new(225)
|
17
|
+
expect(geo.srid).to eql(225)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should instantiate from hex ewkb' do
|
21
|
+
point = GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb('01010000207B000000CDCCCCCCCCCC28406666666666A64640')
|
22
|
+
expect(point.class).to eq(GeoRuby::SimpleFeatures::Point)
|
23
|
+
expect(point.x).to be_within(0.1).of(12.4)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should output as_ewkb' do
|
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
|
+
end
|
31
|
+
|
32
|
+
it 'should output as_ewkb (utf8 issue)' do
|
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
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,268 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
module LineSpecHelper
|
4
|
+
def mock_points(num)
|
5
|
+
# @point = mock(GeoRuby::SimpleFeatures::Point, :x => 1.0, :y => 2.0)
|
6
|
+
Array.new(num) { |i| mock_point(i, i) }
|
7
|
+
end
|
8
|
+
|
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
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe GeoRuby::SimpleFeatures::LineString do
|
15
|
+
|
16
|
+
include LineSpecHelper
|
17
|
+
|
18
|
+
describe 'Instance Methods' do
|
19
|
+
|
20
|
+
let(:line) { GeoRuby::SimpleFeatures::LineString.from_points([double(GeoRuby::SimpleFeatures::Point)]) }
|
21
|
+
|
22
|
+
it 'should instantiate' do
|
23
|
+
violated unless line
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should have binary_geometry_type 2' do
|
27
|
+
expect(line.binary_geometry_type).to eql(2)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should have text_geometry_type' do
|
31
|
+
expect(line.text_geometry_type).to eql('LINESTRING')
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should have a points array' do
|
35
|
+
expect(line.points).to be_instance_of(Array)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'Valid GeoRuby::SimpleFeatures::LineString' do
|
41
|
+
|
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
|
+
|
44
|
+
it 'should check orientation' do
|
45
|
+
expect(line).not_to be_clockwise
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should check orientation' do
|
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
|
+
expect(l).to be_clockwise
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'tu converted' do
|
56
|
+
|
57
|
+
it 'should concat points' do
|
58
|
+
line_string = GeoRuby::SimpleFeatures::LineString.new
|
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
|
+
|
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
|
+
|
64
|
+
point = GeoRuby::SimpleFeatures::Point.from_x_y(123, 45.8777)
|
65
|
+
line_string[0] = point
|
66
|
+
expect(line_string[0]).to eq(point)
|
67
|
+
|
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| expect(line_string[i]).to eq(points[i]) }
|
70
|
+
|
71
|
+
point = GeoRuby::SimpleFeatures::Point.from_x_y(22.4, 13.56)
|
72
|
+
line_string << point
|
73
|
+
expect(line_string.length).to eql(3)
|
74
|
+
expect(line_string[2]).to eql(point)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should create' do
|
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
|
+
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
|
+
|
84
|
+
line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4, -45.3], [45.4, 41.6], [4.456, 1.0698]], 123)
|
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
|
+
|
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
|
+
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
|
+
|
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
|
+
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
|
+
end
|
100
|
+
|
101
|
+
it 'should bbox it' do
|
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
|
+
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
|
+
end
|
107
|
+
|
108
|
+
it 'should test_line_string_equal' do
|
109
|
+
line_string1 = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4, -45.3], [45.4, 41.6], [4.456, 1.0698]], 123)
|
110
|
+
line_string2 = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4, -45.3], [45.4, 41.6]], 123)
|
111
|
+
point = GeoRuby::SimpleFeatures::Point.from_x_y(12.4, -45.3, 123)
|
112
|
+
|
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
|
+
end
|
117
|
+
|
118
|
+
it 'should test_line_string_binary' do
|
119
|
+
line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4, -45.3], [45.4, 41.6]], 256)
|
120
|
+
expect(line_string.as_hex_ewkb).to eql('01020000200001000002000000CDCCCCCCCCCC28406666666666A646C03333333333B34640CDCCCCCCCCCC4440')
|
121
|
+
|
122
|
+
line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4, -45.3, 35.3], [45.4, 41.6, 12.3]], 256, true)
|
123
|
+
expect(line_string.as_hex_ewkb).to eql('01020000A00001000002000000CDCCCCCCCCCC28406666666666A646C06666666666A641403333333333B34640CDCCCCCCCCCC44409A99999999992840')
|
124
|
+
|
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
|
+
expect(line_string.as_hex_ewkb).to eql('01020000E00001000002000000CDCCCCCCCCCC28406666666666A646C06666666666A64140CDCCCCCCCC8C46403333333333B34640CDCCCCCCCCCC44409A999999999928403D0AD7A3701D4440')
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'test_line_string_text' do
|
130
|
+
line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4, -45.3], [45.4, 41.6]], 256)
|
131
|
+
expect(line_string.as_ewkt).to eql('SRID=256;LINESTRING(12.4 -45.3,45.4 41.6)')
|
132
|
+
|
133
|
+
line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4, -45.3, 35.3], [45.4, 41.6, 12.3]], 256, true)
|
134
|
+
expect(line_string.as_ewkt).to eql('SRID=256;LINESTRING(12.4 -45.3 35.3,45.4 41.6 12.3)')
|
135
|
+
|
136
|
+
line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4, -45.3, 35.3], [45.4, 41.6, 12.3]], 256, false, true)
|
137
|
+
expect(line_string.as_ewkt).to eql('SRID=256;LINESTRINGM(12.4 -45.3 35.3,45.4 41.6 12.3)')
|
138
|
+
|
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
|
+
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
|
+
end
|
142
|
+
|
143
|
+
it 'should test_linear_ring_creation' do
|
144
|
+
# testing just the constructor helpers since the rest is the same as for line_string
|
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
|
+
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
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe '> Coordinates' do
|
154
|
+
|
155
|
+
before(:each) do
|
156
|
+
expect(GeoRuby::SimpleFeatures::Point).to receive(:from_coordinates)
|
157
|
+
.exactly(4).with(anything, 4326, false, false).and_return(mock_point)
|
158
|
+
@line = GeoRuby::SimpleFeatures::LineString.from_coordinates([1.2, 2.5, 2.2, 4.5])
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'should instantiate from coordinates' do
|
162
|
+
expect(@line.points.length).to eql(4)
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
describe '> Instantiated' do
|
168
|
+
|
169
|
+
let (:line) { GeoRuby::SimpleFeatures::LineString.from_points(mock_points(7)) }
|
170
|
+
|
171
|
+
it 'should be closed if the last point equals the first' do
|
172
|
+
line.push(line.first)
|
173
|
+
expect(line).to be_closed
|
174
|
+
expect(line.length).to eql(8)
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'should print the text representation' do
|
178
|
+
expect(line.text_representation).to eql('0 0,1 1,2 2,3 3,4 4,5 5,6 6')
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'should print the georss_simple_representation' do
|
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
|
+
end
|
185
|
+
|
186
|
+
it 'should map the georss_poslist' do
|
187
|
+
expect(line.georss_poslist).to eql('0 0 1 1 2 2 3 3 4 4 5 5 6 6')
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'should print the kml_representation' do
|
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
|
+
end
|
194
|
+
|
195
|
+
it 'should print the kml_poslist without reverse or z' do
|
196
|
+
expect(line.kml_poslist({})).to eql('0,0 1,1 2,2 3,3 4,4 5,5 6,6')
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'should print the kml_poslist reverse' do
|
200
|
+
expect(line.kml_poslist(reverse: true)).to eql('6,6 5,5 4,4 3,3 2,2 1,1 0,0')
|
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
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
describe '> Distances...' do
|
214
|
+
before(:each) do
|
215
|
+
@p1 = double(GeoRuby::SimpleFeatures::Point)
|
216
|
+
@p2 = double(GeoRuby::SimpleFeatures::Point)
|
217
|
+
@p3 = double(GeoRuby::SimpleFeatures::Point)
|
218
|
+
@line = GeoRuby::SimpleFeatures::LineString.from_points([@p1, @p2, @p3])
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'should print the length with haversine' do
|
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)
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'should print lenght as euclidian' do
|
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)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
describe 'Simplify' do
|
235
|
+
|
236
|
+
let(:line) { GeoRuby::SimpleFeatures::LineString.from_coordinates([[6, 0], [4, 1], [3, 4], [4, 6], [5, 8], [5, 9], [4, 10], [6, 15]], 4326) }
|
237
|
+
|
238
|
+
it 'should simplify a simple linestring' do
|
239
|
+
line = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12, 15], [14, 17], [17, 20]], 4326)
|
240
|
+
expect(line.simplify.points.size).to eq(2)
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'should simplify a harder linestring' do
|
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)
|
247
|
+
end
|
248
|
+
|
249
|
+
it 'should barely touch it' do
|
250
|
+
expect(line.simplify(1).points.size).to eq(7)
|
251
|
+
end
|
252
|
+
|
253
|
+
it 'should simplify to five points' do
|
254
|
+
expect(line.simplify(7).points.size).to eq(5)
|
255
|
+
end
|
256
|
+
|
257
|
+
it 'should flatten it' do
|
258
|
+
expect(line.simplify(11).points.size).to eq(2)
|
259
|
+
end
|
260
|
+
|
261
|
+
it 'should be the first and last in a flatten' do
|
262
|
+
l = line.simplify(11)
|
263
|
+
expect(l[0]).to be_a_point(6, 0)
|
264
|
+
expect(l[1]).to be_a_point(6, 15)
|
265
|
+
end
|
266
|
+
|
267
|
+
end
|
268
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe GeoRuby::SimpleFeatures::LinearRing do
|
4
|
+
|
5
|
+
it 'should instantiate' do
|
6
|
+
lr = GeoRuby::SimpleFeatures::LinearRing.new(4326)
|
7
|
+
expect(lr).to be_instance_of(GeoRuby::SimpleFeatures::LinearRing)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'Instance' do
|
11
|
+
|
12
|
+
let(:lr) { GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[10, 10], [20, 45], [45, 10], [10, 10]], 256) }
|
13
|
+
|
14
|
+
it 'should test if contains a point' do
|
15
|
+
expect(lr.contains_point?(GeoRuby::SimpleFeatures::Point.from_x_y(21, 21))).to be_truthy
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should test if not contains a point' do
|
19
|
+
expect(lr.contains_point?(GeoRuby::SimpleFeatures::Point.from_x_y(21, 51))).to be_falsey
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|