active_road 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.rspec +1 -0
- data/.travis.yml +7 -2
- data/Gemfile +8 -2
- data/Guardfile +2 -6
- data/README.md +69 -9
- data/Rakefile +8 -7
- data/active_road.gemspec +19 -15
- data/app/models/active_road/access_link.rb +4 -4
- data/app/models/active_road/access_point.rb +5 -9
- data/app/models/active_road/boundary.rb +41 -0
- data/app/models/active_road/junction.rb +4 -18
- data/app/models/active_road/junction_conditionnal_cost.rb +2 -0
- data/app/models/active_road/junctions_physical_road.rb +5 -0
- data/app/models/active_road/logical_road.rb +5 -4
- data/app/models/active_road/osm_pbf_importer.rb +293 -0
- data/app/models/active_road/osm_pbf_importer_level_db.rb +784 -0
- data/app/models/active_road/path.rb +40 -9
- data/app/models/active_road/physical_road.rb +22 -27
- data/app/models/active_road/physical_road_conditionnal_cost.rb +3 -1
- data/app/models/active_road/request_conditionnal_cost_linker.rb +59 -0
- data/app/models/active_road/street_number.rb +60 -57
- data/app/models/active_road/terra_importer.rb +161 -0
- data/db/migrate/20120419093427_add_kind_to_physical_roads.rb +2 -2
- data/db/migrate/20140206091734_create_boundaries.rb +16 -0
- data/db/migrate/20140210132933_add_attributes_to_physical_road.rb +9 -0
- data/db/migrate/20140219095521_add_boundary_id_to_logical_road.rb +5 -0
- data/db/migrate/20140228072448_add_boundary_id_to_physical_road.rb +5 -0
- data/db/migrate/20140304141150_add_marker_to_physical_road.rb +5 -0
- data/db/migrate/20140310083550_add_tags_to_street_number.rb +5 -0
- data/db/migrate/20140317153437_add_index_to_conditionnal_costs.rb +6 -0
- data/db/migrate/20140602160047_add_physical_road_index_to_junctions_physical_road.rb +5 -0
- data/lib/active_road.rb +8 -2
- data/lib/active_road/engine.rb +4 -1
- data/lib/active_road/shortest_path/finder.rb +37 -46
- data/lib/active_road/simulation_tool.rb +73 -0
- data/lib/active_road/version.rb +1 -1
- data/lib/tasks/activeroad_tasks.rake +88 -4
- data/script/benchmark_import_kyotocabinet.rb +148 -0
- data/script/benchmark_shortest_path.rb +22 -0
- data/script/count_tag_in_osm_data.rb +114 -0
- data/script/import-tiger-numbers +3 -3
- data/spec/dummy/db/schema.rb +2 -1
- data/spec/dummy/db/structure.sql +100 -11
- data/spec/factories/boundary.rb +8 -0
- data/spec/factories/junction.rb +1 -1
- data/spec/factories/physical_road.rb +1 -2
- data/spec/fixtures/test.osm +120 -0
- data/spec/fixtures/test.osm.bz2 +0 -0
- data/spec/fixtures/test.osm.pbf +0 -0
- data/spec/lib/active_road/shortest_path/finder_spec.rb +143 -90
- data/spec/lib/active_road/shortest_path/performance_finder_spec.rb +59 -0
- data/spec/models/active_road/access_point_spec.rb +9 -18
- data/spec/models/active_road/junction_conditionnal_cost_spec.rb +4 -4
- data/spec/models/active_road/junction_spec.rb +34 -11
- data/spec/models/active_road/logical_road_spec.rb +20 -19
- data/spec/models/active_road/osm_pbf_importer_level_db_spec.rb +410 -0
- data/spec/models/active_road/path_spec.rb +1 -1
- data/spec/models/active_road/physical_road_conditionnal_cost_spec.rb +4 -4
- data/spec/models/active_road/physical_road_spec.rb +14 -3
- data/spec/models/active_road/request_conditionnal_cost_linker_spec.rb +65 -0
- data/spec/models/active_road/shared_examples/osm_pbf_importer_spec.rb +148 -0
- data/spec/models/active_road/street_number_spec.rb +58 -58
- data/spec/models/active_road/terra_importer_spec.rb +140 -0
- data/spec/spec_helper.rb +14 -9
- data/spec/support/geometry_support.rb +36 -0
- data/spec/support/profile.rb +19 -0
- data/tmp/performance/.gitignore +0 -0
- data/travis/before_install.sh +5 -9
- data/travis/before_script.sh +7 -7
- metadata +118 -121
- data/app/models/active_road/physical_road_filter.rb +0 -41
- data/app/models/active_road/terra_import.rb +0 -148
- data/spec/models/active_road/physical_road_filter_spec.rb +0 -85
- data/spec/models/active_road/terra_import_spec.rb +0 -113
- data/spec/support/georuby_ext.rb +0 -15
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe ActiveRoad::PhysicalRoadConditionnalCost do
|
3
|
+
describe ActiveRoad::PhysicalRoadConditionnalCost, :type => :model do
|
4
4
|
|
5
5
|
subject { create(:physical_road_conditionnal_cost) }
|
6
6
|
|
7
7
|
it "should have tags" do
|
8
|
-
subject.
|
8
|
+
expect(subject).to respond_to(:tags)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should have a cost" do
|
12
|
-
subject.
|
12
|
+
expect(subject).to respond_to(:cost)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should have a physical road" do
|
16
|
-
subject.
|
16
|
+
expect(subject).to respond_to(:physical_road_id)
|
17
17
|
end
|
18
18
|
|
19
19
|
end
|
@@ -1,17 +1,28 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe ActiveRoad::PhysicalRoad do
|
3
|
+
describe ActiveRoad::PhysicalRoad, :type => :model do
|
4
4
|
|
5
5
|
subject { create(:physical_road) }
|
6
6
|
|
7
7
|
it "should validate objectid uniqueness" do
|
8
8
|
other_road = build :physical_road, :objectid => subject.objectid
|
9
|
-
other_road.
|
9
|
+
expect(other_road).not_to be_valid
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should be valid with a logical_road" do
|
13
13
|
subject.logical_road = nil
|
14
|
-
subject.
|
14
|
+
expect(subject).to be_valid
|
15
|
+
end
|
16
|
+
|
17
|
+
describe ".nearest_to" do
|
18
|
+
let(:departure) { point(0, 0) }
|
19
|
+
let!(:ab) { create(:physical_road, :geometry => line_string( "0.0001 0.0001,1 1" ) ) }
|
20
|
+
let!(:ac) { create(:physical_road, :geometry => line_string( "-0.0001 -0.0001,-1 -1" ) ) }
|
21
|
+
let!(:ad) { create(:physical_road, :geometry => line_string( "-0.001 -0.001,-1 -1" ) ) }
|
22
|
+
|
23
|
+
it "should return physical roads in an area ordered from closest to farthest from a departure" do
|
24
|
+
expect(ActiveRoad::PhysicalRoad.nearest_to(departure)).to eq([ab]) #[ab, ac]
|
25
|
+
end
|
15
26
|
end
|
16
27
|
|
17
28
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveRoad::RequestConditionnalCostLinker, :type => :model do
|
4
|
+
|
5
|
+
let!(:physical_road) { create(:physical_road) }
|
6
|
+
let!(:conditionnal_costs) { [ create(:physical_road_conditionnal_cost, :tags => "bike", :cost => 0.1, :physical_road => physical_road),
|
7
|
+
create(:physical_road_conditionnal_cost, :tags => "pavement", :cost => 0.3, :physical_road => physical_road) ]
|
8
|
+
}
|
9
|
+
let(:physical_road_conditionnal_costs) { physical_road.physical_road_conditionnal_costs }
|
10
|
+
|
11
|
+
subject { ActiveRoad::RequestConditionnalCostLinker.new(["bike", "pavement", "~asphalt"]) }
|
12
|
+
|
13
|
+
describe "#authorized_constraints_intersection_with" do
|
14
|
+
|
15
|
+
it "should return true if authorized constraints intersection" do
|
16
|
+
allow(subject).to receive_messages :authorized_constraints => ["bike"]
|
17
|
+
expect(subject.authorized_constraints_intersection_with?(["bike"])).to eq(true)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#unauthorized_constraints_intersection_with" do
|
23
|
+
|
24
|
+
it "should return true if unauthorized constraints intersection" do
|
25
|
+
allow(subject).to receive_messages :unauthorized_constraints => ["bike"]
|
26
|
+
expect(subject.unauthorized_constraints_intersection_with?(["bike"])).to eq(true)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#linked?" do
|
32
|
+
|
33
|
+
it "should return true if tags in conditionnal costs and tag in constraints have common tags" do
|
34
|
+
rcc = ActiveRoad::RequestConditionnalCostLinker.new(["bike", "pavement"])
|
35
|
+
expect(rcc.linked?(["bike", "pavement"])).to eq(true)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return true if tags in conditionnal costs and unauthorized constraints have common tags" do
|
39
|
+
rcc = ActiveRoad::RequestConditionnalCostLinker.new(["~asphalt"])
|
40
|
+
physical_road_conditionnal_costs << create(:physical_road_conditionnal_cost, :tags => "asphalt", :cost => 0.1)
|
41
|
+
expect(rcc.linked?(["bike", "pavement", "asphalt"])).to eq(true)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return false if tags in conditionnal costs have common tags with authorized or unauthorized constraints" do
|
45
|
+
rcc = ActiveRoad::RequestConditionnalCostLinker.new([])
|
46
|
+
expect(rcc.linked?(physical_road_conditionnal_costs)).to eq(false)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#conditionnal_costs_sum" do
|
52
|
+
|
53
|
+
it "should return the sum for conditionnal costs" do
|
54
|
+
expect(subject.conditionnal_costs_sum(physical_road_conditionnal_costs)).to eq(0.4)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return infinity for conditionnal costs with an infinity value in it" do
|
58
|
+
rcc = ActiveRoad::RequestConditionnalCostLinker.new(["bike", "pavement", "test"])
|
59
|
+
physical_road_conditionnal_costs << create(:physical_road_conditionnal_cost, :tags => "test", :cost => Float::MAX)
|
60
|
+
expect(rcc.conditionnal_costs_sum(physical_road_conditionnal_costs)).to eq(Float::INFINITY)
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
shared_examples "an OsmPbfImporter module" do
|
2
|
+
|
3
|
+
describe "#pedestrian?" do
|
4
|
+
it "should return true when tag key is highway and tag value is good" do
|
5
|
+
expect(importer.pedestrian?({"highway" => "pedestrian"})).to be_truthy
|
6
|
+
expect(importer.pedestrian?({"highway" => "path"})).to be_truthy
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should return false when tag key is not highway or tag value is not good" do
|
10
|
+
expect(importer.pedestrian?({"highway" => "residential"})).to be_falsey
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#bike?" do
|
15
|
+
it "should return true when tag key is highway and tag value is good" do
|
16
|
+
expect(importer.bike?({"highway" => "cycleway"})).to be_truthy
|
17
|
+
expect(importer.bike?({"cycleway:right" => "lane"})).to be_truthy
|
18
|
+
expect(importer.bike?({"cycleway:left" => "lane"})).to be_truthy
|
19
|
+
expect(importer.bike?({"cycleway" => "lane"})).to be_truthy
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return false when tag key is not highway or tag value is not good" do
|
23
|
+
expect(importer.bike?({"highway" => "residential"})).to be_falsey
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#train?" do
|
28
|
+
it "should return true when tag key is railway and tag value is good" do
|
29
|
+
expect(importer.train?({"railway" => "rail"})).to be_truthy
|
30
|
+
expect(importer.train?({"railway" => "tram"})).to be_truthy
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return false when tag key is not railway or tag value is not good" do
|
34
|
+
expect(importer.train?({"highway" => "residential"})).to be_falsey
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#car?" do
|
39
|
+
it "should return true when tag key is highway and tag value is good" do
|
40
|
+
expect(importer.car?({"highway" => "motorway"})).to be_truthy
|
41
|
+
expect(importer.car?({"highway" => "secondary"})).to be_truthy
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return false when tag key is not highway or tag value is not good" do
|
45
|
+
expect(importer.car?({"highway" => "railway"})).to be_falsey
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#required_way?" do
|
50
|
+
it "should return true when tag key is highway or railway" do
|
51
|
+
tags = {"highway" => "primary"}
|
52
|
+
expect(importer.required_way?(ActiveRoad::OsmPbfImporter::way_required_tags_keys, tags)).to be_truthy
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should return false when no tag key with highway or railway" do
|
56
|
+
tags = {"maxspeed" => "100", "bike" => "oneway"}
|
57
|
+
expect(importer.required_way?(ActiveRoad::OsmPbfImporter::way_required_tags_keys, tags)).to be_falsey
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#selected_tags" do
|
62
|
+
it "should return true when " do
|
63
|
+
tags = {"highway" => "primary", "name" => "Rue montparnasse", "bridge" => "true", "other_tag" => "other_tag"}
|
64
|
+
expect(importer.selected_tags(tags, ActiveRoad::OsmPbfImporter.way_selected_tags_keys)).to eq({"name" => "Rue montparnasse" })
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#required_relation?" do
|
69
|
+
it "should return true when tag key is boundary" do
|
70
|
+
tags = {"boundary" => "administrative"}
|
71
|
+
expect(importer.required_relation?(tags)).to be_truthy
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should return false when no tag key with highway or railway" do
|
75
|
+
tags = {"other" => "100"}
|
76
|
+
expect(importer.required_relation?(tags)).to be_falsey
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "#physical_road_conditionnal_costs" do
|
81
|
+
let(:physical_road) { create(:physical_road) }
|
82
|
+
|
83
|
+
it "should return conditionnal cost with pedestrian, bike and train to infinity when tag key is car" do
|
84
|
+
expect(importer.physical_road_conditionnal_costs( ActiveRoad::OsmPbfImporter::Way.new("", [], true) )).to eq([["pedestrian", Float::MAX], ["bike", Float::MAX], ["train", Float::MAX]])
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should return conditionnal cost with pedestrian, bike, car and train to infinity when tag key is nothing" do
|
88
|
+
expect(importer.physical_road_conditionnal_costs( ActiveRoad::OsmPbfImporter::Way.new("", []) )).to eq([ ["car", Float::MAX], ["pedestrian", Float::MAX], ["bike", Float::MAX], ["train", Float::MAX]])
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#extract_relation_polygon" do
|
93
|
+
let!(:first_way_geom) { line_string( "0 0,1 1" ) }
|
94
|
+
let!(:second_way_geom) { line_string( "1 1,2 2" ) }
|
95
|
+
let!(:third_way_geom) { line_string( "2 2,0 0" ) }
|
96
|
+
|
97
|
+
it "should return an exception if way geometries are not connected" do
|
98
|
+
second_way_geom_not_connected = line_string( "1 1,3 3" )
|
99
|
+
expect { importer.extract_relation_polygon([first_way_geom, second_way_geom_not_connected, third_way_geom]) }.to raise_error
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should return polygon if way geometries are connected" do
|
103
|
+
expect(importer.extract_relation_polygon([first_way_geom, second_way_geom, third_way_geom])).to match_array( [ polygon(point(0.0,0.0), point(1.0,1.0), point(2.0,2.0)) ] )
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should return polygon if way geometries are connected and some of them have points in the reverse order" do
|
107
|
+
second_way_geom_reversed = line_string( "2 2,1 1" )
|
108
|
+
expect(importer.extract_relation_polygon([first_way_geom, second_way_geom_reversed, third_way_geom])).to match_array( [ polygon(point(0.0,0.0), point(1.0,1.0), point(2.0,2.0)) ] )
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "#join_ways"
|
114
|
+
|
115
|
+
describe "#join_way"
|
116
|
+
|
117
|
+
describe ActiveRoad::OsmPbfImporter::EndpointToWayMap
|
118
|
+
|
119
|
+
describe ActiveRoad::OsmPbfImporter::Way
|
120
|
+
|
121
|
+
describe ActiveRoad::OsmPbfImporter::Node do
|
122
|
+
|
123
|
+
let(:node) { ActiveRoad::OsmPbfImporter::Node.new("122323131", 34.2, 12.5) }
|
124
|
+
|
125
|
+
it "should return a node object when unmarhalling a dump of node object" do
|
126
|
+
data = Marshal.dump(node)
|
127
|
+
object = Marshal.load(data)
|
128
|
+
expect(object).to be_an_instance_of(ActiveRoad::OsmPbfImporter::Node)
|
129
|
+
expect(object.id).to eq(node.id)
|
130
|
+
expect(object.lon).to eq(node.lon)
|
131
|
+
expect(object.lat).to eq(node.lat)
|
132
|
+
expect(object.ways).to eq(node.ways)
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should return a node object with ways when we add a way" do
|
136
|
+
node.add_way("1223344")
|
137
|
+
data = Marshal.dump(node)
|
138
|
+
object = Marshal.load(data)
|
139
|
+
expect(object).to be_an_instance_of(ActiveRoad::OsmPbfImporter::Node)
|
140
|
+
expect(object.id).to eq(node.id)
|
141
|
+
expect(object.lon).to eq(node.lon)
|
142
|
+
expect(object.lat).to eq(node.lat)
|
143
|
+
expect(object.ways).to eq([ "1223344" ])
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
@@ -1,78 +1,78 @@
|
|
1
|
-
require 'spec_helper'
|
1
|
+
# require 'spec_helper'
|
2
2
|
|
3
|
-
describe ActiveRoad::StreetNumber do
|
3
|
+
# describe ActiveRoad::StreetNumber do
|
4
4
|
|
5
|
-
|
5
|
+
# subject { create :street_number }
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
# it "should have a number" do
|
8
|
+
# subject.should respond_to(:number)
|
9
|
+
# end
|
10
10
|
|
11
|
-
|
11
|
+
# describe "#previous" do
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
# it "should find previous StreetNumber in the same road" do
|
14
|
+
# other_number = create(:street_number, :physical_road => subject.road, :number => subject.number - 50)
|
15
|
+
# subject.previous.should == other_number
|
16
|
+
# end
|
17
17
|
|
18
|
-
|
18
|
+
# end
|
19
19
|
|
20
|
-
|
20
|
+
# describe "#next" do
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
# it "should find next StreetNumber in the same road" do
|
23
|
+
# other_number = create(:street_number, :physical_road => subject.road, :number => subject.number + 50)
|
24
|
+
# subject.next.should == other_number
|
25
|
+
# end
|
26
26
|
|
27
|
-
|
27
|
+
# end
|
28
28
|
|
29
|
-
|
29
|
+
# describe "location_on_road" do
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
31
|
+
# it "should return the stored location_on_road if exists" do
|
32
|
+
# subject.location_on_road = 0.3
|
33
|
+
# subject.location_on_road.should == 0.3
|
34
|
+
# end
|
35
|
+
|
36
|
+
# it "should be comptured when not specified at creation" do
|
37
|
+
# create(:street_number, :location_on_road => nil).location_on_road.should_not be_nil
|
38
|
+
# end
|
39
|
+
|
40
|
+
# context "when no location is stored" do
|
41
|
+
|
42
|
+
# before(:each) do
|
43
|
+
# subject.location_on_road = nil
|
44
|
+
# end
|
45
|
+
|
46
|
+
# it "should return nil" do
|
47
|
+
# subject.location_on_road.should be_nil
|
48
|
+
# end
|
49
|
+
|
50
|
+
# it "should use previous and next numbers to compute location" do
|
51
|
+
# subject.stub :previous => mock(:number => 50, :location_on_road => 0.5)
|
52
|
+
# subject.stub :next => mock(:number => 100, :location_on_road => 1)
|
53
|
+
# subject.number = "75"
|
54
|
+
# subject.location_on_road.should == 0.75
|
55
|
+
# end
|
56
56
|
|
57
|
-
|
57
|
+
# end
|
58
58
|
|
59
59
|
|
60
|
-
|
60
|
+
# end
|
61
61
|
|
62
|
-
end
|
62
|
+
# end
|
63
63
|
|
64
|
-
describe ActiveRoad::StreetNumber::Number do
|
64
|
+
# describe ActiveRoad::StreetNumber::Number do
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
# def number(value)
|
67
|
+
# ActiveRoad::StreetNumber::Number.new value
|
68
|
+
# end
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
# it "should support addition" do
|
71
|
+
# (number("50bis") + 50).should == number("100bis")
|
72
|
+
# end
|
73
73
|
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
# it "should support subtraction" do
|
75
|
+
# (number("100bis") - 50).should == number("50bis")
|
76
|
+
# end
|
77
77
|
|
78
|
-
end
|
78
|
+
# end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# require 'spec_helper'
|
2
|
+
|
3
|
+
# describe ActiveRoad::TerraImporter do
|
4
|
+
# let(:xml_file) { File.expand_path("../../../fixtures/terra.xml", __FILE__) }
|
5
|
+
|
6
|
+
# subject { ActiveRoad::TerraImporter.new( xml_file, "/tmp/terra_test.kch" ) }
|
7
|
+
|
8
|
+
# describe "#physical_road_conditionnal_costs" do
|
9
|
+
# let(:physical_road) { create(:physical_road) }
|
10
|
+
|
11
|
+
# it "should returnconditionnal cost with pedestrian, bike and train to infinity when tag key is car" do
|
12
|
+
# ActiveRoad::PhysicalRoadConditionnalCost.should_receive(:new).exactly(3).times
|
13
|
+
# subject.physical_road_conditionnal_costs({"highway" => "primary"})
|
14
|
+
# end
|
15
|
+
|
16
|
+
# it "should return nothing if tag key is not in ['highway', 'railway']" do
|
17
|
+
# ActiveRoad::PhysicalRoadConditionnalCost.should_receive(:new).exactly(0).times
|
18
|
+
# subject.physical_road_conditionnal_costs({"test" => "test"})
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
|
22
|
+
# describe "#backup_nodes" do
|
23
|
+
# before :each do
|
24
|
+
# subject.open_database(subject.database_path)
|
25
|
+
# end
|
26
|
+
|
27
|
+
# after :each do
|
28
|
+
# subject.close_database
|
29
|
+
# end
|
30
|
+
|
31
|
+
# it "should have import all nodes in a temporary database" do
|
32
|
+
# subject.backup_nodes(subject.database)
|
33
|
+
# object = Marshal.load(subject.database.get("ign-obj-100"))
|
34
|
+
# object.id.should == "ign-obj-100"
|
35
|
+
# object.geometry.should == "SRID=4326;POINT(2.331932632740265 48.85215698894743)"
|
36
|
+
# object.ways.should == ["ign-obj-184", "ign-obj-204"]
|
37
|
+
# object.end_of_way.should == false
|
38
|
+
# end
|
39
|
+
# end
|
40
|
+
|
41
|
+
# describe "#iterate_nodes" do
|
42
|
+
# let!(:point) { GeoRuby::SimpleFeatures::Point.from_x_y( 2.331932632740265, 48.85215698894743, 4326) }
|
43
|
+
|
44
|
+
# before :each do
|
45
|
+
# subject.open_database(subject.database_path)
|
46
|
+
# subject.database.set("1", Marshal.dump(ActiveRoad::TerraImporter::Node.new("1", "SRID=4326;POINT(2.331932632740265 48.85215698894743)", ["1", "2"])) )
|
47
|
+
# subject.database.set("2", Marshal.dump(ActiveRoad::TerraImporter::Node.new("2", "SRID=4326;POINT(2.331932632740265 48.85215698894743)", ["1", "3"])) )
|
48
|
+
# end
|
49
|
+
|
50
|
+
# after :each do
|
51
|
+
# subject.close_database
|
52
|
+
# end
|
53
|
+
|
54
|
+
# it "should iterate nodes to save it" do
|
55
|
+
# GeoRuby::SimpleFeatures::Point.stub :from_x_y => point
|
56
|
+
# subject.should_receive(:save_junctions).exactly(1).times.with([["1", point], ["2", point]], {"1" => ["1", "2"], "2" => ["1", "3"]})
|
57
|
+
# subject.iterate_nodes(subject.database)
|
58
|
+
# end
|
59
|
+
# end
|
60
|
+
|
61
|
+
# describe "#save_junctions" do
|
62
|
+
|
63
|
+
# let!(:physical_road) { create(:physical_road, :objectid => "1") }
|
64
|
+
# let!(:point) { GeoRuby::SimpleFeatures::Point.from_x_y( 0, 0, 4326) }
|
65
|
+
|
66
|
+
# it "should save junctions in postgresql database" do
|
67
|
+
# junctions_values = [["1", point], ["2", point]]
|
68
|
+
# junctions_ways = {"1" => ["1"], "2" => ["1"]}
|
69
|
+
|
70
|
+
# subject.save_junctions(junctions_values, junctions_ways)
|
71
|
+
|
72
|
+
# ActiveRoad::Junction.all.size.should == 2
|
73
|
+
# first_junction = ActiveRoad::Junction.first
|
74
|
+
# first_junction.objectid.should == "1"
|
75
|
+
# first_junction.physical_roads.should == [physical_road]
|
76
|
+
|
77
|
+
# last_junction = ActiveRoad::Junction.last
|
78
|
+
# last_junction.objectid.should == "2"
|
79
|
+
# last_junction.physical_roads.should == [physical_road]
|
80
|
+
# end
|
81
|
+
# end
|
82
|
+
|
83
|
+
# describe "#import" do
|
84
|
+
|
85
|
+
# it "should have import all physical roads" do
|
86
|
+
# subject.import
|
87
|
+
# ActiveRoad::PhysicalRoad.all.size.should == 78
|
88
|
+
# ActiveRoad::Junction.all.size.should == 70
|
89
|
+
# #ActiveRoad::StreetNumber.all.size.should == 20
|
90
|
+
# end
|
91
|
+
|
92
|
+
# end
|
93
|
+
|
94
|
+
# describe "#save_physical_roads_and_children" do
|
95
|
+
# let(:pr1) { ActiveRoad::PhysicalRoad.new :objectid => "physicalroad::1" }
|
96
|
+
# let(:pr2) { ActiveRoad::PhysicalRoad.new :objectid => "physicalroad::2" }
|
97
|
+
# let(:physical_roads) { [ pr1, pr2 ] }
|
98
|
+
# let(:prcc) { ActiveRoad::PhysicalRoadConditionnalCost.new :tags => "car", :cost => 0.3 }
|
99
|
+
# let(:physical_road_conditionnal_costs_by_objectid) { {pr1.objectid => [ [prcc] ]} }
|
100
|
+
|
101
|
+
# it "should save physical roads in postgresql database" do
|
102
|
+
# subject.save_physical_roads_and_children(physical_roads)
|
103
|
+
# ActiveRoad::PhysicalRoad.all.size.should == 2
|
104
|
+
# ActiveRoad::PhysicalRoad.first.objectid.should == "physicalroad::1"
|
105
|
+
# ActiveRoad::PhysicalRoad.last.objectid.should == "physicalroad::2"
|
106
|
+
# end
|
107
|
+
|
108
|
+
# it "should save physical road conditionnal costs in postgresql database" do
|
109
|
+
# subject.save_physical_roads_and_children(physical_roads, physical_road_conditionnal_costs_by_objectid)
|
110
|
+
# ActiveRoad::PhysicalRoadConditionnalCost.all.size.should == 1
|
111
|
+
# ActiveRoad::PhysicalRoadConditionnalCost.first.physical_road_id.should == ActiveRoad::PhysicalRoad.first.id
|
112
|
+
# end
|
113
|
+
# end
|
114
|
+
|
115
|
+
# describe ActiveRoad::TerraImporter::Node do
|
116
|
+
|
117
|
+
# let(:subject) { ActiveRoad::TerraImporter::Node.new("ign-obj-100", "SRID=4326;POINT(2.331932632740265 48.85215698894743") }
|
118
|
+
|
119
|
+
# it "should return a node object when unmarhalling a dump of node object" do
|
120
|
+
# data = Marshal.dump(subject)
|
121
|
+
# object = Marshal.load(data)
|
122
|
+
# object.should be_an_instance_of(ActiveRoad::TerraImporter::Node)
|
123
|
+
# object.id.should == subject.id
|
124
|
+
# object.geometry.should == subject.geometry
|
125
|
+
# object.ways.should == subject.ways
|
126
|
+
# end
|
127
|
+
|
128
|
+
# it "should return a node object with ways when we add a way" do
|
129
|
+
# subject.add_way("1223344")
|
130
|
+
# data = Marshal.dump(subject)
|
131
|
+
# object = Marshal.load(data)
|
132
|
+
# object.should be_an_instance_of(ActiveRoad::TerraImporter::Node)
|
133
|
+
# object.id.should == subject.id
|
134
|
+
# object.geometry.should == subject.geometry
|
135
|
+
# object.ways.should == [ "1223344" ]
|
136
|
+
# end
|
137
|
+
|
138
|
+
# end
|
139
|
+
|
140
|
+
# end
|