active_road 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/.gitignore +9 -0
  2. data/.rvmrc +1 -0
  3. data/.travis.yml +11 -0
  4. data/Gemfile +14 -0
  5. data/Guardfile +26 -0
  6. data/LICENSE.txt +19 -0
  7. data/README.md +37 -0
  8. data/Rakefile +46 -0
  9. data/active_road.gemspec +38 -0
  10. data/app/models/active_road/access_link.rb +44 -0
  11. data/app/models/active_road/access_point.rb +65 -0
  12. data/app/models/active_road/base.rb +5 -0
  13. data/app/models/active_road/junction.rb +52 -0
  14. data/app/models/active_road/junction_conditionnal_cost.rb +13 -0
  15. data/app/models/active_road/logical_road.rb +41 -0
  16. data/app/models/active_road/path.rb +85 -0
  17. data/app/models/active_road/physical_road.rb +65 -0
  18. data/app/models/active_road/physical_road_conditionnal_cost.rb +10 -0
  19. data/app/models/active_road/physical_road_filter.rb +41 -0
  20. data/app/models/active_road/street_number.rb +81 -0
  21. data/app/models/active_road/terra_import.rb +148 -0
  22. data/config/database.yml +20 -0
  23. data/config/database.yml.ci +12 -0
  24. data/config/routes.rb +2 -0
  25. data/db/init.sql +6 -0
  26. data/db/migrate/20110914160756_create_street_numbers.rb +18 -0
  27. data/db/migrate/20120201114800_create_physical_roads.rb +17 -0
  28. data/db/migrate/20120201162800_create_logical_roads.rb +16 -0
  29. data/db/migrate/20120203154500_create_junctions.rb +25 -0
  30. data/db/migrate/20120401083409_create_physical_roads_spatial_index.rb +9 -0
  31. data/db/migrate/20120419093427_add_kind_to_physical_roads.rb +10 -0
  32. data/db/migrate/20121010125851_create_junction_conditionnal_costs.rb +13 -0
  33. data/db/migrate/20121011124923_create_physical_road_conditionnal_costs.rb +13 -0
  34. data/db/migrate/20121012134251_add_start_end_ref_to_junction_conditionnal_cost.rb +6 -0
  35. data/db/migrate/20121012134440_add_tags_junction.rb +5 -0
  36. data/db/migrate/20121012134457_add_tags_physical_road.rb +5 -0
  37. data/db/migrate/20121106095002_add_objectid_to_street_number.rb +5 -0
  38. data/db/migrate/20130419155438_add_length_and_minimum_width_to_physical_road.rb +6 -0
  39. data/db/migrate/20130507162801_setup_hstore.rb +9 -0
  40. data/db/migrate/20130509075631_change_tags_type_for_physical_road.rb +10 -0
  41. data/db/migrate/20130509081745_index_physical_roads_tags.rb +9 -0
  42. data/db/migrate/20130513134422_change_tags_type_for_junction.rb +10 -0
  43. data/db/migrate/20130513134511_index_junctions_tags.rb +9 -0
  44. data/db/migrate/20130607114951_change_length_name_for_physical_road.rb +11 -0
  45. data/db/migrate/20130801151637_add_constraints_to_physical_roads.rb +37 -0
  46. data/db/migrate/20130809155019_add_height_and_waiting_constraint_to_junction.rb +6 -0
  47. data/db/migrate/20130812143049_fix_waiting_constraint_type_for_junction.rb +11 -0
  48. data/lib/active_road.rb +19 -0
  49. data/lib/active_road/engine.rb +13 -0
  50. data/lib/active_road/migration.rb +15 -0
  51. data/lib/active_road/shortest_path.rb +2 -0
  52. data/lib/active_road/shortest_path/finder.rb +172 -0
  53. data/lib/active_road/version.rb +3 -0
  54. data/lib/tasks/activeroad_tasks.rake +4 -0
  55. data/log/.gitignore +0 -0
  56. data/script/console +2 -0
  57. data/script/import-tiger-numbers +201 -0
  58. data/script/rails +9 -0
  59. data/spec/dummy/README.rdoc +261 -0
  60. data/spec/dummy/Rakefile +6 -0
  61. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  62. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  63. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  64. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  65. data/spec/dummy/app/mailers/.gitkeep +0 -0
  66. data/spec/dummy/app/models/.gitkeep +0 -0
  67. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  68. data/spec/dummy/config.ru +4 -0
  69. data/spec/dummy/config/application.rb +56 -0
  70. data/spec/dummy/config/boot.rb +10 -0
  71. data/spec/dummy/config/database.yml +20 -0
  72. data/spec/dummy/config/environment.rb +5 -0
  73. data/spec/dummy/config/environments/development.rb +37 -0
  74. data/spec/dummy/config/environments/production.rb +67 -0
  75. data/spec/dummy/config/environments/test.rb +37 -0
  76. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  77. data/spec/dummy/config/initializers/inflections.rb +15 -0
  78. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  79. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  80. data/spec/dummy/config/initializers/session_store.rb +8 -0
  81. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  82. data/spec/dummy/config/locales/en.yml +5 -0
  83. data/spec/dummy/config/routes.rb +4 -0
  84. data/spec/dummy/db/schema.rb +87 -0
  85. data/spec/dummy/db/structure.sql +10250 -0
  86. data/spec/dummy/lib/assets/.gitkeep +0 -0
  87. data/spec/dummy/log/.gitkeep +0 -0
  88. data/spec/dummy/public/404.html +26 -0
  89. data/spec/dummy/public/422.html +26 -0
  90. data/spec/dummy/public/500.html +25 -0
  91. data/spec/dummy/public/favicon.ico +0 -0
  92. data/spec/dummy/script/rails +6 -0
  93. data/spec/factories/junction.rb +18 -0
  94. data/spec/factories/junction_conditionnal_cost.rb +13 -0
  95. data/spec/factories/logical_road.rb +8 -0
  96. data/spec/factories/physical_road.rb +9 -0
  97. data/spec/factories/physical_road_conditionnal_cost.rb +9 -0
  98. data/spec/factories/street_number.rb +11 -0
  99. data/spec/fixtures/terra.xml +1772 -0
  100. data/spec/fixtures/terra_minimal.xml +28 -0
  101. data/spec/fixtures/trajectory_arc.xml +10 -0
  102. data/spec/fixtures/trajectory_node.xml +11 -0
  103. data/spec/lib/active_road/shortest_path/finder_spec.rb +157 -0
  104. data/spec/models/active_road/access_point_spec.rb +36 -0
  105. data/spec/models/active_road/junction_conditionnal_cost_spec.rb +28 -0
  106. data/spec/models/active_road/junction_spec.rb +25 -0
  107. data/spec/models/active_road/logical_road_spec.rb +46 -0
  108. data/spec/models/active_road/path_spec.rb +7 -0
  109. data/spec/models/active_road/physical_road_conditionnal_cost_spec.rb +19 -0
  110. data/spec/models/active_road/physical_road_filter_spec.rb +85 -0
  111. data/spec/models/active_road/physical_road_spec.rb +17 -0
  112. data/spec/models/active_road/street_number_spec.rb +78 -0
  113. data/spec/models/active_road/terra_import_spec.rb +113 -0
  114. data/spec/spec_helper.rb +46 -0
  115. data/spec/support/georuby_ext.rb +15 -0
  116. data/travis/before_install.sh +10 -0
  117. data/travis/before_script.sh +9 -0
  118. metadata +460 -0
@@ -0,0 +1,12 @@
1
+ development:
2
+ adapter: postgresql
3
+ database: activeroad
4
+ username: postgres
5
+ template: template_postgis
6
+
7
+ test:
8
+ adapter: postgresql
9
+ database: activeroad_test
10
+ username: postgres
11
+ template: template_postgis
12
+
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
data/db/init.sql ADDED
@@ -0,0 +1,6 @@
1
+ create language plpgsql;
2
+
3
+ \i /usr/share/postgresql-8.3-postgis/lwpostgis.sql;
4
+ \i /usr/share/postgresql-8.3-postgis/spatial_ref_sys.sql;
5
+
6
+ INSERT INTO spatial_ref_sys (srid, auth_name, auth_srid, srtext, proj4text)VALUES (900913,'EPSG',900913,'PROJCS["WGS84 / Simple Mercator",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS_1984", 6378137.0, 298.257223563]],PRIMEM["Greenwich", 0.0],UNIT["degree", 0.017453292519943295],AXIS["Longitude", EAST],AXIS["Latitude", NORTH]],PROJECTION["Mercator_1SP_Google"],PARAMETER["latitude_of_origin", 0.0],PARAMETER["central_meridian", 0.0],PARAMETER["scale_factor", 1.0],PARAMETER["false_easting", 0.0],PARAMETER["false_northing", 0.0],UNIT["m", 1.0],AXIS["x", EAST],AXIS["y", NORTH],AUTHORITY["EPSG","900913"]]','+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs');
@@ -0,0 +1,18 @@
1
+ class CreateStreetNumbers < ActiveRoad::Migration
2
+ def self.up
3
+ create_table :street_numbers do |t|
4
+ t.string :number
5
+ t.float :location_on_road
6
+ t.belongs_to :physical_road
7
+ t.point :geometry, :srid => ActiveRoad.srid
8
+ t.timestamps
9
+ end
10
+
11
+ add_index :street_numbers, [:number, :physical_road_id]
12
+ add_index :street_numbers, :physical_road_id
13
+ end
14
+
15
+ def self.down
16
+ drop_table :street_numbers
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ class CreatePhysicalRoads < ActiveRoad::Migration
2
+ def self.up
3
+ create_table :physical_roads do |t|
4
+ t.string :objectid
5
+ t.belongs_to :logical_road
6
+ t.line_string :geometry, :srid => ActiveRoad.srid
7
+ t.timestamps
8
+ end
9
+
10
+ add_index :physical_roads, :objectid, :uniq => true
11
+ add_index :physical_roads, :logical_road_id
12
+ end
13
+
14
+ def self.down
15
+ drop_table :physical_roads
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ class CreateLogicalRoads < ActiveRoad::Migration
2
+ def self.up
3
+ create_table :logical_roads do |t|
4
+ t.string :name
5
+ t.string :objectid
6
+ t.timestamps
7
+ end
8
+
9
+ add_index :logical_roads, :objectid, :uniq => true
10
+ add_index :logical_roads, :name
11
+ end
12
+
13
+ def self.down
14
+ drop_table :logical_roads
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ class CreateJunctions < ActiveRoad::Migration
2
+ def self.up
3
+ create_table :junctions do |t|
4
+ t.string :objectid
5
+ t.point :geometry, :srid => ActiveRoad.srid
6
+ t.timestamps
7
+ end
8
+
9
+ add_index :junctions, :objectid, :uniq => true
10
+
11
+ create_table :junctions_physical_roads, :id => false do |t|
12
+ t.belongs_to :physical_road
13
+ t.belongs_to :junction
14
+ end
15
+
16
+ # Generated name is too long for PostgreSQL
17
+ add_index :junctions_physical_roads, [:physical_road_id, :junction_id], :name => 'junctions_physical_roads_ids', :uniq => true
18
+ add_index :junctions_physical_roads, [:junction_id]
19
+ end
20
+
21
+ def self.down
22
+ drop_table :junctions
23
+ drop_table :junctions_physical_roads
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ class CreatePhysicalRoadsSpatialIndex < ActiveRecord::Migration
2
+ def up
3
+ add_index :physical_roads, :geometry, :spatial => true
4
+ end
5
+
6
+ def down
7
+ remove_index :physical_roads, :geometry, :spatial => true
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ class AddKindToPhysicalRoads < ActiveRecord::Migration
2
+ def change
3
+ add_column :physical_roads, :kind, :string
4
+
5
+ ActiveRoad::PhysicalRoad.reset_column_information
6
+ ActiveRoad::PhysicalRoad.update_all :kind => "road"
7
+
8
+ add_index :physical_roads, :kind
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ class CreateJunctionConditionnalCosts < ActiveRoad::Migration
2
+ def up
3
+ create_table :junction_conditionnal_costs do |t|
4
+ t.belongs_to :junction
5
+ t.float :cost
6
+ t.string :tags
7
+ end
8
+ end
9
+
10
+ def down
11
+ drop_table :junction_conditionnal_costs
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ class CreatePhysicalRoadConditionnalCosts < ActiveRecord::Migration
2
+ def up
3
+ create_table :physical_road_conditionnal_costs do |t|
4
+ t.belongs_to :physical_road
5
+ t.float :cost
6
+ t.string :tags
7
+ end
8
+ end
9
+
10
+ def down
11
+ drop_table :physical_road_conditionnal_costs
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ class AddStartEndRefToJunctionConditionnalCost < ActiveRecord::Migration
2
+ def change
3
+ add_column :junction_conditionnal_costs, :start_physical_road_id, :integer
4
+ add_column :junction_conditionnal_costs, :end_physical_road_id, :integer
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class AddTagsJunction < ActiveRecord::Migration
2
+ def change
3
+ add_column :junctions, :tags, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddTagsPhysicalRoad < ActiveRecord::Migration
2
+ def change
3
+ add_column :physical_roads, :tags, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddObjectidToStreetNumber < ActiveRecord::Migration
2
+ def change
3
+ add_column :street_numbers, :objectid, :string
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class AddLengthAndMinimumWidthToPhysicalRoad < ActiveRecord::Migration
2
+ def change
3
+ add_column :physical_roads, :length, :integer, :default => 0
4
+ add_column :physical_roads, :minimum_width, :integer, :default => 0
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ class SetupHstore < ActiveRecord::Migration
2
+ def self.up
3
+ execute "CREATE EXTENSION IF NOT EXISTS hstore"
4
+ end
5
+
6
+ def self.down
7
+ execute "DROP EXTENSION IF EXISTS hstore"
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ class ChangeTagsTypeForPhysicalRoad < ActiveRecord::Migration
2
+ def up
3
+ remove_column :physical_roads, :tags
4
+ add_column :physical_roads, :tags, :hstore
5
+ end
6
+
7
+ def down
8
+ add_column :physical_roads, :tags, :string
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ class IndexPhysicalRoadsTags < ActiveRecord::Migration
2
+ def up
3
+ execute "CREATE INDEX physical_roads_tags ON physical_roads USING GIN(tags)"
4
+ end
5
+
6
+ def down
7
+ execute "DROP INDEX physical_roads_tags"
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ class ChangeTagsTypeForJunction < ActiveRecord::Migration
2
+ def up
3
+ remove_column :junctions, :tags
4
+ add_column :junctions, :tags, :hstore
5
+ end
6
+
7
+ def down
8
+ add_column :junctions, :tags, :string
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ class IndexJunctionsTags < ActiveRecord::Migration
2
+ def up
3
+ execute "CREATE INDEX junctions_tags ON junctions USING GIN(tags)"
4
+ end
5
+
6
+ def down
7
+ execute "DROP INDEX junctions_tags"
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ class ChangeLengthNameForPhysicalRoad < ActiveRecord::Migration
2
+ def up
3
+ remove_column :physical_roads, :length
4
+ add_column :physical_roads, :length_in_meter, :float, :default => 0
5
+ end
6
+
7
+ def down
8
+ remove_column :physical_roads, :length_in_meter
9
+ add_column :physical_roads, :length, :integer
10
+ end
11
+ end
@@ -0,0 +1,37 @@
1
+ class AddConstraintsToPhysicalRoads < ActiveRecord::Migration
2
+ def up
3
+ remove_column :physical_roads, :minimum_width
4
+ remove_column :physical_roads, :kind
5
+
6
+ add_column :physical_roads, :minimum_width, :string
7
+ add_column :physical_roads, :transport_mode, :string
8
+ add_column :physical_roads, :uphill, :float
9
+ add_column :physical_roads, :downhill, :float
10
+ add_column :physical_roads, :slope, :string
11
+ add_column :physical_roads, :cant, :string
12
+ add_column :physical_roads, :covering, :string
13
+ add_column :physical_roads, :steps_count, :integer
14
+ add_column :physical_roads, :banisters_available, :boolean
15
+ add_column :physical_roads, :tactile_band, :boolean
16
+ add_column :physical_roads, :physical_road_type, :string
17
+
18
+ add_index :physical_roads, :physical_road_type
19
+
20
+ end
21
+
22
+ def down
23
+ remove_column :physical_roads, :minimum_width
24
+ remove_column :physical_roads, :transport_mode
25
+ remove_column :physical_roads, :uphill
26
+ remove_column :physical_roads, :downhill
27
+ remove_column :physical_roads, :slope
28
+ remove_column :physical_roads, :cant
29
+ remove_column :physical_roads, :covering
30
+ remove_column :physical_roads, :steps_count
31
+ remove_column :physical_roads, :banisters_available
32
+ remove_column :physical_roads, :tactile_band
33
+ remove_column :physical_roads, :physical_road_type
34
+
35
+ add_column :physical_roads, :minimum_width, :integer
36
+ end
37
+ end
@@ -0,0 +1,6 @@
1
+ class AddHeightAndWaitingConstraintToJunction < ActiveRecord::Migration
2
+ def change
3
+ add_column :junctions, :height, :float
4
+ add_column :junctions, :waiting_constraint, :time
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ class FixWaitingConstraintTypeForJunction < ActiveRecord::Migration
2
+ def up
3
+ remove_column :junctions, :waiting_constraint
4
+ add_column :junctions, :waiting_constraint, :float
5
+ end
6
+
7
+ def down
8
+ remove_column :junctions, :waiting_constraint
9
+ add_column :junctions, :waiting_constraint, :time
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ require "active_road/engine"
2
+ require 'erb'
3
+
4
+ module ActiveRoad
5
+
6
+ def self.srid
7
+ 4326
8
+ end
9
+
10
+ def self.database_configuration
11
+ YAML::load(ERB.new(IO.read( File.expand_path('../../config/database.yml', __FILE__))).result)
12
+ end
13
+
14
+ end
15
+
16
+ require "active_road/shortest_path"
17
+ require "active_road/shortest_path/finder"
18
+
19
+
@@ -0,0 +1,13 @@
1
+ module ActiveRoad
2
+ if defined?(Rails)
3
+ require "active_road/migration"
4
+
5
+ class Engine < ::Rails::Engine
6
+
7
+ initializer "active_road.factories", :after => "factory_girl.set_factory_paths" do
8
+ FactoryGirl.definition_file_paths << File.expand_path('../../../spec/factories', __FILE__) if defined?(FactoryGirl)
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ class ActiveRoad::Migration < ActiveRecord::Migration
2
+ # def connection
3
+ # # @connection can be wrapped (with CommandRecorder in Rails 3.2 for example)
4
+ # if roads_connection?(@connection)
5
+ # @connection
6
+ # else
7
+ # @connection = ActiveRoad::Base.connection
8
+ # end
9
+ # end
10
+
11
+ # def roads_connection?(connection)
12
+ # connection.respond_to?(:current_database) and
13
+ # connection.current_database == ActiveRoad::Base.connection.current_database
14
+ # end
15
+ end
@@ -0,0 +1,2 @@
1
+ module ActiveRoad::ShortestPath
2
+ end
@@ -0,0 +1,172 @@
1
+ # -*- coding: utf-8 -*-
2
+ # This class find the shortest path between a departure and an arrival with :
3
+ # - weight functions
4
+ # - tags to find selected physical roads
5
+ #
6
+ # A classic result would be with a point for departure and arrival :
7
+ # Paths ==> 1 : Departure Point
8
+ # |=> 2 : Access Link
9
+ # |=> 3 : Path between AccessPoint and a Junction
10
+ # |=> ... : Path between a Junction and another Junction
11
+ # |=> n-2 : Path between a Junction and an Access Point
12
+ # |=> n-1 : Access Link
13
+ # |=> n : Arrival Point
14
+
15
+
16
+ require 'shortest_path/finder'
17
+
18
+ class ActiveRoad::ShortestPath::Finder < ShortestPath::Finder
19
+
20
+ attr_accessor :speed, :physical_road_filter, :follow_way_filter, :user_weights
21
+
22
+ def initialize(departure, arrival, speed = 4, constraints = {}, user_weights = {})
23
+ super departure, arrival
24
+ @speed = speed * 1000 / 3600 # Convert speed in meter/second
25
+ @follow_way_filter, @physical_road_filter = {}, {}
26
+ constraints.each do |key, value|
27
+ if key == :uphill || key == :downhill || key == :height
28
+ @follow_way_filter[key] = value # filter to use with follow_way? method
29
+ else
30
+ @physical_road_filter[key] = value # filter to use with physical_roads
31
+ end
32
+ end
33
+ @user_weights = user_weights # Not used
34
+ end
35
+
36
+ def destination_accesses
37
+ @destination_accesses ||= ActiveRoad::AccessPoint.to(destination, physical_road_filter)
38
+ end
39
+
40
+ # Return a time in second from node to destination
41
+ # TODO : Tenir compte de la sinuosité de la route???
42
+ def time_heuristic(node)
43
+ if node.respond_to?(:arrival)
44
+ node.arrival.to_geometry.spherical_distance(destination) / speed
45
+ else
46
+ node.to_geometry.spherical_distance(destination) / speed
47
+ end
48
+ end
49
+
50
+ # Return a distance in meter from node to destination
51
+ def distance_heuristic(node)
52
+ if node.respond_to?(:arrival)
53
+ node.arrival.to_geometry.spherical_distance(destination)
54
+ else
55
+ node.to_geometry.spherical_distance(destination)
56
+ end
57
+ end
58
+
59
+ def path_weights(path)
60
+ path_weights = 0
61
+
62
+ # Add path weight
63
+ path_weights += path_weight(path.length_in_meter) if path.respond_to?(:length_in_meter)
64
+
65
+ # Add junction weight if it's a junction with a waiting constraint
66
+ if path.class != GeoRuby::SimpleFeatures::Point && path.departure.class == ActiveRoad::Junction && path.departure && path.departure.waiting_constraint
67
+ path_weights += path.departure.waiting_constraint
68
+ end
69
+
70
+ # TODO Refactor user weights
71
+ # if path.respond_to?(:road) # PhysicalRoad only no AccessLink
72
+ # path_tags = path.road.tags
73
+
74
+ # user_weights.each do |key, value|
75
+ # if path_tags.keys.include? key
76
+ # min, max, percentage = value[0], value[1], value[2]
77
+ # if min <= path_tags[key].to_i && path_tags[key].to_i <= max
78
+ # path_weights += path_weight(path_length, percentage)
79
+ # end
80
+ # end
81
+ # end
82
+ # end
83
+
84
+ path_weights
85
+ end
86
+
87
+ def path_weight( length_in_meter = 0, percentage = 1 )
88
+ (length_in_meter / speed) * percentage
89
+ end
90
+
91
+ def geometry
92
+ @geometry ||= GeoRuby::SimpleFeatures::LineString.merge path.collect { |n| n.to_geometry }.select { |g| GeoRuby::SimpleFeatures::LineString === g }
93
+ end
94
+
95
+ # Use to profile code
96
+ def self.example
97
+ from = (ENV['FROM'] or "30.030238,-90.061541")
98
+ to = (ENV['TO'] or "29.991739,-90.06918")
99
+
100
+ ActiveRoad::ShortestPath::Finder.new GeoRuby::SimpleFeatures::Point.from_lat_lng(from), GeoRuby::SimpleFeatures::Point.from_lat_lng(to)
101
+ end
102
+
103
+ #-----------------------------------------
104
+ # Overwrite ShortestPath::Finder methods
105
+ #-----------------------------------------
106
+
107
+ def visited?(node)
108
+ super(respond_to?(:arrival) ? node.arrival : node)
109
+ end
110
+
111
+ def visit(node)
112
+ super(respond_to?(:arrival) ? node.arrival : node)
113
+ end
114
+
115
+ def search_heuristic(node)
116
+ shortest_distances[node] + time_heuristic(node)
117
+ end
118
+
119
+ # Update context with uphill, downhill and height
120
+ # TODO : Fix arguments node is not a node but a path a point or an access link!!
121
+ def refresh_context( node, context = {} )
122
+ context_uphill = context[:uphill] ? context[:uphill] : 0
123
+ context_downhill = context[:downhill] ? context[:downhill] : 0
124
+ context_height = context[:height] ? context[:height] : 0
125
+
126
+ if( node.class == ActiveRoad::Path )
127
+ departure = node.departure
128
+ physical_road = node.physical_road
129
+
130
+ node_uphill = ( physical_road && physical_road.uphill) ? physical_road.uphill : 0
131
+ node_downhill = (physical_road && physical_road.downhill) ? physical_road.downhill : 0
132
+ node_height = (departure.class != ActiveRoad::AccessPoint && departure && departure.height) ? departure.height : 0
133
+
134
+ return { :uphill => (context_uphill + node_uphill), :downhill => (context_downhill + node_downhill), :height => (context_height + node_height) }
135
+ else
136
+ return {:uphill => context_uphill, :downhill => context_downhill, :height => context_height}
137
+ end
138
+ end
139
+
140
+ # Follow way depends from uphill, downhill, height and heuristics
141
+ def follow_way?(node, destination, weight, context={})
142
+ # Check that arguments in the context is less than the object parameters
143
+ request = true
144
+ request = request && context[:uphill] <= follow_way_filter[:uphill] if follow_way_filter[:uphill] && context[:uphill].present?
145
+ request = request && context[:downhill] <= follow_way_filter[:downhill] if follow_way_filter[:downhill] && context[:downhill].present?
146
+ request = request && context[:height] <= follow_way_filter[:height] if follow_way_filter[:height] && context[:height].present?
147
+ request = request && search_heuristic(node) + weight < time_heuristic(source) * 10
148
+ end
149
+
150
+ def ways(node, context={})
151
+ paths =
152
+ if GeoRuby::SimpleFeatures::Point === node
153
+ ActiveRoad::AccessLink.from(node, physical_road_filter)
154
+ else
155
+ node.paths(physical_road_filter)
156
+ end
157
+
158
+ unless GeoRuby::SimpleFeatures::Point === node # For the first point to access physical roads
159
+ destination_accesses.select do |destination_access|
160
+ if node.access_to_road?(destination_access.physical_road)
161
+ paths << ActiveRoad::Path.new(:departure => node.arrival, :arrival => destination_access, :physical_road => destination_access.physical_road)
162
+ end
163
+ end
164
+ end
165
+
166
+ array = paths.collect do |path|
167
+ [ path, path_weights(path)]
168
+ end
169
+ Hash[array]
170
+ end
171
+
172
+ end