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.
Files changed (76) hide show
  1. checksums.yaml +15 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +7 -2
  4. data/Gemfile +8 -2
  5. data/Guardfile +2 -6
  6. data/README.md +69 -9
  7. data/Rakefile +8 -7
  8. data/active_road.gemspec +19 -15
  9. data/app/models/active_road/access_link.rb +4 -4
  10. data/app/models/active_road/access_point.rb +5 -9
  11. data/app/models/active_road/boundary.rb +41 -0
  12. data/app/models/active_road/junction.rb +4 -18
  13. data/app/models/active_road/junction_conditionnal_cost.rb +2 -0
  14. data/app/models/active_road/junctions_physical_road.rb +5 -0
  15. data/app/models/active_road/logical_road.rb +5 -4
  16. data/app/models/active_road/osm_pbf_importer.rb +293 -0
  17. data/app/models/active_road/osm_pbf_importer_level_db.rb +784 -0
  18. data/app/models/active_road/path.rb +40 -9
  19. data/app/models/active_road/physical_road.rb +22 -27
  20. data/app/models/active_road/physical_road_conditionnal_cost.rb +3 -1
  21. data/app/models/active_road/request_conditionnal_cost_linker.rb +59 -0
  22. data/app/models/active_road/street_number.rb +60 -57
  23. data/app/models/active_road/terra_importer.rb +161 -0
  24. data/db/migrate/20120419093427_add_kind_to_physical_roads.rb +2 -2
  25. data/db/migrate/20140206091734_create_boundaries.rb +16 -0
  26. data/db/migrate/20140210132933_add_attributes_to_physical_road.rb +9 -0
  27. data/db/migrate/20140219095521_add_boundary_id_to_logical_road.rb +5 -0
  28. data/db/migrate/20140228072448_add_boundary_id_to_physical_road.rb +5 -0
  29. data/db/migrate/20140304141150_add_marker_to_physical_road.rb +5 -0
  30. data/db/migrate/20140310083550_add_tags_to_street_number.rb +5 -0
  31. data/db/migrate/20140317153437_add_index_to_conditionnal_costs.rb +6 -0
  32. data/db/migrate/20140602160047_add_physical_road_index_to_junctions_physical_road.rb +5 -0
  33. data/lib/active_road.rb +8 -2
  34. data/lib/active_road/engine.rb +4 -1
  35. data/lib/active_road/shortest_path/finder.rb +37 -46
  36. data/lib/active_road/simulation_tool.rb +73 -0
  37. data/lib/active_road/version.rb +1 -1
  38. data/lib/tasks/activeroad_tasks.rake +88 -4
  39. data/script/benchmark_import_kyotocabinet.rb +148 -0
  40. data/script/benchmark_shortest_path.rb +22 -0
  41. data/script/count_tag_in_osm_data.rb +114 -0
  42. data/script/import-tiger-numbers +3 -3
  43. data/spec/dummy/db/schema.rb +2 -1
  44. data/spec/dummy/db/structure.sql +100 -11
  45. data/spec/factories/boundary.rb +8 -0
  46. data/spec/factories/junction.rb +1 -1
  47. data/spec/factories/physical_road.rb +1 -2
  48. data/spec/fixtures/test.osm +120 -0
  49. data/spec/fixtures/test.osm.bz2 +0 -0
  50. data/spec/fixtures/test.osm.pbf +0 -0
  51. data/spec/lib/active_road/shortest_path/finder_spec.rb +143 -90
  52. data/spec/lib/active_road/shortest_path/performance_finder_spec.rb +59 -0
  53. data/spec/models/active_road/access_point_spec.rb +9 -18
  54. data/spec/models/active_road/junction_conditionnal_cost_spec.rb +4 -4
  55. data/spec/models/active_road/junction_spec.rb +34 -11
  56. data/spec/models/active_road/logical_road_spec.rb +20 -19
  57. data/spec/models/active_road/osm_pbf_importer_level_db_spec.rb +410 -0
  58. data/spec/models/active_road/path_spec.rb +1 -1
  59. data/spec/models/active_road/physical_road_conditionnal_cost_spec.rb +4 -4
  60. data/spec/models/active_road/physical_road_spec.rb +14 -3
  61. data/spec/models/active_road/request_conditionnal_cost_linker_spec.rb +65 -0
  62. data/spec/models/active_road/shared_examples/osm_pbf_importer_spec.rb +148 -0
  63. data/spec/models/active_road/street_number_spec.rb +58 -58
  64. data/spec/models/active_road/terra_importer_spec.rb +140 -0
  65. data/spec/spec_helper.rb +14 -9
  66. data/spec/support/geometry_support.rb +36 -0
  67. data/spec/support/profile.rb +19 -0
  68. data/tmp/performance/.gitignore +0 -0
  69. data/travis/before_install.sh +5 -9
  70. data/travis/before_script.sh +7 -7
  71. metadata +118 -121
  72. data/app/models/active_road/physical_road_filter.rb +0 -41
  73. data/app/models/active_road/terra_import.rb +0 -148
  74. data/spec/models/active_road/physical_road_filter_spec.rb +0 -85
  75. data/spec/models/active_road/terra_import_spec.rb +0 -113
  76. data/spec/support/georuby_ext.rb +0 -15
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ActiveRoad::Path do
3
+ describe ActiveRoad::Path, :type => :model do
4
4
 
5
5
 
6
6
 
@@ -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.should respond_to(:tags)
8
+ expect(subject).to respond_to(:tags)
9
9
  end
10
10
 
11
11
  it "should have a cost" do
12
- subject.should respond_to(:cost)
12
+ expect(subject).to respond_to(:cost)
13
13
  end
14
14
 
15
15
  it "should have a physical road" do
16
- subject.should respond_to(:physical_road_id)
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.should_not be_valid
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.should be_valid
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
- subject { create :street_number }
5
+ # subject { create :street_number }
6
6
 
7
- it "should have a number" do
8
- subject.should respond_to(:number)
9
- end
7
+ # it "should have a number" do
8
+ # subject.should respond_to(:number)
9
+ # end
10
10
 
11
- describe "#previous" do
11
+ # describe "#previous" do
12
12
 
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
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
- end
18
+ # end
19
19
 
20
- describe "#next" do
20
+ # describe "#next" do
21
21
 
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
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
- end
27
+ # end
28
28
 
29
- describe "location_on_road" do
29
+ # describe "location_on_road" do
30
30
 
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
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
- end
57
+ # end
58
58
 
59
59
 
60
- end
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
- def number(value)
67
- ActiveRoad::StreetNumber::Number.new value
68
- end
66
+ # def number(value)
67
+ # ActiveRoad::StreetNumber::Number.new value
68
+ # end
69
69
 
70
- it "should support addition" do
71
- (number("50bis") + 50).should == number("100bis")
72
- end
70
+ # it "should support addition" do
71
+ # (number("50bis") + 50).should == number("100bis")
72
+ # end
73
73
 
74
- it "should support subtraction" do
75
- (number("100bis") - 50).should == number("50bis")
76
- end
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