active_road 0.0.2 → 0.0.3

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.
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,43 +1,44 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ActiveRoad::LogicalRoad do
3
+ describe ActiveRoad::LogicalRoad, :type => :model do
4
4
 
5
- subject { create(:logical_road) }
5
+ let(:boundary) { create(:boundary)}
6
+ subject { create(:logical_road, :boundary_id => boundary.id) }
6
7
 
7
8
  it "should have a name" do
8
- subject.should respond_to(:name)
9
+ expect(subject).to respond_to(:name)
9
10
  end
10
11
 
11
12
  describe "at" do
12
13
 
13
14
  context "when the given number exists" do
14
15
 
15
- #let(:physical_road) { create :physical_road, :logical_road => subject }
16
- #let(:number) { create :street_number, :physical_road => physical_road }
16
+ let(:physical_road) { create :physical_road, :logical_road => subject }
17
+ let(:number) { create :street_number, :physical_road => physical_road }
17
18
 
18
19
  it "should return the number geometry" do
19
- #subject.at(number.number).should == number.geometry
20
- subject.name.should_not be_nil
20
+ expect(subject.at(number.number)).to eq(number.geometry)
21
+ expect(subject.name).not_to be_nil
21
22
  end
22
23
 
23
24
  end
24
25
 
25
26
  context "when the given number is between two existing numbers" do
26
27
 
27
- # let(:physical_road) { create :physical_road, :logical_road => subject }
28
- # let(:number) { 45 }
29
- # let!(:previous_number) do
30
- # physical_road.numbers.create create.attributes_for(:street_number, :location_on_road => 0.5, :number => "30")
31
- # end
32
- # let!(:next_number) do
33
- # physical_road.numbers.create create.attributes_for(:street_number, :location_on_road => 1, :number => "60")
34
- # end
28
+ let(:physical_road) { create :physical_road, :logical_road => subject }
29
+ let(:number) { 45 }
30
+ let!(:previous_number) do
31
+ physical_road.numbers.create FactoryGirl.attributes_for(:street_number, :location_on_road => 0.5, :number => "30")
32
+ end
33
+ let!(:next_number) do
34
+ physical_road.numbers.create FactoryGirl.attributes_for(:street_number, :location_on_road => 1, :number => "60")
35
+ end
35
36
 
36
- # let(:estimated_geometry) { subject.geometry.interpolate_point(0.75) }
37
+ let(:estimated_geometry) { subject.geometry.interpolate_point(0.75) }
37
38
 
38
- # it "should return the estimated geometry" do
39
- # subject.at(number).should == estimated_geometry
40
- # end
39
+ it "should return the estimated geometry" do
40
+ expect(subject.at(number)).to eq(estimated_geometry)
41
+ end
41
42
 
42
43
  end
43
44
 
@@ -0,0 +1,410 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveRoad::OsmPbfImporterLevelDb, :type => :model do
4
+ let(:pbf_file) { File.expand_path("../../../fixtures/test.osm.pbf", __FILE__) }
5
+ let!(:subject_without_data) { ActiveRoad::OsmPbfImporterLevelDb.new( "", true, "/tmp/osm_pbf_nodes_test_without_data_leveldb", "/tmp/osm_pbf_ways_test_without_data_leveldb" ) }
6
+ let!(:subject_without_split) { ActiveRoad::OsmPbfImporterLevelDb.new( pbf_file, false, "/tmp/osm_pbf_nodes_test_leveldb", "/tmp/osm_pbf_ways_test_leveldb" ) }
7
+
8
+ subject { ActiveRoad::OsmPbfImporterLevelDb.new( pbf_file, true, "/tmp/osm_pbf_nodes_test_leveldb", "/tmp/osm_pbf_ways_test_leveldb" ) }
9
+
10
+ it_behaves_like "an OsmPbfImporter module" do
11
+ let(:importer) { subject }
12
+ end
13
+
14
+ describe "#update_nodes_with_way" do
15
+ before :each do
16
+ subject.backup_nodes
17
+ end
18
+
19
+ after :each do
20
+ subject.close_nodes_database
21
+ end
22
+
23
+ it "should have call update_node_with_way n times" do
24
+ #expect(subject).to receive(:update_node_with_way).exactly(3).times
25
+ subject.update_nodes_with_way
26
+ end
27
+
28
+ end
29
+
30
+ describe "#backup_ways" do
31
+ before :each do
32
+ subject.nodes_database
33
+ subject.ways_database
34
+
35
+ subject.backup_nodes
36
+ subject.update_nodes_with_way
37
+ end
38
+
39
+ after :each do
40
+ subject.close_nodes_database
41
+ subject.delete_nodes_database
42
+ subject.close_ways_database
43
+ subject.delete_ways_database
44
+ end
45
+
46
+ it "should have import all ways in temporary ways_database" do
47
+ subject.backup_ways
48
+ expect(subject.ways_database.count).to eq(13)
49
+ expect(subject.ways_database.keys).to eq(["2", "3-0", "3-1", "5-0", "5-1", "5-2", "6-0", "6-1", "6-2", "7","76809952", "8", "9"])
50
+ end
51
+
52
+ end
53
+
54
+ # describe "#update_node_with_way" do
55
+ # let(:way_id) { "1" }
56
+ # let(:node_ids) { ["1", "2", "3"] }
57
+
58
+ # before :each do
59
+ # subject_without_data.nodes_database.put("1", Marshal.dump(ActiveRoad::OsmPbfImporterLevelDb::Node.new("1", 2.0, 2.0)) )
60
+ # subject_without_data.nodes_database.put("2", Marshal.dump(ActiveRoad::OsmPbfImporterLevelDb::Node.new("2", 2.0, 2.0)) )
61
+ # subject_without_data.nodes_database.put("3", Marshal.dump(ActiveRoad::OsmPbfImporterLevelDb::Node.new("3", 2.0, 2.0)) )
62
+ # end
63
+
64
+ # after :each do
65
+ # subject_without_data.nodes_database.delete("1")
66
+ # subject_without_data.nodes_database.delete("2")
67
+ # subject_without_data.nodes_database.delete("3")
68
+
69
+ # subject_without_data.close_nodes_database
70
+ # end
71
+
72
+ # it "should have update all nodes with way in the temporary nodes_database" do
73
+ # subject_without_data.update_node_with_way(way_id, node_ids)
74
+
75
+ # node1 = Marshal.load(subject_without_data.nodes_database.get("1"))
76
+ # expect(node1.id).to eq("1")
77
+ # expect(node1.lon).to eq(2.0)
78
+ # expect(node1.lat).to eq(2.0)
79
+ # expect(node1.ways).to eq(["1"])
80
+ # expect(node1.end_of_way).to eq(true)
81
+
82
+ # node2 = Marshal.load(subject_without_data.nodes_database.get("2"))
83
+ # expect(node2.id).to eq("2")
84
+ # expect(node2.lon).to eq(2.0)
85
+ # expect(node2.lat).to eq(2.0)
86
+ # expect(node2.ways).to eq(["1"])
87
+ # expect(node2.end_of_way).to eq(false)
88
+
89
+ # node3 = Marshal.load(subject_without_data.nodes_database.get("3"))
90
+ # expect(node3.id).to eq("3")
91
+ # expect(node3.lon).to eq(2.0)
92
+ # expect(node3.lat).to eq(2.0)
93
+ # expect(node3.ways).to eq(["1"])
94
+ # expect(node3.end_of_way).to eq(true)
95
+ # end
96
+ # end
97
+
98
+ describe "#iterate_nodes" do
99
+ let!(:point) { GeoRuby::SimpleFeatures::Point.from_x_y( 0, 0, 4326) }
100
+
101
+ before :each do
102
+ subject_without_data.nodes_database.put("1", Marshal.dump(ActiveRoad::OsmPbfImporterLevelDb::Node.new("1", 2.0, 2.0, "", ["1", "2"], false, {"junction" => "roundabout"})) )
103
+ subject_without_data.nodes_database.put("2", Marshal.dump(ActiveRoad::OsmPbfImporterLevelDb::Node.new("2", 2.0, 2.0, "", ["1", "3"])) )
104
+ subject_without_data.nodes_database.put("3", Marshal.dump(ActiveRoad::OsmPbfImporterLevelDb::Node.new("3", 2.0, 2.0, "7,8", [], false, {"addr:street" => "Rue de Noaille"})) )
105
+ end
106
+
107
+ after :each do
108
+ subject_without_data.nodes_database.delete("1")
109
+ subject_without_data.nodes_database.delete("2")
110
+ subject_without_data.nodes_database.delete("3")
111
+
112
+ subject_without_data.close_nodes_database
113
+ end
114
+
115
+ it "should iterate nodes to save it" do
116
+ # GeoRuby::SimpleFeatures::Point.stub :from_x_y => point
117
+ # subject_without_data.should_receive(:backup_nodes_pgsql).exactly(1).times.with([["1", point, {"junction" => "roundabout"}], ["2", point, {}] ])
118
+ # subject_without_data.should_receive(:backup_street_numbers_pgsql).exactly(1).times.with([ ["3", point, "7,8", {"addr:street" => "Rue de Noaille"}] ])
119
+ subject_without_data.iterate_nodes
120
+ expect(ActiveRoad::Junction.all.collect(&:objectid)).to match_array(["1", "2"])
121
+ end
122
+ end
123
+
124
+ describe "#iterate_ways" do
125
+ let!(:line) { line_string( "0 0,2 2" ) }
126
+ let!(:line2) { line_string( "2 2,3 3" ) }
127
+ let!(:junction1) { create(:junction, :objectid => "1", :geometry => point(0, 0) ) }
128
+ let!(:junction2) { create(:junction, :objectid => "2", :geometry => point(2, 2) ) }
129
+ let!(:junction3) { create(:junction, :objectid => "3", :geometry => point(3, 3) ) }
130
+ let!(:boundary) { create(:boundary, :geometry => multi_polygon( [ polygon( point(0,0), point(2,0), point(2,2), point(0,2) ) ] ) ) }
131
+
132
+ before :each do
133
+ subject_without_data.nodes_database.put("1", Marshal.dump(ActiveRoad::OsmPbfImporterLevelDb::Node.new("1", 0.0, 0.0, "", ["1", "2"])) )
134
+ subject_without_data.nodes_database.put("2", Marshal.dump(ActiveRoad::OsmPbfImporterLevelDb::Node.new("2", 2.0, 2.0, "", ["1", "3"])) )
135
+ subject_without_data.nodes_database.put("3", Marshal.dump(ActiveRoad::OsmPbfImporterLevelDb::Node.new("3", 3.0, 3.0, "", ["1", "3"])) )
136
+ subject_without_data.ways_database.put("1", Marshal.dump(ActiveRoad::OsmPbfImporterLevelDb::Way.new("1-0", ["1", "2", "3"], true, false, false, false, "Test", "100", true, "", "", "", {"cycleway" => "lane"}) ) )
137
+ subject_without_data.ways_database.put("2", Marshal.dump(ActiveRoad::OsmPbfImporterLevelDb::Way.new("2-0", ["1", "2"], true, false, false, false, "Test", "100", true, "", "", "", {"toll" => "true"}) ) )
138
+ subject_without_data.ways_database.put("3", Marshal.dump(ActiveRoad::OsmPbfImporterLevelDb::Way.new("3-0", ["1", "2"], true, false, false, false, "Test", "100", true, "", "", "", {}) ) )
139
+ end
140
+
141
+ after :each do
142
+ subject_without_data.nodes_database.delete("1")
143
+ subject_without_data.nodes_database.delete("2")
144
+ subject_without_data.nodes_database.delete("3")
145
+
146
+ subject_without_data.ways_database.delete("1")
147
+ subject_without_data.ways_database.delete("2")
148
+ subject_without_data.ways_database.delete("3")
149
+
150
+ subject_without_data.close_nodes_database
151
+ subject_without_data.close_ways_database
152
+ end
153
+
154
+ it "should iterate ways to save it" do
155
+ subject_without_data.iterate_ways
156
+ expect(ActiveRoad::PhysicalRoad.all.collect(&:objectid)).to match_array(["1-0", "2-0", "3-0"]
157
+ )
158
+ end
159
+ end
160
+
161
+ describe "#way_geometry" do
162
+ let(:nodes) { [double("node1", :id => "1", :lon => 0.0, :lat => 0.0), double("node2", :id => "2", :lon => 1.0, :lat => 1.0), double("node3", :id => "3", :lon => 2.0, :lat => 2.0)] }
163
+
164
+ it "should update physical road geometry" do
165
+ expect(subject.way_geometry(nodes)).to eq(GeoRuby::SimpleFeatures::LineString.from_points( [point(0.0,0.0), point(1.0,1.0), point(2.0,2.0) ]))
166
+ end
167
+
168
+ end
169
+
170
+ describe "#split_way_with_nodes" do
171
+ let!(:simple_way) { ActiveRoad::OsmPbfImporterLevelDb::Way.new("1", ["1", "2", "3"], false, false, true, true, "SimpleWay" ) }
172
+ let(:complex_way) { ActiveRoad::OsmPbfImporterLevelDb::Way.new("2", ["4", "5", "6", "7", "8"], false, false, true, true, "ComplexWay" ) }
173
+ let(:complex_way_boundary) { ActiveRoad::OsmPbfImporterLevelDb::Way.new( "2", ["4", "6", "8"], false, false, true, true, "ComplexWayBoundary" ) }
174
+
175
+ before :each do
176
+ # Nodes for simple way
177
+ subject_without_data.nodes_database.put("1", Marshal.dump(ActiveRoad::OsmPbfImporterLevelDb::Node.new("1", -1.0, 1.0, "", [simple_way.id], true)) )
178
+ subject_without_data.nodes_database.put("2", Marshal.dump(ActiveRoad::OsmPbfImporterLevelDb::Node.new("2", 0.0, 1.0, "", [simple_way.id, "2"])) )
179
+ subject_without_data.nodes_database.put("3", Marshal.dump(ActiveRoad::OsmPbfImporterLevelDb::Node.new("3", 1.0, 1.0, "", [simple_way.id], true)) )
180
+
181
+ #Nodes for complex way
182
+ subject_without_data.nodes_database.put("4", Marshal.dump(ActiveRoad::OsmPbfImporterLevelDb::Node.new("4", -1.0, 1.0, "", [complex_way.id], true)) )
183
+ subject_without_data.nodes_database.put("5", Marshal.dump(ActiveRoad::OsmPbfImporterLevelDb::Node.new("5", 0.0, 1.0, "", [complex_way.id] )) )
184
+ subject_without_data.nodes_database.put("6", Marshal.dump(ActiveRoad::OsmPbfImporterLevelDb::Node.new("6", 1.0, 1.0, "", [complex_way.id, "3"] )) )
185
+ subject_without_data.nodes_database.put("7", Marshal.dump(ActiveRoad::OsmPbfImporterLevelDb::Node.new("7", 1.0, 2.0, "", [complex_way.id] )) )
186
+ subject_without_data.nodes_database.put("8", Marshal.dump(ActiveRoad::OsmPbfImporterLevelDb::Node.new("8", 1.0, 3.0, "", [complex_way.id], true)) )
187
+ end
188
+
189
+ after :each do
190
+ subject_without_data.nodes_database.delete("1")
191
+ subject_without_data.nodes_database.delete("2")
192
+ subject_without_data.nodes_database.delete("3")
193
+ subject_without_data.nodes_database.delete("4")
194
+ subject_without_data.nodes_database.delete("5")
195
+ subject_without_data.nodes_database.delete("6")
196
+ subject_without_data.nodes_database.delete("7")
197
+ subject_without_data.nodes_database.delete("8")
198
+ subject_without_data.close_nodes_database
199
+ end
200
+
201
+ it "should return ways splitted" do
202
+ ways_splitted = subject_without_data.split_way_with_nodes(simple_way)
203
+ expect(ways_splitted.size).to eq(2)
204
+ expect(ways_splitted.first.instance_values).to include(
205
+ "id" => "1-0",
206
+ "car"=> false,
207
+ "bike" => false,
208
+ "train" => true,
209
+ "pedestrian" => true,
210
+ "name" => "SimpleWay",
211
+ "boundary" => "",
212
+ "options" => {"first_node_id"=>"1", "last_node_id"=>"2"},
213
+ "nodes" => ["1", "2"] )
214
+ expect(ways_splitted.last.instance_values).to include( "id" => "1-1",
215
+ "car"=> false,
216
+ "bike" => false,
217
+ "train" => true,
218
+ "pedestrian" => true,
219
+ "name" => "SimpleWay",
220
+ "boundary" => "",
221
+ "options" => {"first_node_id"=>"2", "last_node_id"=>"3"},
222
+ "nodes" => ["2", "3"] )
223
+ end
224
+
225
+ it "should return ways not splitted" do
226
+ allow(subject_without_data).to receive_messages :split_ways => false
227
+ ways_splitted = subject_without_data.split_way_with_nodes(simple_way)
228
+ expect(ways_splitted.size).to eq(1)
229
+ expect(ways_splitted.first.instance_values).to include(
230
+ "id" => "1-0",
231
+ "car"=> false,
232
+ "bike" => false,
233
+ "train" => true,
234
+ "pedestrian" => true,
235
+ "name" => "SimpleWay",
236
+ "boundary" => "",
237
+ "options" => { "first_node_id"=>"1", "last_node_id"=>"3" },
238
+ "nodes" => ["1", "2", "3"] )
239
+ end
240
+
241
+ end
242
+
243
+ describe "#split_way_with_boundaries" do
244
+ let!(:boundary) { create(:boundary, :geometry => multi_polygon( [ polygon( point(0,0), point(2,0), point(2,2), point(0,2), point(0,0) ) ] ) ) }
245
+ let!(:boundary2) { create(:boundary, :geometry => multi_polygon( [ polygon( point(0,2), point(2,2), point(2,4), point(0,4) ) ] ) ) }
246
+
247
+ it "should split way in three parts" do
248
+ physical_road = create(:physical_road, :geometry => line_string("-1.0 1.0, 1.0 1.0, 1.0 2.0, 1.0 3.0"), :boundary_id => nil, :tags => {"bridge" => "true", "first_node_id" => "1", "last_node_id" => "2"})
249
+ departure = create(:junction, :geometry => point(-1.0, 1.0))
250
+ arrival = create(:junction, :geometry => point(1.0, 3.0))
251
+ physical_road.junctions << [departure, arrival]
252
+
253
+ subject_without_data.split_way_with_boundaries
254
+ expect(ActiveRoad::PhysicalRoad.all.size).to eq(3)
255
+ expect(ActiveRoad::PhysicalRoad.all.collect(&:objectid)).to match_array(["#{physical_road.objectid}-0", "#{physical_road.objectid}-1", "#{physical_road.objectid}-2"])
256
+
257
+ expect(ActiveRoad::Junction.all.size).to eq(4)
258
+ expect(ActiveRoad::Junction.all.collect(&:objectid)).to match_array(["#{departure.objectid}", "#{departure.objectid}-#{arrival.objectid}-0", "#{departure.objectid}-#{arrival.objectid}-1", "#{arrival.objectid}"])
259
+
260
+ expect(ActiveRoad::PhysicalRoad.all.collect(&:boundary_id)).to match_array([nil, boundary.id, boundary2.id])
261
+ expect(ActiveRoad::PhysicalRoad.all.collect(&:tags)).to match_array( [{"bridge"=>"true", "last_node_id"=>"#{departure.objectid}-#{arrival.objectid}-0", "first_node_id"=>"#{departure.objectid}"}, {"bridge"=>"true", "last_node_id"=>"#{departure.objectid}-#{arrival.objectid}-1", "first_node_id"=>"#{departure.objectid}-#{arrival.objectid}-0"}, {"bridge"=>"true", "last_node_id"=>"#{arrival.objectid}", "first_node_id"=>"#{departure.objectid}-#{arrival.objectid}-1"}] )
262
+
263
+ end
264
+
265
+ # Split intersection between segment on perimeter and segment in boundary
266
+ it "should treat geometry differences with multi linestring" do
267
+ physical_road = create(:physical_road, :geometry => line_string("-1.0 1.0, 1.0 1.0, 1.0 2.0, -1.0 2.0"), :boundary_id => nil)
268
+ departure = create(:junction, :geometry => point(-1.0, 1.0))
269
+ arrival = create(:junction, :geometry => point(-1.0, 2.0))
270
+ physical_road.junctions << [departure, arrival]
271
+
272
+ subject_without_data.split_way_with_boundaries
273
+ expect(ActiveRoad::PhysicalRoad.all.size).to eq(4)
274
+ end
275
+
276
+ it "should update boundary_id" do
277
+ physical_road = create(:physical_road, :geometry => line_string("0.0 1.0,1.0 1.0"), :boundary_id => nil)
278
+ departure = create(:junction, :geometry => point(0.0, 1.0))
279
+ arrival = create(:junction, :geometry => point(1.0, 1.0))
280
+ physical_road.junctions << [departure, arrival]
281
+
282
+ subject_without_data.split_way_with_boundaries
283
+ expect(ActiveRoad::PhysicalRoad.all.size).to eq(1)
284
+ expect(ActiveRoad::PhysicalRoad.all.collect(&:boundary_id)).to match_array([boundary.id])
285
+ end
286
+
287
+ # it "should return ways splitted with boundary" do
288
+ # boundary = create(:boundary, :geometry => multi_polygon( [ polygon( point(0,0), point(2,0), point(2,2), point(0,2) ) ] ) )
289
+ # boundary2 = create(:boundary, :geometry => multi_polygon( [ polygon( point(0,2), point(2,2), point(2,4), point(0,4) ) ] ) )
290
+ # expect(subject_without_data.split_way_with_nodes(complex_way_boundary)).to match_array( [{:objectid=>"2-0", :car=>false, :bike=>false, :train=>true, :pedestrian=>true, :name=>"", :length_in_meter=>111302.53586533663, :geometry=>line_string("-1.0 1.0,0.0 1.0"), :boundary_id=>nil, :tags=>{}, :conditionnal_costs=>[["car", 1.7976931348623157e+308], ["bike", 1.7976931348623157e+308]], :junctions=>["4", "5"]},
291
+ # {:objectid=>"2-1", :car=>false, :bike=>false, :train=>true, :pedestrian=>true, :name=>"", :length_in_meter=>111319.4907932736, :geometry=>line_string("0.0 1.0,1.0 1.0"), :boundary_id=>boundary.id, :tags=>{}, :conditionnal_costs=>[["car", 1.7976931348623157e+308], ["bike", 1.7976931348623157e+308]], :junctions=>["5", "6-8-0"]},
292
+ # {:objectid=>"2-2", :car=>false, :bike=>false, :train=>true, :pedestrian=>true, :name=>"", :length_in_meter=>111319.49079327364, :geometry=>line_string("1.0 2.0,1.0 3.0"), :boundary_id=>boundary2.id, :tags=>{}, :conditionnal_costs=>[["car", 1.7976931348623157e+308], ["bike", 1.7976931348623157e+308]], :junctions=>["6-8-0", "6-8-1"]}] )
293
+ # end
294
+
295
+ end
296
+
297
+ describe "#import" do
298
+
299
+ it "should import all datas when split" do
300
+ subject.import
301
+ expect(ActiveRoad::Junction.all.size).to eq(6)
302
+ expect(ActiveRoad::Junction.all.collect(&:objectid)).to match_array(["1", "2", "5", "8", "9", "10"])
303
+ expect(ActiveRoad::StreetNumber.all.size).to eq(4)
304
+ expect(ActiveRoad::StreetNumber.all.collect(&:objectid)).to match_array(["2646260105", "2646260106", "76809952", "2"])
305
+ expect(ActiveRoad::PhysicalRoad.all.size).to eq(8)
306
+ expect(ActiveRoad::PhysicalRoad.all.collect(&:objectid)).to match_array(["3-0", "3-1", "5-0", "5-1", "5-2", "6-0", "6-1", "6-2"])
307
+ expect(ActiveRoad::PhysicalRoadConditionnalCost.all.size).to eq(24)
308
+ expect(ActiveRoad::Boundary.all.size).to eq(1)
309
+ expect(ActiveRoad::Boundary.all.collect(&:objectid)).to match_array(["73464"])
310
+ expect(ActiveRoad::LogicalRoad.all.size).to eq(2)
311
+ expect(ActiveRoad::LogicalRoad.all.collect(&:name)).to match_array(["Rue J. Symphorien", nil])
312
+ expect(ActiveRoad::JunctionsPhysicalRoad.all.size).to eq(16)
313
+ end
314
+
315
+ it "should import only ways, nodes and street number when no split" do
316
+ subject_without_split.import
317
+ expect(ActiveRoad::Junction.all.size).to eq(6)
318
+ expect(ActiveRoad::Junction.all.collect(&:objectid)).to match_array(["1", "2", "5", "8", "9", "10"])
319
+ expect(ActiveRoad::StreetNumber.all.size).to eq(4)
320
+ expect(ActiveRoad::StreetNumber.all.collect(&:objectid)).to match_array(["2646260105", "2646260106", "76809952", "2"])
321
+ expect(ActiveRoad::PhysicalRoad.all.size).to eq(3)
322
+ expect(ActiveRoad::PhysicalRoad.all.collect(&:objectid)).to match_array(["3-0", "5-0", "6-0"])
323
+ expect(ActiveRoad::PhysicalRoadConditionnalCost.all.size).to eq(9)
324
+ expect(ActiveRoad::JunctionsPhysicalRoad.all.size).to eq(11)
325
+ expect(ActiveRoad::Boundary.all.size).to eq(0)
326
+ expect(ActiveRoad::LogicalRoad.all.size).to eq(0)
327
+ end
328
+ end
329
+
330
+ describe "#backup_relations_pgsql" do
331
+
332
+ before :each do
333
+ subject.nodes_database
334
+ subject.ways_database
335
+
336
+ subject.backup_nodes
337
+ subject.backup_ways
338
+ end
339
+
340
+ after :each do
341
+ subject.close_nodes_database
342
+ subject.delete_nodes_database
343
+ subject.close_ways_database
344
+ subject.delete_ways_database
345
+ end
346
+
347
+ it "should backup boundary" do
348
+ subject.backup_relations_pgsql
349
+ expect(ActiveRoad::Boundary.all.size).to eq(1)
350
+ expect(ActiveRoad::Boundary.first.objectid).to eq("73464")
351
+ expect(ActiveRoad::Boundary.first.geometry).to eq(multi_polygon( [ polygon( point(-54.3, 5.3), point(-54.3, 5.4), point(-54.1, 5.4), point(-54.1, 5.3), point(-54.3, 5.3) ) ] ))
352
+ end
353
+
354
+ # it "should order ways geometry" do
355
+ # let(:first) { line_string( "0 0,1 1" ) }
356
+ # let(:second) { line_string( "2 2,1 1" ) }
357
+ # let(:second_ordered) { line_string( "2 2,1 1" ) }
358
+ # let(:third) { line_string( "2 2,3 3" ) }
359
+ # expect(subject.order_ways_geometry( [first, second, last] )).to match_array( [first, second_ordered, third] )
360
+ # end
361
+
362
+ end
363
+
364
+ describe "#backup_logical_roads_pgsql" do
365
+ let!(:boundary) { create(:boundary) }
366
+
367
+ it "should not create a logical road if physical road has no boundary" do
368
+ physical_road = create(:physical_road, :boundary_id => nil)
369
+ subject.backup_logical_roads_pgsql
370
+ expect(ActiveRoad::LogicalRoad.all.size).to eq(0)
371
+ expect(ActiveRoad::PhysicalRoad.all.collect(&:logical_road_id)).to match_array([nil])
372
+ end
373
+
374
+ it "should create a logical road with no name and a boundary if physical road has no name but a boundary" do
375
+ physical_road = create(:physical_road, :boundary_id => boundary.id)
376
+ subject.backup_logical_roads_pgsql
377
+ expect(ActiveRoad::LogicalRoad.all.size).to eq(1)
378
+ expect(ActiveRoad::LogicalRoad.first.attributes).to include( "boundary_id" => boundary.id )
379
+ expect(ActiveRoad::PhysicalRoad.all.collect(&:logical_road_id)).to match_array(ActiveRoad::LogicalRoad.all.collect(&:id))
380
+ end
381
+
382
+ it "should create a logical road with no name and a boundary if physical roads has no name but a boundary" do
383
+ physical_road = create(:physical_road, :boundary_id => boundary.id)
384
+ physical_road2 = create(:physical_road, :boundary_id => boundary.id)
385
+ subject.backup_logical_roads_pgsql
386
+ expect(ActiveRoad::LogicalRoad.all.size).to eq(1)
387
+ expect(ActiveRoad::LogicalRoad.first.attributes).to include( "boundary_id" => boundary.id )
388
+ expect(ActiveRoad::PhysicalRoad.all.collect(&:logical_road_id)).to match_array([ActiveRoad::LogicalRoad.first.id, ActiveRoad::LogicalRoad.first.id])
389
+ end
390
+
391
+ it "should create a logical road with a name and a boundary if physical road has a name and a boundary" do
392
+ physical_road = create(:physical_road, :boundary_id => boundary.id, :name => "Test")
393
+ subject.backup_logical_roads_pgsql
394
+ expect(ActiveRoad::LogicalRoad.all.size).to eq(1)
395
+ expect(ActiveRoad::LogicalRoad.first.attributes).to include( "boundary_id" => boundary.id, "name" => "Test" )
396
+ expect(ActiveRoad::PhysicalRoad.all.collect(&:logical_road_id)).to match_array([ActiveRoad::LogicalRoad.first.id])
397
+ end
398
+
399
+ it "should create one logical road with a name and a boundary if physical roads have same name and a boundary" do
400
+ physical_road = create(:physical_road, :boundary_id => boundary.id, :name => "Test")
401
+ physical_road = create(:physical_road, :boundary_id => boundary.id, :name => "Test")
402
+ subject.backup_logical_roads_pgsql
403
+ expect(ActiveRoad::LogicalRoad.all.size).to eq(1)
404
+ expect(ActiveRoad::LogicalRoad.first.attributes).to include( "boundary_id" => boundary.id, "name" => "Test" )
405
+ expect(ActiveRoad::PhysicalRoad.all.collect(&:logical_road_id)).to match_array([ActiveRoad::LogicalRoad.first.id, ActiveRoad::LogicalRoad.first.id])
406
+ end
407
+
408
+ end
409
+
410
+ end