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.
- 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,41 +0,0 @@
|
|
1
|
-
# Filter Physical Road by :
|
2
|
-
# - constraints
|
3
|
-
class ActiveRoad::PhysicalRoadFilter
|
4
|
-
attr_accessor :relation, :constraints
|
5
|
-
|
6
|
-
def initialize(constraints = {}, relation = ActiveRoad::PhysicalRoad.scoped )
|
7
|
-
@relation, @constraints = relation, constraints
|
8
|
-
end
|
9
|
-
|
10
|
-
# Must define an sql request with forbidden tags
|
11
|
-
def sql_request
|
12
|
-
sql_request = ""
|
13
|
-
constraints.each do |key, value|
|
14
|
-
if !( (constraints.keys.first.present? && constraints.keys.first == key) )
|
15
|
-
sql_request += " AND "
|
16
|
-
end
|
17
|
-
|
18
|
-
sql_request += "(tags -> '#{new_key}')::int > :#{key}"
|
19
|
-
|
20
|
-
# if key.to_s.include? "min_"
|
21
|
-
# new_key = key.to_s.gsub("min_", "")
|
22
|
-
# sql_request += "(tags -> '#{new_key}')::int > :#{key}"
|
23
|
-
# elsif key.to_s.include? "max_"
|
24
|
-
# new_key = key.to_s.gsub("max_", "")
|
25
|
-
# sql_request += "(tags -> '#{new_key}')::int < :#{key}"
|
26
|
-
# else
|
27
|
-
# sql_request += "tags -> '#{key}' != :#{key}"
|
28
|
-
# end
|
29
|
-
end
|
30
|
-
sql_request
|
31
|
-
end
|
32
|
-
|
33
|
-
def filter
|
34
|
-
if constraints.present?
|
35
|
-
@relation = @relation.where(constraints)
|
36
|
-
else
|
37
|
-
@relation
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
@@ -1,148 +0,0 @@
|
|
1
|
-
module ActiveRoad
|
2
|
-
class TerraImport
|
3
|
-
attr_reader :parser
|
4
|
-
|
5
|
-
def initialize(xml_file)
|
6
|
-
@parser = ::Saxerator.parser(File.new(xml_file))
|
7
|
-
end
|
8
|
-
|
9
|
-
def extract
|
10
|
-
parser.for_tag(:LogicalRoad).each do |logical_road|
|
11
|
-
LogicalRoadXml.new(logical_road).import
|
12
|
-
end
|
13
|
-
|
14
|
-
parser.for_tag(:TrajectoryArc).each do |physical_road|
|
15
|
-
TrajectoryArcXml.new(physical_road).import
|
16
|
-
end
|
17
|
-
|
18
|
-
parser.for_tag(:TrajectoryNode).each do |junction|
|
19
|
-
TrajectoryNodeXml.new(junction).import
|
20
|
-
end
|
21
|
-
|
22
|
-
parser.for_tag(:StreetNumber).each do |street_number|
|
23
|
-
StreetNumberXml.new(street_number).import
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
class ElementXml
|
29
|
-
attr_reader :xml
|
30
|
-
|
31
|
-
def initialize(xml)
|
32
|
-
@xml = xml
|
33
|
-
end
|
34
|
-
|
35
|
-
def objectid
|
36
|
-
xml['ObjectId']
|
37
|
-
end
|
38
|
-
|
39
|
-
def geometry
|
40
|
-
GeoRuby::SimpleFeatures::Geometry.from_ewkt( xml['Geometry'] )
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
class LogicalRoadXml < ElementXml
|
46
|
-
|
47
|
-
def name
|
48
|
-
xml['Name']
|
49
|
-
end
|
50
|
-
|
51
|
-
def import
|
52
|
-
ActiveRoad::LogicalRoad.create :name => name, :objectid => objectid
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
class TrajectoryArcXml < ElementXml
|
58
|
-
|
59
|
-
def logical_road
|
60
|
-
ActiveRoad::LogicalRoad.find_by_objectid( logical_road_id )
|
61
|
-
end
|
62
|
-
|
63
|
-
def logical_road_id
|
64
|
-
xml['LogicalRoadRef']
|
65
|
-
end
|
66
|
-
|
67
|
-
def minimum_width
|
68
|
-
xml['MinimumWidth']
|
69
|
-
end
|
70
|
-
|
71
|
-
def length
|
72
|
-
xml['Length']
|
73
|
-
end
|
74
|
-
|
75
|
-
def tags
|
76
|
-
{}
|
77
|
-
end
|
78
|
-
|
79
|
-
def import
|
80
|
-
ActiveRoad::PhysicalRoad.create(:geometry => geometry, :tags => tags, :logical_road_id => logical_road_id, :objectid => objectid, :minimum_with => minimum_width, :length_in_meter => length) if (geometry) #&& logical_road)
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
class TrajectoryNodeXml < ElementXml
|
86
|
-
|
87
|
-
def tags
|
88
|
-
{} #xml['Tags'].to_s
|
89
|
-
end
|
90
|
-
|
91
|
-
# def height
|
92
|
-
# xml['Height'] || 0
|
93
|
-
# end
|
94
|
-
|
95
|
-
# def physical_road
|
96
|
-
# ActiveRoad::PhysicalRoad.find_by_objectid( physical_road_id )
|
97
|
-
# end
|
98
|
-
|
99
|
-
# def physical_road_id
|
100
|
-
# xml['PhysicalRoadRef']
|
101
|
-
# end
|
102
|
-
|
103
|
-
def physical_roads
|
104
|
-
physical_roads = []
|
105
|
-
if(xml['TrajectoryArcRef'].class == Saxerator::Builder::StringElement)
|
106
|
-
physical_roads << ActiveRoad::PhysicalRoad.find_by_objectid( xml['TrajectoryArcRef'].to_s )
|
107
|
-
else
|
108
|
-
xml['TrajectoryArcRef'].each do |trajectory_arc_ref|
|
109
|
-
physical_road = ActiveRoad::PhysicalRoad.find_by_objectid( trajectory_arc_ref.to_s )
|
110
|
-
physical_roads << physical_road if physical_road.present?
|
111
|
-
end
|
112
|
-
end
|
113
|
-
physical_roads
|
114
|
-
end
|
115
|
-
|
116
|
-
def import
|
117
|
-
junction = ActiveRoad::Junction.create :objectid => objectid, :tags => tags, :geometry => geometry
|
118
|
-
junction.physical_roads << physical_roads
|
119
|
-
end
|
120
|
-
|
121
|
-
end
|
122
|
-
|
123
|
-
class StreetNumberXml < ElementXml
|
124
|
-
# TODO : Fix location_on_road value
|
125
|
-
def physical_road
|
126
|
-
ActiveRoad::PhysicalRoad.find_by_objectid( physical_road_ref )
|
127
|
-
end
|
128
|
-
|
129
|
-
def physical_road_ref
|
130
|
-
xml['TrajectoryArcRef']
|
131
|
-
end
|
132
|
-
|
133
|
-
def number
|
134
|
-
xml['Number']
|
135
|
-
end
|
136
|
-
|
137
|
-
def location_on_road
|
138
|
-
xml['LocationOnRoad'] || 0
|
139
|
-
end
|
140
|
-
|
141
|
-
def import
|
142
|
-
ActiveRoad::StreetNumber.create(:number => number , :objectid => objectid, :geometry => geometry, :location_on_road => location_on_road)#, :physical_road_id => physical_road.id)
|
143
|
-
end
|
144
|
-
|
145
|
-
end
|
146
|
-
|
147
|
-
end
|
148
|
-
end
|
@@ -1,85 +0,0 @@
|
|
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
|
@@ -1,113 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveRoad::TerraImport do
|
4
|
-
|
5
|
-
describe "test big xml file" do
|
6
|
-
let(:xml_file) { File.expand_path("../../../fixtures/terra.xml", __FILE__) }
|
7
|
-
|
8
|
-
subject { ActiveRoad::TerraImport.new( xml_file ) }
|
9
|
-
|
10
|
-
before :each do
|
11
|
-
subject.extract
|
12
|
-
end
|
13
|
-
|
14
|
-
# it "should have import all logical roads" do
|
15
|
-
# ActiveRoad::LogicalRoad.all.size.should == 4
|
16
|
-
# end
|
17
|
-
|
18
|
-
it "should have import all physical roads" do
|
19
|
-
ActiveRoad::PhysicalRoad.all.size.should == 78
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should have import all junctions" do
|
23
|
-
ActiveRoad::Junction.all.size.should == 70
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should have import all street number" do
|
27
|
-
ActiveRoad::StreetNumber.all.size.should == 20
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "test minimal xml file" do
|
32
|
-
let(:xml_file) { File.expand_path("../../../fixtures/terra_minimal.xml", __FILE__) }
|
33
|
-
|
34
|
-
subject { ActiveRoad::TerraImport.new( xml_file ) }
|
35
|
-
|
36
|
-
before :each do
|
37
|
-
subject.extract
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should have import one physical road" do
|
41
|
-
ActiveRoad::PhysicalRoad.all.size.should == 1
|
42
|
-
|
43
|
-
physical_road = ActiveRoad::PhysicalRoad.first
|
44
|
-
|
45
|
-
physical_road.objectid.should == "ign-obj-205"
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should have import 2 junctions" do
|
49
|
-
ActiveRoad::Junction.all.size.should == 2
|
50
|
-
|
51
|
-
junction1 = ActiveRoad::Junction.first
|
52
|
-
junction2 = ActiveRoad::Junction.last
|
53
|
-
|
54
|
-
junction1.objectid.should == "ign-obj-55"
|
55
|
-
junction1.physical_roads.first.objectid.should == "ign-obj-205"
|
56
|
-
junction2.objectid.should == "ign-obj-56"
|
57
|
-
junction2.physical_roads.first.objectid.should == "ign-obj-205"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
describe ActiveRoad::TerraImport::TrajectoryNodeXml do
|
64
|
-
let(:trajectory_node_xml) { File.expand_path("../../../fixtures/trajectory_node.xml", __FILE__) }
|
65
|
-
let(:parser) { Saxerator.parser(File.new(trajectory_node_xml)) }
|
66
|
-
|
67
|
-
let(:trajectory_node) { ActiveRoad::TerraImport::TrajectoryNodeXml.new(parser.for_tag(:TrajectoryNode).first) }
|
68
|
-
|
69
|
-
it "should have an object id" do
|
70
|
-
trajectory_node.objectid.should == "ign-obj-93"
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should have tags" do
|
74
|
-
trajectory_node.tags.should == {}
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should have a geometry" do
|
78
|
-
trajectory_node.geometry.should_not be_nil
|
79
|
-
end
|
80
|
-
|
81
|
-
# it "should have an height" do
|
82
|
-
# trajectory_node.height.should == 5
|
83
|
-
# end
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
describe ActiveRoad::TerraImport::TrajectoryArcXml do
|
88
|
-
let(:trajectory_arc_xml) { File.expand_path("../../../fixtures/trajectory_arc.xml", __FILE__) }
|
89
|
-
let(:parser) { Saxerator.parser(File.new(trajectory_arc_xml)) }
|
90
|
-
|
91
|
-
let(:trajectory_arc) { ActiveRoad::TerraImport::TrajectoryArcXml.new(parser.for_tag(:TrajectoryArc).first) }
|
92
|
-
|
93
|
-
it "should have an object id" do
|
94
|
-
trajectory_arc.objectid.should == "ign-obj-132"
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should have tags" do
|
98
|
-
trajectory_arc.tags.should == {}
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should have a geometry" do
|
102
|
-
trajectory_arc.geometry.should_not be_nil
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should have a minimum width" do
|
106
|
-
trajectory_arc.minimum_width.should == "wide"
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should have a length in meter" do
|
110
|
-
trajectory_arc.length.should == "62.59449394845691"
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
data/spec/support/georuby_ext.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
def geometry_from_text(text, srid = 4326)
|
2
|
-
GeoRuby::SimpleFeatures::Geometry.from_ewkt "SRID=#{srid};#{text}"
|
3
|
-
end
|
4
|
-
|
5
|
-
def point(x=0.0, y=0.0, srid = 4326)
|
6
|
-
GeoRuby::SimpleFeatures::Point.from_x_y x, y, srid
|
7
|
-
end
|
8
|
-
|
9
|
-
def line_string(*points)
|
10
|
-
if points.one? and String === points.first
|
11
|
-
geometry_from_text("LINESTRING(#{points.first})")
|
12
|
-
else
|
13
|
-
GeoRuby::SimpleFeatures::LineString.from_points(points, points.first.srid)
|
14
|
-
end
|
15
|
-
end
|