active_road 0.0.2
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.
- data/.gitignore +9 -0
- data/.rvmrc +1 -0
- data/.travis.yml +11 -0
- data/Gemfile +14 -0
- data/Guardfile +26 -0
- data/LICENSE.txt +19 -0
- data/README.md +37 -0
- data/Rakefile +46 -0
- data/active_road.gemspec +38 -0
- data/app/models/active_road/access_link.rb +44 -0
- data/app/models/active_road/access_point.rb +65 -0
- data/app/models/active_road/base.rb +5 -0
- data/app/models/active_road/junction.rb +52 -0
- data/app/models/active_road/junction_conditionnal_cost.rb +13 -0
- data/app/models/active_road/logical_road.rb +41 -0
- data/app/models/active_road/path.rb +85 -0
- data/app/models/active_road/physical_road.rb +65 -0
- data/app/models/active_road/physical_road_conditionnal_cost.rb +10 -0
- data/app/models/active_road/physical_road_filter.rb +41 -0
- data/app/models/active_road/street_number.rb +81 -0
- data/app/models/active_road/terra_import.rb +148 -0
- data/config/database.yml +20 -0
- data/config/database.yml.ci +12 -0
- data/config/routes.rb +2 -0
- data/db/init.sql +6 -0
- data/db/migrate/20110914160756_create_street_numbers.rb +18 -0
- data/db/migrate/20120201114800_create_physical_roads.rb +17 -0
- data/db/migrate/20120201162800_create_logical_roads.rb +16 -0
- data/db/migrate/20120203154500_create_junctions.rb +25 -0
- data/db/migrate/20120401083409_create_physical_roads_spatial_index.rb +9 -0
- data/db/migrate/20120419093427_add_kind_to_physical_roads.rb +10 -0
- data/db/migrate/20121010125851_create_junction_conditionnal_costs.rb +13 -0
- data/db/migrate/20121011124923_create_physical_road_conditionnal_costs.rb +13 -0
- data/db/migrate/20121012134251_add_start_end_ref_to_junction_conditionnal_cost.rb +6 -0
- data/db/migrate/20121012134440_add_tags_junction.rb +5 -0
- data/db/migrate/20121012134457_add_tags_physical_road.rb +5 -0
- data/db/migrate/20121106095002_add_objectid_to_street_number.rb +5 -0
- data/db/migrate/20130419155438_add_length_and_minimum_width_to_physical_road.rb +6 -0
- data/db/migrate/20130507162801_setup_hstore.rb +9 -0
- data/db/migrate/20130509075631_change_tags_type_for_physical_road.rb +10 -0
- data/db/migrate/20130509081745_index_physical_roads_tags.rb +9 -0
- data/db/migrate/20130513134422_change_tags_type_for_junction.rb +10 -0
- data/db/migrate/20130513134511_index_junctions_tags.rb +9 -0
- data/db/migrate/20130607114951_change_length_name_for_physical_road.rb +11 -0
- data/db/migrate/20130801151637_add_constraints_to_physical_roads.rb +37 -0
- data/db/migrate/20130809155019_add_height_and_waiting_constraint_to_junction.rb +6 -0
- data/db/migrate/20130812143049_fix_waiting_constraint_type_for_junction.rb +11 -0
- data/lib/active_road.rb +19 -0
- data/lib/active_road/engine.rb +13 -0
- data/lib/active_road/migration.rb +15 -0
- data/lib/active_road/shortest_path.rb +2 -0
- data/lib/active_road/shortest_path/finder.rb +172 -0
- data/lib/active_road/version.rb +3 -0
- data/lib/tasks/activeroad_tasks.rake +4 -0
- data/log/.gitignore +0 -0
- data/script/console +2 -0
- data/script/import-tiger-numbers +201 -0
- data/script/rails +9 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +56 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +20 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/db/schema.rb +87 -0
- data/spec/dummy/db/structure.sql +10250 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories/junction.rb +18 -0
- data/spec/factories/junction_conditionnal_cost.rb +13 -0
- data/spec/factories/logical_road.rb +8 -0
- data/spec/factories/physical_road.rb +9 -0
- data/spec/factories/physical_road_conditionnal_cost.rb +9 -0
- data/spec/factories/street_number.rb +11 -0
- data/spec/fixtures/terra.xml +1772 -0
- data/spec/fixtures/terra_minimal.xml +28 -0
- data/spec/fixtures/trajectory_arc.xml +10 -0
- data/spec/fixtures/trajectory_node.xml +11 -0
- data/spec/lib/active_road/shortest_path/finder_spec.rb +157 -0
- data/spec/models/active_road/access_point_spec.rb +36 -0
- data/spec/models/active_road/junction_conditionnal_cost_spec.rb +28 -0
- data/spec/models/active_road/junction_spec.rb +25 -0
- data/spec/models/active_road/logical_road_spec.rb +46 -0
- data/spec/models/active_road/path_spec.rb +7 -0
- data/spec/models/active_road/physical_road_conditionnal_cost_spec.rb +19 -0
- data/spec/models/active_road/physical_road_filter_spec.rb +85 -0
- data/spec/models/active_road/physical_road_spec.rb +17 -0
- data/spec/models/active_road/street_number_spec.rb +78 -0
- data/spec/models/active_road/terra_import_spec.rb +113 -0
- data/spec/spec_helper.rb +46 -0
- data/spec/support/georuby_ext.rb +15 -0
- data/travis/before_install.sh +10 -0
- data/travis/before_script.sh +9 -0
- metadata +460 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<?xml version="1.0"?>
|
|
2
|
+
<?xml-stylesheet type="text/xsl" href="roads-exchange.xsl"?>
|
|
3
|
+
<Referential xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:./roads-exchange-SP4-SP5.xsd" name="Place Saint Sulpice septembre 2012">
|
|
4
|
+
<TrajectoryNode>
|
|
5
|
+
<ObjectId>ign-obj-55</ObjectId>
|
|
6
|
+
<Tags></Tags>
|
|
7
|
+
<Geometry>SRID=4326;POINT(2.331308046501452 48.85192725813857)</Geometry>
|
|
8
|
+
<TrajectoryArcRef>ign-obj-205</TrajectoryArcRef>
|
|
9
|
+
<PhysicalRoadRef>ign-obj-4</PhysicalRoadRef>
|
|
10
|
+
</TrajectoryNode>
|
|
11
|
+
<TrajectoryNode>
|
|
12
|
+
<ObjectId>ign-obj-56</ObjectId>
|
|
13
|
+
<Tags></Tags>
|
|
14
|
+
<Geometry>SRID=4326;POINT(2.331308046501452 48.89192725813857)</Geometry>
|
|
15
|
+
<TrajectoryArcRef>ign-obj-205</TrajectoryArcRef>
|
|
16
|
+
<PhysicalRoadRef>ign-obj-4</PhysicalRoadRef>
|
|
17
|
+
</TrajectoryNode>
|
|
18
|
+
<TrajectoryArc>
|
|
19
|
+
<ObjectId>ign-obj-205</ObjectId>
|
|
20
|
+
<Tags></Tags>
|
|
21
|
+
<Geometry>SRID=4326;LINESTRING(2.331800215057413 48.85220542836662, 2.331637521069522 48.85226948829244)</Geometry>
|
|
22
|
+
<TrajectoryNodeRef>ign-obj-55</TrajectoryNodeRef>
|
|
23
|
+
<TrajectoryNodeRef>ign-obj-56</TrajectoryNodeRef>
|
|
24
|
+
<PhysicalRoadRef>ign-obj-8</PhysicalRoadRef>
|
|
25
|
+
<Length>13.90200574121281</Length>
|
|
26
|
+
<MinimumWidth>1.934781931678176</MinimumWidth>
|
|
27
|
+
</TrajectoryArc>
|
|
28
|
+
</Referential>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<TrajectoryArc>
|
|
2
|
+
<ObjectId>ign-obj-132</ObjectId>
|
|
3
|
+
<Tags></Tags>
|
|
4
|
+
<Geometry>SRID=4326;LINESTRING(2.332951894607378 48.85202237268847, 2.332954059651963 48.85203176810643, 2.332987498916577 48.85217930000868, 2.333012216929252 48.85228653406593, 2.333019156716375 48.85231664083499, 2.333020631447154 48.85232307844341, 2.333054110912616 48.85246483593746, 2.333054409771297 48.85246610837084, 2.333069582167015 48.85253004267233, 2.333069181836508 48.85253081856987, 2.333061780607442 48.85254114991605, 2.333052671610163 48.85254999057511, 2.333027875983071 48.85257017716946, 2.333027422653056 48.85257048008516)</Geometry>
|
|
5
|
+
<TrajectoryNodeRef>ign-obj-43</TrajectoryNodeRef>
|
|
6
|
+
<TrajectoryNodeRef>ign-obj-92</TrajectoryNodeRef>
|
|
7
|
+
<PhysicalRoadRef>ign-obj-14</PhysicalRoadRef>
|
|
8
|
+
<Length>62.59449394845691</Length>
|
|
9
|
+
<MinimumWidth>wide</MinimumWidth>
|
|
10
|
+
</TrajectoryArc>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<TrajectoryNode>
|
|
2
|
+
<ObjectId>ign-obj-93</ObjectId>
|
|
3
|
+
<Tags></Tags>
|
|
4
|
+
<Geometry>SRID=4326;POINT(2.33280726637185 48.85139664547131)</Geometry>
|
|
5
|
+
<TrajectoryArcRef>ign-obj-158</TrajectoryArcRef>
|
|
6
|
+
<TrajectoryArcRef>ign-obj-187</TrajectoryArcRef>
|
|
7
|
+
<JunctionRef>ign-obj-111</JunctionRef>
|
|
8
|
+
<PhysicalRoadRef>ign-obj-13</PhysicalRoadRef>
|
|
9
|
+
<PhysicalRoadRef>ign-obj-14</PhysicalRoadRef>
|
|
10
|
+
<Height>5</Height>
|
|
11
|
+
</TrajectoryNode>
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe ActiveRoad::ShortestPath::Finder do
|
|
4
|
+
|
|
5
|
+
# Path schema
|
|
6
|
+
#
|
|
7
|
+
# E-----------------F
|
|
8
|
+
# | _______________/|
|
|
9
|
+
# |/ |
|
|
10
|
+
# C-----------------D
|
|
11
|
+
# | |
|
|
12
|
+
# | |
|
|
13
|
+
# A-----------------B
|
|
14
|
+
#
|
|
15
|
+
|
|
16
|
+
let(:departure) { point(-0.1, 0.1) }
|
|
17
|
+
let(:arrival) { point(1, 2) }
|
|
18
|
+
let(:speed) { 4 }
|
|
19
|
+
let(:constraints) { {:transport_mode => [:pedestrian, nil]} }
|
|
20
|
+
|
|
21
|
+
let(:ab) { create(:physical_road, :objectid => "ab", :geometry => line_string( "0 0,1 0" ) ) }
|
|
22
|
+
let(:cd) { create(:physical_road, :objectid => "cd", :geometry => line_string( "0 1,1 1" ) ) }
|
|
23
|
+
let(:ef) { create(:physical_road, :objectid => "ef", :geometry => line_string( "0 2,1 2" ) ) }
|
|
24
|
+
let(:ac) { create(:physical_road, :objectid => "ac", :geometry => line_string( "0 0,0 1" ), :uphill => 2 ) }
|
|
25
|
+
let(:bd) { create(:physical_road, :objectid => "bd", :geometry => line_string( "1 0,1 1" ) ) }
|
|
26
|
+
let(:ce) { create(:physical_road, :objectid => "ce", :geometry => line_string( "0 1,0 2" ), :uphill => 2 ) }
|
|
27
|
+
let(:df) { create(:physical_road, :objectid => "df", :geometry => line_string( "1 1,1 2" ) ) }
|
|
28
|
+
let(:cf) { create(:physical_road, :objectid => "cf", :geometry => line_string( "0 1,1 2" ), :transport_mode => :bike, :uphill => 2 ) }
|
|
29
|
+
|
|
30
|
+
let!(:a) { create(:junction, :geometry => point(0, 0), :physical_roads => [ ab, ac ] ) }
|
|
31
|
+
let!(:b) { create(:junction, :geometry => point(1, 0), :physical_roads => [ ab, bd ] ) }
|
|
32
|
+
let!(:c) { create(:junction, :geometry => point(0, 1), :physical_roads => [ cd, ac, ce, cf ] ) }
|
|
33
|
+
let!(:d) { create(:junction, :geometry => point(1, 1), :physical_roads => [ cd, bd, df ] ) }
|
|
34
|
+
let!(:e) { create(:junction, :geometry => point(0, 2), :physical_roads => [ ce, ef ] ) }
|
|
35
|
+
let!(:f) { create(:junction, :geometry => point(1, 2), :physical_roads => [ ef, df, cf ] ) }
|
|
36
|
+
|
|
37
|
+
it "should find a solution between first and last road with with no constraints" do
|
|
38
|
+
subject = ActiveRoad::ShortestPath::Finder.new departure, arrival, 4
|
|
39
|
+
subject.path.should_not be_blank
|
|
40
|
+
subject.path.size.should == 6
|
|
41
|
+
subject.path[2].physical_road.objectid.should == "ac"
|
|
42
|
+
subject.path[3].physical_road.objectid.should == "cf"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "should find a solution between first and last road with physical_road filter in constraints" do
|
|
46
|
+
subject = ActiveRoad::ShortestPath::Finder.new departure, arrival, 4, constraints
|
|
47
|
+
subject.path.should_not be_blank
|
|
48
|
+
subject.path.size.should == 7
|
|
49
|
+
subject.path[2].physical_road.objectid.should == "ac"
|
|
50
|
+
subject.path[3].physical_road.objectid.should == "ce"
|
|
51
|
+
subject.path[4].physical_road.objectid.should == "ef"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "should find a solution between first and last road with context arguments in constraints" do
|
|
55
|
+
subject = ActiveRoad::ShortestPath::Finder.new departure, arrival, 4, { :uphill => 3 }
|
|
56
|
+
subject.path.should_not be_blank
|
|
57
|
+
subject.path.size.should == 7
|
|
58
|
+
subject.path[2].physical_road.objectid.should == "ac"
|
|
59
|
+
subject.path[3].physical_road.objectid.should == "cd"
|
|
60
|
+
subject.path[4].physical_road.objectid.should == "df"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "should return something when no solution" do
|
|
64
|
+
subject = ActiveRoad::ShortestPath::Finder.new departure, arrival, 4, constraints
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# describe "Shortest path with weights" do
|
|
69
|
+
|
|
70
|
+
# it "should find a solution between first and last road with weights" do
|
|
71
|
+
# subject = ActiveRoad::ShortestPath::Finder.new source, destination, 4
|
|
72
|
+
# subject.path.should_not be_blank
|
|
73
|
+
# subject.path.size.should == 7
|
|
74
|
+
# subject.path[3].physical_road.objectid.should == "bc"
|
|
75
|
+
# subject.path[4].physical_road.objectid.should == "cd"
|
|
76
|
+
# end
|
|
77
|
+
|
|
78
|
+
# end
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
describe "#path_weights" do
|
|
82
|
+
|
|
83
|
+
let(:subject) { ActiveRoad::ShortestPath::Finder.new departure, arrival, 4 }
|
|
84
|
+
|
|
85
|
+
it "should return 0 if no physical road" do
|
|
86
|
+
path = departure
|
|
87
|
+
subject.path_weights(path).should == 0
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "should return path weights" do
|
|
91
|
+
path = ActiveRoad::Path.new(:departure => create(:junction), :physical_road => create(:physical_road) )
|
|
92
|
+
path.stub :length_in_meter => 2
|
|
93
|
+
subject.path_weights(path).should == 2 / (4 * 1000/3600)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it "should return path weights and node weight" do
|
|
97
|
+
path = ActiveRoad::Path.new(:departure => create(:junction, :waiting_constraint => 2.5), :physical_road => create(:physical_road) )
|
|
98
|
+
path.stub :length_in_meter => 2
|
|
99
|
+
subject.path_weights(path).should == 2 / (4 * 1000/3600) + 2.5
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
describe "#refresh_context" do
|
|
105
|
+
let(:subject) { ActiveRoad::ShortestPath::Finder.new departure, arrival, 4 }
|
|
106
|
+
|
|
107
|
+
it "should increase uphill if path has got a departure with an uphill value" do
|
|
108
|
+
node = ActiveRoad::Path.new( :physical_road => create(:physical_road, :uphill => 3.0), :departure => create(:junction))
|
|
109
|
+
context = {:uphill => 3}
|
|
110
|
+
subject.refresh_context(node, context).should == { :uphill => 6.0, :downhill => 0, :height => 0}
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "should not increase uphill if path hasn't' got a departure with an uphill value" do
|
|
114
|
+
node = ActiveRoad::Path.new( :physical_road => create(:physical_road), :departure => create(:junction))
|
|
115
|
+
context = {:uphill => 3}
|
|
116
|
+
subject.refresh_context(node, context).should == { :uphill => 3.0, :downhill => 0, :height => 0}
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it "should set context uphill to 0 if path hasn't' got a departure with an uphill value and no previous context" do
|
|
120
|
+
node = ActiveRoad::Path.new( :physical_road => create(:physical_road), :departure => create(:junction))
|
|
121
|
+
context = {}
|
|
122
|
+
subject.refresh_context(node, context).should == { :uphill => 0, :downhill => 0, :height => 0}
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it "should return {} if node is not a ActiveRoad::Path" do
|
|
126
|
+
node = GeoRuby::SimpleFeatures::Point.from_x_y(0, 0)
|
|
127
|
+
context = {}
|
|
128
|
+
subject.refresh_context(node, context).should == {:uphill=>0, :downhill=>0, :height=>0}
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
describe "#follow_way" do
|
|
133
|
+
|
|
134
|
+
let(:node) { mock(:node) }
|
|
135
|
+
let(:destination) { mock(:destination) }
|
|
136
|
+
let(:weight) { 2 }
|
|
137
|
+
let(:context) { {:uphill => 2} }
|
|
138
|
+
let(:subject) { ActiveRoad::ShortestPath::Finder.new departure, arrival, 4 }
|
|
139
|
+
|
|
140
|
+
before(:each) do
|
|
141
|
+
subject.stub :search_heuristic => 1
|
|
142
|
+
subject.stub :time_heuristic => 2
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
it "should not follow way if uphill > uphill max" do
|
|
146
|
+
subject.follow_way_filter = {:uphill => 1}
|
|
147
|
+
subject.follow_way?(node, destination, weight, context).should be_false
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
it "should follow way if uphill < uphill max" do
|
|
151
|
+
subject.follow_way_filter = {:uphill => 3}
|
|
152
|
+
subject.follow_way?(node, destination, weight, context).should be_true
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe ActiveRoad::AccessPoint do
|
|
4
|
+
let!(:ab) { create(:physical_road, :geometry => line_string( "0 0,1 0" ), :minimum_width => :wide ) }
|
|
5
|
+
|
|
6
|
+
subject { ActiveRoad::Accesspoint.new( :location => point(0, 0), :physical_road => ab ) }
|
|
7
|
+
|
|
8
|
+
describe ".from" do
|
|
9
|
+
|
|
10
|
+
it "should return all access point with tags from the location" do
|
|
11
|
+
access_points = ActiveRoad::AccessPoint.from( point(0, 0), { :minimum_width => :wide } )
|
|
12
|
+
access_points.size.should == 1
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should return all access point from the location with tags not in physical roads" do
|
|
16
|
+
access_points = ActiveRoad::AccessPoint.from( point(0, 0), { :minimum_width => :narrow } )
|
|
17
|
+
access_points.size.should == 0
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe ".to" do
|
|
23
|
+
|
|
24
|
+
it "should return all access point with tags from the location" do
|
|
25
|
+
access_points = ActiveRoad::AccessPoint.to( point(0, 0), { :minimum_width => :wide } )
|
|
26
|
+
access_points.size.should == 1
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should return all access point from the location with tags not in physical roads" do
|
|
30
|
+
access_points = ActiveRoad::AccessPoint.to( point(0, 0), { :minimum_width => :narrow } )
|
|
31
|
+
access_points.size.should == 0
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe ActiveRoad::JunctionConditionnalCost do
|
|
4
|
+
|
|
5
|
+
subject { create(:junction_conditionnal_cost) }
|
|
6
|
+
|
|
7
|
+
it "should have tags" do
|
|
8
|
+
subject.should respond_to(:tags)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should have a cost" do
|
|
12
|
+
subject.should respond_to(:cost)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should have a junction" do
|
|
16
|
+
subject.should respond_to(:junction_id)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe "#start_physical_road" do
|
|
20
|
+
let(:new_road){create(:physical_road)}
|
|
21
|
+
it "should belongs to physical_road" do
|
|
22
|
+
subject.update_attributes( :start_physical_road => new_road)
|
|
23
|
+
subject.reload
|
|
24
|
+
subject.start_physical_road_id = new_road.id
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe ActiveRoad::Junction do
|
|
4
|
+
|
|
5
|
+
subject { create(:junction) }
|
|
6
|
+
|
|
7
|
+
it "should validate objectid uniqueness" do
|
|
8
|
+
other = build :junction, :objectid => subject.objectid
|
|
9
|
+
other.should_not be_valid
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
context "junction connected to physical roads" do
|
|
13
|
+
subject { create(:junction) }
|
|
14
|
+
|
|
15
|
+
describe "#physical_roads" do
|
|
16
|
+
let(:new_road) { create(:physical_road) }
|
|
17
|
+
it "should be addable" do
|
|
18
|
+
subject.physical_roads << new_road
|
|
19
|
+
subject.save!
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe ActiveRoad::LogicalRoad do
|
|
4
|
+
|
|
5
|
+
subject { create(:logical_road) }
|
|
6
|
+
|
|
7
|
+
it "should have a name" do
|
|
8
|
+
subject.should respond_to(:name)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe "at" do
|
|
12
|
+
|
|
13
|
+
context "when the given number exists" do
|
|
14
|
+
|
|
15
|
+
#let(:physical_road) { create :physical_road, :logical_road => subject }
|
|
16
|
+
#let(:number) { create :street_number, :physical_road => physical_road }
|
|
17
|
+
|
|
18
|
+
it "should return the number geometry" do
|
|
19
|
+
#subject.at(number.number).should == number.geometry
|
|
20
|
+
subject.name.should_not be_nil
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context "when the given number is between two existing numbers" do
|
|
26
|
+
|
|
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
|
|
35
|
+
|
|
36
|
+
# let(:estimated_geometry) { subject.geometry.interpolate_point(0.75) }
|
|
37
|
+
|
|
38
|
+
# it "should return the estimated geometry" do
|
|
39
|
+
# subject.at(number).should == estimated_geometry
|
|
40
|
+
# end
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe ActiveRoad::PhysicalRoadConditionnalCost do
|
|
4
|
+
|
|
5
|
+
subject { create(:physical_road_conditionnal_cost) }
|
|
6
|
+
|
|
7
|
+
it "should have tags" do
|
|
8
|
+
subject.should respond_to(:tags)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should have a cost" do
|
|
12
|
+
subject.should respond_to(:cost)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should have a physical road" do
|
|
16
|
+
subject.should respond_to(:physical_road_id)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe ActiveRoad::PhysicalRoadFilter do
|
|
4
|
+
|
|
5
|
+
# describe "#sql_request" do
|
|
6
|
+
|
|
7
|
+
# it "should return sql_request with min key" do
|
|
8
|
+
# physical_road_filter = ActiveRoad::PhysicalRoadFilter.new({"min_size" => "2"})
|
|
9
|
+
# physical_road_filter.sql_request.should == "(tags -> 'size')::int > :min_size"
|
|
10
|
+
# end
|
|
11
|
+
|
|
12
|
+
# it "should return sql_request with max key" do
|
|
13
|
+
# physical_road_filter = ActiveRoad::PhysicalRoadFilter.new({"max_size" => "2"})
|
|
14
|
+
# physical_road_filter.sql_request.should == "(tags -> 'size')::int < :max_size"
|
|
15
|
+
# end
|
|
16
|
+
|
|
17
|
+
# it "should return sql_request with default key" do
|
|
18
|
+
# physical_road_filter = ActiveRoad::PhysicalRoadFilter.new({"pedestrian" => "true"})
|
|
19
|
+
# physical_road_filter.sql_request.should == "tags -> 'pedestrian' != :pedestrian"
|
|
20
|
+
# end
|
|
21
|
+
|
|
22
|
+
# it "should return sql_request with 3 parameter" do
|
|
23
|
+
# physical_road_filter = ActiveRoad::PhysicalRoadFilter.new({"pedestrian" => "true", "max_size" => "2", "min_size" => "1"})
|
|
24
|
+
# physical_road_filter.sql_request.should == "tags -> 'pedestrian' != :pedestrian AND (tags -> 'size')::int < :max_size AND (tags -> 'size')::int > :min_size"
|
|
25
|
+
# end
|
|
26
|
+
|
|
27
|
+
# end
|
|
28
|
+
|
|
29
|
+
describe "#filter" do
|
|
30
|
+
|
|
31
|
+
let!( :physical_road ) { create( :physical_road ) }
|
|
32
|
+
let!( :physical_road2 ) { create( :physical_road ) }
|
|
33
|
+
let!( :physical_road3 ) { create( :physical_road ) }
|
|
34
|
+
|
|
35
|
+
it "should return physical roads which contains minimum_width <= narrow" do
|
|
36
|
+
physical_road.update_attribute :minimum_width, :wide
|
|
37
|
+
physical_road2.update_attribute :minimum_width, :cramped
|
|
38
|
+
|
|
39
|
+
physical_road_filter = ActiveRoad::PhysicalRoadFilter.new({:minimum_width => [:wide, :enlarged, :narrow]})
|
|
40
|
+
physical_road_filter.filter.should =~ [physical_road, physical_road3]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "should return physical roads which contains slope <= medium" do
|
|
44
|
+
physical_road.update_attribute :slope, :medium
|
|
45
|
+
physical_road2.update_attribute :slope, :steep
|
|
46
|
+
|
|
47
|
+
physical_road_filter = ActiveRoad::PhysicalRoadFilter.new({:slope => [:flat, :medium] })
|
|
48
|
+
physical_road_filter.filter.should =~ [physical_road, physical_road3]
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "should return physical roads which contains cant <= medium" do
|
|
52
|
+
physical_road.update_attribute :cant, :medium
|
|
53
|
+
physical_road2.update_attribute :cant, :steep
|
|
54
|
+
|
|
55
|
+
physical_road_filter = ActiveRoad::PhysicalRoadFilter.new({:cant => [:flat, :medium] })
|
|
56
|
+
physical_road_filter.filter.should =~ [physical_road, physical_road3]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "should return physical roads which contains physical_road_type == path_link" do
|
|
60
|
+
physical_road.update_attribute :physical_road_type, :path_link
|
|
61
|
+
physical_road2.update_attribute :physical_road_type, :crossing
|
|
62
|
+
|
|
63
|
+
physical_road_filter = ActiveRoad::PhysicalRoadFilter.new({:physical_road_type => :path_link})
|
|
64
|
+
physical_road_filter.filter.should =~ [physical_road, physical_road3]
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "should return physical roads which contains transport_mode == pedestrian" do
|
|
69
|
+
physical_road.update_attribute :transport_mode, :pedestrian
|
|
70
|
+
physical_road2.update_attribute :transport_mode, :bike
|
|
71
|
+
|
|
72
|
+
physical_road_filter = ActiveRoad::PhysicalRoadFilter.new({:transport_mode => [:pedestrian, nil]})
|
|
73
|
+
physical_road_filter.filter.should =~ [physical_road, physical_road3]
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "should return physical roads which contains covering == asphalt_road or pavement" do
|
|
77
|
+
physical_road.update_attribute :covering, :asphalt_road
|
|
78
|
+
physical_road2.update_attribute :covering, :pavement
|
|
79
|
+
|
|
80
|
+
physical_road_filter = ActiveRoad::PhysicalRoadFilter.new({:covering => [:pavement, :asphalt_road, nil]})
|
|
81
|
+
physical_road_filter.filter.should =~ [physical_road, physical_road2, physical_road3]
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|