georuby 2.3.0 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -1,87 +1,87 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GeoRuby::Gpx4r do
|
4
4
|
|
5
5
|
it "should add gpx extension and raise if doesn't exists" do
|
6
6
|
expect do
|
7
|
-
expect(File).to receive(:
|
7
|
+
expect(File).to receive(:exist?).with('short.gpx').and_return(false)
|
8
8
|
expect(GeoRuby::Gpx4r::GpxFile.open('short')).to be_truthy
|
9
9
|
end.to raise_error GeoRuby::Gpx4r::MalformedGpxException
|
10
10
|
end
|
11
11
|
|
12
|
-
describe
|
12
|
+
describe 'Waypoints' do
|
13
13
|
|
14
14
|
before(:all) do
|
15
|
-
@gpxfile = GeoRuby::Gpx4r::GpxFile.open(File.dirname(__FILE__) + '
|
16
|
-
@gpxfile2 = GeoRuby::Gpx4r::GpxFile.open(File.dirname(__FILE__) + '
|
17
|
-
@gpxfile3 = GeoRuby::Gpx4r::GpxFile.open(File.dirname(__FILE__) + '
|
15
|
+
@gpxfile = GeoRuby::Gpx4r::GpxFile.open(File.dirname(__FILE__) + '/../data/gpx/short.gpx', with_z: true, with_m: true)
|
16
|
+
@gpxfile2 = GeoRuby::Gpx4r::GpxFile.open(File.dirname(__FILE__) + '/../data/gpx/fells_loop', with_z: true, with_m: true)
|
17
|
+
@gpxfile3 = GeoRuby::Gpx4r::GpxFile.open(File.dirname(__FILE__) + '/../data/gpx/tracktreks.gpx', with_z: true)
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it 'should open and parse' do
|
21
21
|
expect(@gpxfile.record_count).to eql(2724)
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
24
|
+
it 'should open and parse no trkpt one' do
|
25
25
|
expect(@gpxfile2.record_count).to eql(86)
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
28
|
+
it 'should open and parse 3' do
|
29
29
|
expect(@gpxfile3.record_count).to eql(225)
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
32
|
+
it 'should read X and Y' do
|
33
33
|
expect(@gpxfile[0].x).to be_within(0.0001).of(9.093942)
|
34
34
|
expect(@gpxfile[0].y).to be_within(0.0001).of(48.731813)
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
37
|
+
it 'should read Z and M' do
|
38
38
|
expect(@gpxfile[0].z).to eql(468.0)
|
39
|
-
expect(@gpxfile[0].m).to eql(
|
39
|
+
expect(@gpxfile[0].m).to eql('2008-09-07T17:36:57Z')
|
40
40
|
end
|
41
41
|
|
42
|
-
it
|
42
|
+
it 'should read X and Y 2' do
|
43
43
|
expect(@gpxfile2[0].x).to be_within(0.0001).of(-71.119277)
|
44
44
|
expect(@gpxfile2[0].y).to be_within(0.0001).of(42.438878)
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
47
|
+
it 'should read Z and M 2' do
|
48
48
|
expect(@gpxfile2[0].z).to eql(44.586548)
|
49
|
-
expect(@gpxfile2[0].m).to eql(
|
49
|
+
expect(@gpxfile2[0].m).to eql('2001-11-28T21:05:28Z')
|
50
50
|
end
|
51
51
|
|
52
|
-
it
|
52
|
+
it 'should read X and Y 3' do
|
53
53
|
expect(@gpxfile3[0].x).to be_within(0.0001).of(-149.8358011)
|
54
54
|
expect(@gpxfile3[0].y).to be_within(0.0001).of(-17.5326508)
|
55
55
|
end
|
56
56
|
|
57
|
-
it
|
57
|
+
it 'should read Z and M 3' do
|
58
58
|
expect(@gpxfile3[0].z).to eql(88.5787354)
|
59
59
|
expect(@gpxfile3[0].m).to eql(0.0)
|
60
60
|
end
|
61
61
|
|
62
|
-
it
|
62
|
+
it 'should return it as a linestring' do
|
63
63
|
expect(@gpxfile.as_line_string).to be_instance_of GeoRuby::SimpleFeatures::LineString
|
64
64
|
expect(@gpxfile.as_polyline).to be_instance_of GeoRuby::SimpleFeatures::LineString
|
65
65
|
end
|
66
66
|
|
67
|
-
it
|
67
|
+
it 'should return it as a linestring 3' do
|
68
68
|
expect(@gpxfile3.as_line_string).to be_instance_of GeoRuby::SimpleFeatures::LineString
|
69
69
|
expect(@gpxfile3.as_polyline).to be_instance_of GeoRuby::SimpleFeatures::LineString
|
70
70
|
end
|
71
71
|
|
72
|
-
it
|
72
|
+
it 'should return a envelope' do
|
73
73
|
expect(@gpxfile.envelope).to be_instance_of GeoRuby::SimpleFeatures::Envelope
|
74
74
|
expect(@gpxfile.envelope.lower_corner.x).to be_within(0.001).of(9.08128)
|
75
75
|
expect(@gpxfile.envelope.lower_corner.y).to be_within(0.001).of(48.7169)
|
76
76
|
end
|
77
77
|
|
78
|
-
it
|
78
|
+
it 'should return a envelope 3' do
|
79
79
|
expect(@gpxfile3.envelope).to be_instance_of GeoRuby::SimpleFeatures::Envelope
|
80
80
|
expect(@gpxfile3.envelope.lower_corner.x).to be_within(0.001).of(-149.8422613)
|
81
81
|
expect(@gpxfile3.envelope.lower_corner.y).to be_within(0.001).of(-17.547636)
|
82
82
|
end
|
83
83
|
|
84
|
-
it
|
84
|
+
it 'should return it as a polygon' do
|
85
85
|
[@gpxfile, @gpxfile2, @gpxfile3].each do |g|
|
86
86
|
expect(g.as_polygon).to be_instance_of GeoRuby::SimpleFeatures::Polygon
|
87
87
|
expect(g.as_polygon[0]).to be_instance_of GeoRuby::SimpleFeatures::LinearRing
|
@@ -90,13 +90,13 @@ describe GeoRuby::Gpx4r do
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
it
|
93
|
+
it 'should close the polygon' do
|
94
94
|
se = GeoRuby::SimpleFeatures::Point.from_x_y(-44, -23)
|
95
95
|
sw = GeoRuby::SimpleFeatures::Point.from_x_y(-42, -22)
|
96
96
|
nw = GeoRuby::SimpleFeatures::Point.from_x_y(-42, -25)
|
97
97
|
ne = GeoRuby::SimpleFeatures::Point.from_x_y(-44, -21)
|
98
|
-
@gpxfile.instance_variable_set(:@points, [se,sw,nw,ne])
|
99
|
-
expect(@gpxfile.as_polygon).to eq(GeoRuby::SimpleFeatures::Polygon.from_points([[se,sw,nw,ne,se]]))
|
98
|
+
@gpxfile.instance_variable_set(:@points, [se, sw, nw, ne])
|
99
|
+
expect(@gpxfile.as_polygon).to eq(GeoRuby::SimpleFeatures::Polygon.from_points([[se, sw, nw, ne, se]]))
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
data/spec/geo_ruby/kml_spec.rb
CHANGED
@@ -2,97 +2,101 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
2
|
|
3
3
|
describe GeoRuby::KmlParser do
|
4
4
|
before(:all) do
|
5
|
-
POINT =
|
6
|
-
LINESTRING =
|
7
|
-
LINEARRING =
|
8
|
-
POLYGON =
|
9
|
-
COMPLEX_POLYGON =
|
10
|
-
MULTIGEOMETRY =
|
11
|
-
POINT3D =
|
12
|
-
LINESTRING3D =
|
5
|
+
POINT = '<Point><coordinates>-82.4898187291883,34.2473206042649</coordinates></Point>'
|
6
|
+
LINESTRING = '<LineString><coordinates>-122.365662,37.826988 -122.365202,37.826302 -122.364581,37.82655 -122.365038,37.827237</coordinates></LineString>'
|
7
|
+
LINEARRING = '<LinearRing><coordinates>-122.365662,37.826988 -122.365202,37.826302 -122.364581,37.82655 -122.365038,37.827237 -122.365662,37.826988</coordinates></LinearRing>'
|
8
|
+
POLYGON = '<Polygon><outerBoundaryIs><LinearRing><coordinates>-82.5961385808407,34.0134202383713 -82.6029437979289,34.0346366848087 -82.6603553035687,34.1083560439036 -82.7357807829899,34.1697961502507 -82.7425935601244,34.2055536194311 -82.3145921793097,34.4812209701586 -82.2758648198483,34.4347213073308 -82.2405017851073,34.4067761024174 -82.3327002190662,34.3417863447576 -82.2910826671599,34.2708004396966 -82.2497468801283,34.2261551348023 -82.2370438982521,34.1709424545969 -82.2569955519648,34.1119142196088 -82.3237086862075,34.0601294413679 -82.368425596693,34.0533120146082 -82.4455985300521,34.0562556252352 -82.4806178108032,34.0759686807282 -82.5334224196077,34.0620944842448 -82.5961385808407,34.0134202383713</coordinates></LinearRing></outerBoundaryIs></Polygon>'
|
9
|
+
COMPLEX_POLYGON = '<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.366278,37.818844 -122.365248,37.819267 -122.36564,37.819861 -122.366669,37.819429 -122.366278,37.818844</coordinates></LinearRing></outerBoundaryIs><innerBoundaryIs><LinearRing><coordinates>-122.366212,37.818977 -122.365424,37.819294 -122.365704,37.819731 -122.366488,37.819402 -122.366212,37.818977</coordinates></LinearRing></innerBoundaryIs></Polygon>'
|
10
|
+
MULTIGEOMETRY = '<MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>-82.5961385808407,34.0134202383713 -82.6029437979289,34.0346366848087 -82.6603553035687,34.1083560439036 -82.7357807829899,34.1697961502507 -82.7425935601244,34.2055536194311 -82.3145921793097,34.4812209701586 -82.2758648198483,34.4347213073308 -82.2405017851073,34.4067761024174 -82.3327002190662,34.3417863447576 -82.2910826671599,34.2708004396966 -82.2497468801283,34.2261551348023 -82.2370438982521,34.1709424545969 -82.2569955519648,34.1119142196088 -82.3237086862075,34.0601294413679 -82.368425596693,34.0533120146082 -82.4455985300521,34.0562556252352 -82.4806178108032,34.0759686807282 -82.5334224196077,34.0620944842448 -82.5961385808407,34.0134202383713</coordinates></LinearRing></outerBoundaryIs></Polygon><Point><coordinates>-82.4898187291883,34.2473206042649</coordinates></Point></MultiGeometry>'
|
11
|
+
POINT3D = '<Point><coordinates>-82.4898187291883,34.2473206042649,5</coordinates></Point>'
|
12
|
+
LINESTRING3D = '<LineString><coordinates>-122.365662,37.826988,1 -122.365202,37.826302,2 -122.364581,37.82655,3 -122.365038,37.827237,4</coordinates></LineString>'
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
before(:each) do
|
16
16
|
@factory = GeoRuby::SimpleFeatures::GeometryFactory.new
|
17
17
|
@kml_parser = described_class.new(@factory)
|
18
18
|
end
|
19
|
-
|
20
|
-
it
|
19
|
+
|
20
|
+
it 'should parse a GeoRuby::SimpleFeatures::Point correctly' do
|
21
21
|
@kml_parser.parse(POINT)
|
22
22
|
g = @factory.geometry
|
23
23
|
expect(g).not_to eql(nil)
|
24
24
|
expect(g).to be_an_instance_of(GeoRuby::SimpleFeatures::Point)
|
25
|
-
expect(g.as_kml.gsub(/\n/,'')).to eql(POINT)
|
25
|
+
expect(g.as_kml.gsub(/\n/, '')).to eql(POINT)
|
26
26
|
end
|
27
|
-
|
28
|
-
it
|
27
|
+
|
28
|
+
it 'should parse a GeoRuby::SimpleFeatures::LineString correctly' do
|
29
29
|
@kml_parser.parse(LINESTRING)
|
30
30
|
g = @factory.geometry
|
31
31
|
expect(g).not_to eql(nil)
|
32
32
|
expect(g).to be_an_instance_of(GeoRuby::SimpleFeatures::LineString)
|
33
|
-
expect(g.as_kml.gsub(/\n/,'')).to eql(LINESTRING)
|
33
|
+
expect(g.as_kml.gsub(/\n/, '')).to eql(LINESTRING)
|
34
34
|
|
35
35
|
@kml_parser.parse(LINEARRING)
|
36
36
|
g = @factory.geometry
|
37
37
|
expect(g).not_to eql(nil)
|
38
38
|
expect(g).to be_an_instance_of(GeoRuby::SimpleFeatures::LinearRing)
|
39
|
-
expect(g.as_kml.gsub(/\n/,'')).to eql(LINEARRING)
|
39
|
+
expect(g.as_kml.gsub(/\n/, '')).to eql(LINEARRING)
|
40
40
|
end
|
41
|
-
|
42
|
-
it
|
41
|
+
|
42
|
+
it 'should parse a GeoRuby::SimpleFeatures::Polygon correctly' do
|
43
43
|
@kml_parser.parse(POLYGON)
|
44
44
|
g = @factory.geometry
|
45
45
|
expect(g).not_to eql(nil)
|
46
46
|
expect(g).to be_an_instance_of(GeoRuby::SimpleFeatures::Polygon)
|
47
|
-
expect(g.as_kml.gsub(/\n/,'')).to eql(POLYGON)
|
47
|
+
expect(g.as_kml.gsub(/\n/, '')).to eql(POLYGON)
|
48
48
|
|
49
49
|
@kml_parser.parse(COMPLEX_POLYGON)
|
50
50
|
g = @factory.geometry
|
51
51
|
expect(g).not_to eql(nil)
|
52
52
|
expect(g).to be_an_instance_of(GeoRuby::SimpleFeatures::Polygon)
|
53
|
-
expect(g.as_kml.gsub(/\n/,'')).to eql(COMPLEX_POLYGON)
|
53
|
+
expect(g.as_kml.gsub(/\n/, '')).to eql(COMPLEX_POLYGON)
|
54
54
|
end
|
55
|
-
|
56
|
-
it
|
55
|
+
|
56
|
+
it 'should parse a MultiGeometry correctly' do
|
57
57
|
@kml_parser.parse(MULTIGEOMETRY)
|
58
58
|
g = @factory.geometry
|
59
59
|
expect(g).not_to eql(nil)
|
60
60
|
expect(g.geometries.length).to eql(2)
|
61
61
|
expect(g).to be_an_instance_of(GeoRuby::SimpleFeatures::GeometryCollection)
|
62
|
-
expect(g.as_kml.gsub(/\n/,'')).to eql(MULTIGEOMETRY)
|
62
|
+
expect(g.as_kml.gsub(/\n/, '')).to eql(MULTIGEOMETRY)
|
63
63
|
end
|
64
|
-
|
65
|
-
it
|
66
|
-
# not testing generation because GeoRuby kml generation logic currently
|
67
|
-
# XML nodes to actually output 3D coordinate
|
64
|
+
|
65
|
+
it 'should parse 3D geometries correctly' do
|
66
|
+
# not testing generation because GeoRuby kml generation logic currently
|
67
|
+
# requires additional XML nodes to actually output 3D coordinate
|
68
|
+
# information. I might modify that behavior.
|
68
69
|
g = @kml_parser.parse(POINT3D)
|
69
70
|
expect(g).not_to eql(nil)
|
70
71
|
expect(g.with_z).to eql(true)
|
71
|
-
# g.as_kml(:altitude_mode => "clampToGround").gsub(/\n/,'')
|
72
|
+
# g.as_kml(:altitude_mode => "clampToGround").gsub(/\n/,'')
|
73
|
+
# .should eql(POINT3D)
|
72
74
|
|
73
75
|
g = @kml_parser.parse(LINESTRING3D)
|
74
76
|
expect(g).not_to eql(nil)
|
75
77
|
expect(g.with_z).to eql(true)
|
76
|
-
# g.as_kml(:altitude_mode => "clampToGround").gsub(/\n/,'')
|
78
|
+
# g.as_kml(:altitude_mode => "clampToGround").gsub(/\n/,'')
|
79
|
+
# .should eql(LINESTRING3D)
|
77
80
|
end
|
78
81
|
|
79
|
-
it
|
80
|
-
[LINESTRING, LINEARRING, POLYGON, COMPLEX_POLYGON,
|
82
|
+
it 'should yield a geometries with functional bounding boxes' do
|
83
|
+
[LINESTRING, LINEARRING, POLYGON, COMPLEX_POLYGON,
|
84
|
+
MULTIGEOMETRY, LINESTRING3D].each do |kml|
|
81
85
|
@kml_parser.parse(kml)
|
82
86
|
g = @factory.geometry
|
83
|
-
expect
|
87
|
+
expect do
|
84
88
|
g.bounding_box
|
85
|
-
|
89
|
+
end.not_to raise_error
|
86
90
|
end
|
87
91
|
end
|
88
92
|
|
89
|
-
it
|
93
|
+
it 'should yield a geometries with functional envelopes' do
|
90
94
|
[LINESTRING, LINEARRING, POLYGON, COMPLEX_POLYGON, MULTIGEOMETRY, LINESTRING3D].each do |kml|
|
91
95
|
@kml_parser.parse(kml)
|
92
96
|
g = @factory.geometry
|
93
|
-
expect
|
97
|
+
expect do
|
94
98
|
g.envelope.center
|
95
|
-
|
99
|
+
end.not_to raise_error
|
96
100
|
end
|
97
101
|
end
|
98
102
|
end
|
@@ -2,119 +2,119 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
2
2
|
|
3
3
|
describe GeoRuby::Shp4r do
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe 'Point' do
|
6
6
|
before(:each) do
|
7
7
|
@shpfile = GeoRuby::Shp4r::ShpFile.open(File.dirname(__FILE__) + '/../../data/point.shp')
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
10
|
+
it 'should parse ok' do
|
11
11
|
expect(@shpfile.record_count).to eql(2)
|
12
12
|
expect(@shpfile.fields.size).to eq(1)
|
13
13
|
expect(@shpfile.shp_type).to eql(GeoRuby::Shp4r::ShpType::POINT)
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it 'should parse fields' do
|
17
17
|
field = @shpfile.fields.first
|
18
|
-
expect(field.name).to eql(
|
19
|
-
expect(field.type).to eql(
|
18
|
+
expect(field.name).to eql('Hoyoyo')
|
19
|
+
expect(field.type).to eql('N')
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
22
|
+
it 'should parse record 1' do
|
23
23
|
rec = @shpfile[0]
|
24
24
|
expect(rec.geometry).to be_kind_of GeoRuby::SimpleFeatures::Point
|
25
25
|
expect(rec.geometry.x).to be_within(0.00001).of(-90.08375)
|
26
26
|
expect(rec.geometry.y).to be_within(0.00001).of(34.39996)
|
27
|
-
expect(rec.data[
|
27
|
+
expect(rec.data['Hoyoyo']).to eql(6)
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
30
|
+
it 'should parse record 2' do
|
31
31
|
rec = @shpfile[1]
|
32
32
|
expect(rec.geometry).to be_kind_of GeoRuby::SimpleFeatures::Point
|
33
33
|
expect(rec.geometry.x).to be_within(0.00001).of(-87.82580)
|
34
34
|
expect(rec.geometry.y).to be_within(0.00001).of(33.36416)
|
35
|
-
expect(rec.data[
|
35
|
+
expect(rec.data['Hoyoyo']).to eql(9)
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
39
39
|
|
40
|
-
describe
|
40
|
+
describe 'Polyline' do
|
41
41
|
before(:each) do
|
42
42
|
@shpfile = GeoRuby::Shp4r::ShpFile.open(File.dirname(__FILE__) + '/../../data/polyline.shp')
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
45
|
+
it 'should parse ok' do
|
46
46
|
expect(@shpfile.record_count).to eql(1)
|
47
47
|
expect(@shpfile.fields.size).to eq(1)
|
48
48
|
expect(@shpfile.shp_type).to eql(GeoRuby::Shp4r::ShpType::POLYLINE)
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
51
|
+
it 'should parse fields' do
|
52
52
|
field = @shpfile.fields.first
|
53
|
-
expect(field.name).to eql(
|
53
|
+
expect(field.name).to eql('Chipoto')
|
54
54
|
# GeoRuby::Shp4r::Dbf now uses the decimal to choose between int and float
|
55
55
|
# So here is N instead of F
|
56
|
-
expect(field.type).to eql(
|
56
|
+
expect(field.type).to eql('N')
|
57
57
|
end
|
58
58
|
|
59
|
-
it
|
59
|
+
it 'should parse record 1' do
|
60
60
|
rec = @shpfile[0]
|
61
61
|
expect(rec.geometry).to be_kind_of GeoRuby::SimpleFeatures::MultiLineString
|
62
62
|
expect(rec.geometry.length).to eql(1)
|
63
63
|
expect(rec.geometry[0].length).to eql(6)
|
64
|
-
expect(rec.data[
|
64
|
+
expect(rec.data['Chipoto']).to eql(5.678)
|
65
65
|
end
|
66
66
|
|
67
67
|
end
|
68
68
|
|
69
|
-
describe
|
69
|
+
describe 'Polygon' do
|
70
70
|
before(:each) do
|
71
71
|
@shpfile = GeoRuby::Shp4r::ShpFile.open(File.dirname(__FILE__) + '/../../data/polygon.shp')
|
72
72
|
end
|
73
73
|
|
74
|
-
it
|
74
|
+
it 'should parse ok' do
|
75
75
|
expect(@shpfile.record_count).to eql(1)
|
76
76
|
expect(@shpfile.fields.size).to eq(1)
|
77
77
|
expect(@shpfile.shp_type).to eql(GeoRuby::Shp4r::ShpType::POLYGON)
|
78
78
|
end
|
79
79
|
|
80
|
-
it
|
80
|
+
it 'should parse fields' do
|
81
81
|
field = @shpfile.fields.first
|
82
|
-
expect(field.name).to eql(
|
83
|
-
expect(field.type).to eql(
|
82
|
+
expect(field.name).to eql('Hello')
|
83
|
+
expect(field.type).to eql('C')
|
84
84
|
end
|
85
85
|
|
86
|
-
it
|
86
|
+
it 'should parse record 1' do
|
87
87
|
rec = @shpfile[0]
|
88
88
|
expect(rec.geometry).to be_kind_of GeoRuby::SimpleFeatures::MultiPolygon
|
89
89
|
expect(rec.geometry.length).to eql(1)
|
90
90
|
expect(rec.geometry[0].length).to eql(1)
|
91
91
|
expect(rec.geometry[0][0].length).to eql(7)
|
92
|
-
expect(rec.data[
|
92
|
+
expect(rec.data['Hello']).to eql('Bouyoul!')
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
describe
|
97
|
-
def cp_all_shp(file1,file2)
|
98
|
-
FileUtils.copy(file1 +
|
99
|
-
FileUtils.copy(file1 +
|
100
|
-
FileUtils.copy(file1 +
|
96
|
+
describe 'Write' do
|
97
|
+
def cp_all_shp(file1, file2)
|
98
|
+
FileUtils.copy(file1 + '.shp', file2 + '.shp')
|
99
|
+
FileUtils.copy(file1 + '.shx', file2 + '.shx')
|
100
|
+
FileUtils.copy(file1 + '.dbf', file2 + '.dbf')
|
101
101
|
end
|
102
102
|
|
103
103
|
def rm_all_shp(file)
|
104
|
-
FileUtils.rm(file +
|
105
|
-
FileUtils.rm(file +
|
106
|
-
FileUtils.rm(file +
|
104
|
+
FileUtils.rm(file + '.shp')
|
105
|
+
FileUtils.rm(file + '.shx')
|
106
|
+
FileUtils.rm(file + '.dbf')
|
107
107
|
end
|
108
108
|
|
109
|
-
it
|
109
|
+
it 'test_point' do
|
110
110
|
cp_all_shp(File.dirname(__FILE__) + '/../../data/point',
|
111
111
|
File.dirname(__FILE__) + '/../../data/point2')
|
112
112
|
shpfile = GeoRuby::Shp4r::ShpFile.open(File.dirname(__FILE__) + '/../../data/point2.shp')
|
113
113
|
|
114
114
|
shpfile.transaction do |tr|
|
115
115
|
expect(tr).to be_instance_of GeoRuby::Shp4r::ShpTransaction
|
116
|
-
tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::Point.from_x_y(123.4,123.4),'Hoyoyo' => 5))
|
117
|
-
tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::Point.from_x_y(-16.67,16.41),'Hoyoyo' => -7))
|
116
|
+
tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::Point.from_x_y(123.4, 123.4), 'Hoyoyo' => 5))
|
117
|
+
tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::Point.from_x_y(-16.67, 16.41), 'Hoyoyo' => -7))
|
118
118
|
tr.delete(1)
|
119
119
|
end
|
120
120
|
|
@@ -124,7 +124,7 @@ describe GeoRuby::Shp4r do
|
|
124
124
|
rm_all_shp(File.dirname(__FILE__) + '/../../data/point2')
|
125
125
|
end
|
126
126
|
|
127
|
-
it
|
127
|
+
it 'test_linestring' do
|
128
128
|
cp_all_shp(File.dirname(__FILE__) + '/../../data/polyline',
|
129
129
|
File.dirname(__FILE__) + '/../../data/polyline2')
|
130
130
|
|
@@ -132,8 +132,8 @@ describe GeoRuby::Shp4r do
|
|
132
132
|
|
133
133
|
shpfile.transaction do |tr|
|
134
134
|
expect(tr).to be_instance_of GeoRuby::Shp4r::ShpTransaction
|
135
|
-
tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::LineString.from_coordinates([[123.4,123.4],[45.6,12.3]]),'Chipoto' => 5.6778))
|
136
|
-
tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::LineString.from_coordinates([[23.4,13.4],[45.6,12.3],[12
|
135
|
+
tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::LineString.from_coordinates([[123.4, 123.4], [45.6, 12.3]]), 'Chipoto' => 5.6778))
|
136
|
+
tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::LineString.from_coordinates([[23.4, 13.4], [45.6, 12.3], [12, -67]]), 'Chipoto' => -7.1))
|
137
137
|
tr.delete(0)
|
138
138
|
end
|
139
139
|
|
@@ -142,7 +142,7 @@ describe GeoRuby::Shp4r do
|
|
142
142
|
rm_all_shp(File.dirname(__FILE__) + '/../../data/polyline2')
|
143
143
|
end
|
144
144
|
|
145
|
-
it
|
145
|
+
it 'test_polygon' do
|
146
146
|
cp_all_shp(File.dirname(__FILE__) + '/../../data/polygon',
|
147
147
|
File.dirname(__FILE__) + '/../../data/polygon2')
|
148
148
|
shpfile = GeoRuby::Shp4r::ShpFile.open(File.dirname(__FILE__) + '/../../data/polygon2.shp')
|
@@ -150,7 +150,7 @@ describe GeoRuby::Shp4r do
|
|
150
150
|
shpfile.transaction do |tr|
|
151
151
|
expect(tr).to be_instance_of GeoRuby::Shp4r::ShpTransaction
|
152
152
|
tr.delete(0)
|
153
|
-
tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[40,0],[40,40],[0,40],[0,0]],[[10,10],[10,20],[20,20],[10,10]]]),'Hello' =>
|
153
|
+
tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0], [40, 0], [40, 40], [0, 40], [0, 0]], [[10, 10], [10, 20], [20, 20], [10, 10]]]), 'Hello' => 'oook'))
|
154
154
|
end
|
155
155
|
|
156
156
|
expect(shpfile.record_count).to eql(1)
|
@@ -159,14 +159,14 @@ describe GeoRuby::Shp4r do
|
|
159
159
|
rm_all_shp(File.dirname(__FILE__) + '/../../data/polygon2')
|
160
160
|
end
|
161
161
|
|
162
|
-
it
|
162
|
+
it 'test_multipoint' do
|
163
163
|
cp_all_shp(File.dirname(__FILE__) + '/../../data/multipoint',
|
164
164
|
File.dirname(__FILE__) + '/../../data/multipoint2')
|
165
165
|
shpfile = GeoRuby::Shp4r::ShpFile.open(File.dirname(__FILE__) + '/../../data/multipoint2.shp')
|
166
166
|
|
167
167
|
shpfile.transaction do |tr|
|
168
168
|
expect(tr).to be_instance_of GeoRuby::Shp4r::ShpTransaction
|
169
|
-
tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[45.6
|
169
|
+
tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[45.6, -45.1], [12.4, 98.2], [51.2, -0.12], [156.12345, 56.109]]), 'Hello' => 5, 'Hoyoyo' => 'AEZAE'))
|
170
170
|
end
|
171
171
|
|
172
172
|
expect(shpfile.record_count).to eql(2)
|
@@ -175,7 +175,7 @@ describe GeoRuby::Shp4r do
|
|
175
175
|
rm_all_shp(File.dirname(__FILE__) + '/../../data/multipoint2')
|
176
176
|
end
|
177
177
|
|
178
|
-
it
|
178
|
+
it 'test_multi_polygon' do
|
179
179
|
cp_all_shp(File.dirname(__FILE__) + '/../../data/polygon',
|
180
180
|
File.dirname(__FILE__) + '/../../data/polygon4')
|
181
181
|
|
@@ -183,7 +183,7 @@ describe GeoRuby::Shp4r do
|
|
183
183
|
|
184
184
|
shpfile.transaction do |tr|
|
185
185
|
expect(tr).to be_instance_of GeoRuby::Shp4r::ShpTransaction
|
186
|
-
tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[40,0],[40,40],[0,40],[0,0]],[[10,10],[10,20],[20,20],[10,10]]])]),'Hello' =>
|
186
|
+
tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0], [40, 0], [40, 40], [0, 40], [0, 0]], [[10, 10], [10, 20], [20, 20], [10, 10]]])]), 'Hello' => 'oook'))
|
187
187
|
end
|
188
188
|
|
189
189
|
expect(shpfile.record_count).to eql(2)
|
@@ -193,7 +193,7 @@ describe GeoRuby::Shp4r do
|
|
193
193
|
rm_all_shp(File.dirname(__FILE__) + '/../../data/polygon4')
|
194
194
|
end
|
195
195
|
|
196
|
-
it
|
196
|
+
it 'test_rollback' do
|
197
197
|
cp_all_shp(File.dirname(__FILE__) + '/../../data/polygon',
|
198
198
|
File.dirname(__FILE__) + '/../../data/polygon5')
|
199
199
|
|
@@ -201,7 +201,7 @@ describe GeoRuby::Shp4r do
|
|
201
201
|
|
202
202
|
shpfile.transaction do |tr|
|
203
203
|
expect(tr).to be_instance_of GeoRuby::Shp4r::ShpTransaction
|
204
|
-
tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[40,0],[40,40],[0,40],[0,0]],[[10,10],[10,20],[20,20],[10,10]]])]),'Hello' =>
|
204
|
+
tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0], [40, 0], [40, 40], [0, 40], [0, 0]], [[10, 10], [10, 20], [20, 20], [10, 10]]])]), 'Hello' => 'oook'))
|
205
205
|
tr.rollback
|
206
206
|
end
|
207
207
|
expect(shpfile.record_count).to eql(1)
|
@@ -212,20 +212,20 @@ describe GeoRuby::Shp4r do
|
|
212
212
|
|
213
213
|
end
|
214
214
|
|
215
|
-
it
|
216
|
-
shpfile = GeoRuby::Shp4r::ShpFile.create(File.dirname(__FILE__) + '/../../data/point3.shp',GeoRuby::Shp4r::ShpType::POINT,[GeoRuby::Shp4r::Dbf::Field.new(
|
215
|
+
it 'test_creation' do
|
216
|
+
shpfile = GeoRuby::Shp4r::ShpFile.create(File.dirname(__FILE__) + '/../../data/point3.shp', GeoRuby::Shp4r::ShpType::POINT, [GeoRuby::Shp4r::Dbf::Field.new('Hoyoyo', 'C', 10, 0)])
|
217
217
|
shpfile.transaction do |tr|
|
218
|
-
tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::Point.from_x_y(123,123.4),'Hoyoyo' =>
|
218
|
+
tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::Point.from_x_y(123, 123.4), 'Hoyoyo' => 'HJHJJ'))
|
219
219
|
end
|
220
220
|
expect(shpfile.record_count).to eql(1)
|
221
221
|
shpfile.close
|
222
222
|
rm_all_shp(File.dirname(__FILE__) + '/../../data/point3')
|
223
223
|
end
|
224
224
|
|
225
|
-
it
|
226
|
-
shpfile = GeoRuby::Shp4r::ShpFile.create(File.dirname(__FILE__) + '/../../data/multipoint3.shp',GeoRuby::Shp4r::ShpType::MULTIPOINT,[GeoRuby::Shp4r::Dbf::Field.new(
|
225
|
+
it 'test_creation_multipoint' do
|
226
|
+
shpfile = GeoRuby::Shp4r::ShpFile.create(File.dirname(__FILE__) + '/../../data/multipoint3.shp', GeoRuby::Shp4r::ShpType::MULTIPOINT, [GeoRuby::Shp4r::Dbf::Field.new('Hoyoyo', 'C', 10), GeoRuby::Shp4r::Dbf::Field.new('Hello', 'N', 10)])
|
227
227
|
shpfile.transaction do |tr|
|
228
|
-
tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[123,123.4],[345,12.2]]),'Hoyoyo' =>
|
228
|
+
tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[123, 123.4], [345, 12.2]]), 'Hoyoyo' => 'HJHJJ', 'Hello' => 5))
|
229
229
|
end
|
230
230
|
expect(shpfile.record_count).to eql(1)
|
231
231
|
shpfile.close
|