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
data/.gitignore
ADDED
data/.rvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rvm ruby-1.9.3-head
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
source "http://rubygems.org"
|
|
2
|
+
|
|
3
|
+
# Specify your gem's dependencies in activeroad.gemspec
|
|
4
|
+
gemspec
|
|
5
|
+
|
|
6
|
+
gem 'dr-postgis_adapter', :require => "postgis_adapter"
|
|
7
|
+
|
|
8
|
+
group :development do
|
|
9
|
+
gem 'rails-erd'
|
|
10
|
+
group :linux do
|
|
11
|
+
gem 'rb-inotify', :require => RUBY_PLATFORM.include?('linux') && 'rb-inotify'
|
|
12
|
+
gem 'rb-fsevent', :require => RUBY_PLATFORM.include?('darwin') && 'rb-fsevent'
|
|
13
|
+
end
|
|
14
|
+
end
|
data/Guardfile
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
guard 'bundler' do
|
|
2
|
+
watch('Gemfile')
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
guard 'rspec', :version => 2, :notification => false, :bundler => true, :binstubs => false do
|
|
6
|
+
watch(%r{^spec/.+_spec\.rb$})
|
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
|
8
|
+
|
|
9
|
+
# Rails example
|
|
10
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
|
11
|
+
watch(%r{^lib/active_road/(.+)\.rb$}) { |m| "spec/lib/active_road/#{m[1]}_spec.rb" }
|
|
12
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
|
13
|
+
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
|
14
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
|
15
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
|
16
|
+
watch('config/routes.rb') { "spec/routing" }
|
|
17
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
|
18
|
+
# Capybara request specs
|
|
19
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
guard 'migrate' do
|
|
23
|
+
watch(%r{^db/migrate/(\d+).+\.rb})
|
|
24
|
+
watch('db/seeds.rb')
|
|
25
|
+
end
|
|
26
|
+
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2010-2013 Cityway, inc.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# ActiveRoad [](http://travis-ci.org/dryade/activeroad?branch=master) [](https://gemnasium.com/dryade/activeroad) [](https://codeclimate.com/github/dryade/activeroad)
|
|
2
|
+
|
|
3
|
+
Rails engine with a model for roads and rails description
|
|
4
|
+
|
|
5
|
+
Requirements
|
|
6
|
+
------------
|
|
7
|
+
|
|
8
|
+
This code has been run and tested on Ruby 1.9.3
|
|
9
|
+
|
|
10
|
+
Installation
|
|
11
|
+
------------
|
|
12
|
+
|
|
13
|
+
This package is available in RubyGems and can be installed with:
|
|
14
|
+
|
|
15
|
+
gem install active_road
|
|
16
|
+
|
|
17
|
+
More Information
|
|
18
|
+
----------------
|
|
19
|
+
|
|
20
|
+
More information can be found on the [project website on GitHub](http://github.com/dryade/activeroad).
|
|
21
|
+
There is extensive usage documentation available [on the wiki](https://github.com/dryade/activeroad/wiki).
|
|
22
|
+
|
|
23
|
+
Example Usage
|
|
24
|
+
------------
|
|
25
|
+
|
|
26
|
+
...
|
|
27
|
+
|
|
28
|
+
License
|
|
29
|
+
-------
|
|
30
|
+
|
|
31
|
+
This project is licensed under the MIT license, a copy of which can be found in the LICENSE file.
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
Support
|
|
35
|
+
-------
|
|
36
|
+
|
|
37
|
+
Users looking for support should file an issue on the GitHub issue tracking page (https://github.com/dryade/activeroad/issues), or file a pull request (https://github.com/dryade/activeroad/pulls) if you have a fix available.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env rake
|
|
2
|
+
begin
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
rescue LoadError
|
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
namespace :ci do
|
|
9
|
+
task :prepare do
|
|
10
|
+
cp "config/database.yml.ci", "config/database.yml"
|
|
11
|
+
end
|
|
12
|
+
task :build => ["db:migrate", "spec"]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
begin
|
|
16
|
+
require 'rdoc/task'
|
|
17
|
+
rescue LoadError
|
|
18
|
+
require 'rdoc/rdoc'
|
|
19
|
+
require 'rake/rdoctask'
|
|
20
|
+
RDoc::Task = Rake::RDocTask
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
24
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
25
|
+
rdoc.title = 'ActiveRoad'
|
|
26
|
+
rdoc.options << '--line-numbers'
|
|
27
|
+
rdoc.rdoc_files.include('README.rdoc')
|
|
28
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
|
32
|
+
load 'rails/tasks/engine.rake'
|
|
33
|
+
|
|
34
|
+
Bundler::GemHelper.install_tasks
|
|
35
|
+
|
|
36
|
+
require 'rspec/core'
|
|
37
|
+
require 'rspec/core/rake_task'
|
|
38
|
+
|
|
39
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
40
|
+
|
|
41
|
+
RSpec::Core::RakeTask.new(:rcov) do |t|
|
|
42
|
+
t.rcov = true
|
|
43
|
+
t.rcov_opts = %w{--exclude osx\/objc,gems\/,spec\/,lib\/database_cleaner\/}
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
task :spec => "app:db:test:prepare"
|
data/active_road.gemspec
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
require "active_road/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "active_road"
|
|
7
|
+
s.version = ActiveRoad::VERSION
|
|
8
|
+
s.authors = ["Alban Peignier", "Luc Donnet", "Marc Florisson"]
|
|
9
|
+
s.email = ["alban@tryphon.eu", "luc.donnet@free.fr", "mflorisson@gmail.com"]
|
|
10
|
+
s.homepage = ""
|
|
11
|
+
s.summary = %q{Rails engine to manage roads and rails model}
|
|
12
|
+
s.description = %q{Find street numbers and road ways}
|
|
13
|
+
|
|
14
|
+
s.files = `git ls-files`.split("\n")
|
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
17
|
+
s.require_paths = ["lib"]
|
|
18
|
+
|
|
19
|
+
s.add_development_dependency "guard"
|
|
20
|
+
s.add_development_dependency "guard-bundler"
|
|
21
|
+
s.add_development_dependency "guard-rspec"
|
|
22
|
+
s.add_development_dependency "guard-migrate"
|
|
23
|
+
s.add_development_dependency "factory_girl_rails", "~> 4.2.1"
|
|
24
|
+
s.add_development_dependency "rspec-rails", "~> 2.11.4"
|
|
25
|
+
s.add_development_dependency 'rails', '~> 3.2.13'
|
|
26
|
+
|
|
27
|
+
s.add_dependency 'activerecord'
|
|
28
|
+
s.add_dependency 'activerecord-postgres-hstore'
|
|
29
|
+
s.add_dependency 'dr-postgis_adapter', '0.8.1'
|
|
30
|
+
s.add_dependency 'sqlite3', '~> 1.3.7'
|
|
31
|
+
s.add_dependency 'pg', '~> 0.15.1'
|
|
32
|
+
s.add_dependency 'activerecord-import', '~> 0.3.1'
|
|
33
|
+
s.add_dependency 'georuby-ext', "0.0.2"
|
|
34
|
+
s.add_dependency 'nokogiri'
|
|
35
|
+
s.add_dependency 'saxerator'
|
|
36
|
+
s.add_dependency 'shortest_path', '0.0.3'
|
|
37
|
+
s.add_dependency 'enumerize', '0.6.1'
|
|
38
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
class ActiveRoad::AccessLink
|
|
2
|
+
|
|
3
|
+
attr_accessor :departure, :arrival
|
|
4
|
+
|
|
5
|
+
def initialize(attributes = {})
|
|
6
|
+
attributes.each do |k, v|
|
|
7
|
+
send("#{k}=", v)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def name
|
|
12
|
+
"AccessLink : #{departure} -> #{arrival}"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
alias_method :to_s, :name
|
|
16
|
+
|
|
17
|
+
def self.from(location, constraints = {})
|
|
18
|
+
ActiveRoad::AccessPoint.from(location, constraints).collect do |access_point|
|
|
19
|
+
new :departure => location, :arrival => access_point
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def length
|
|
24
|
+
@length ||= departure.to_geometry.spherical_distance arrival.to_geometry
|
|
25
|
+
end
|
|
26
|
+
# TODO Delete this hack due to postgis adapter in physical road
|
|
27
|
+
alias_method :length_in_meter, :length
|
|
28
|
+
|
|
29
|
+
def geometry
|
|
30
|
+
@geometry ||= GeoRuby::SimpleFeatures::LineString.from_points [departure.to_geometry, arrival.to_geometry]
|
|
31
|
+
end
|
|
32
|
+
alias_method :to_geometry, :geometry
|
|
33
|
+
|
|
34
|
+
delegate :access_to_road?, :to => :arrival
|
|
35
|
+
|
|
36
|
+
def paths(constraints = {})
|
|
37
|
+
arrival.respond_to?(:paths) ? arrival.paths(constraints) : [arrival]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def access_to_road?(road)
|
|
41
|
+
arrival.respond_to?(:access_to_road?) ? arrival.access_to_road?(road) : false
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Access Point is a projection from an origin point on a Physical Road
|
|
2
|
+
# This origin point and Access Point are linked by an Access Link
|
|
3
|
+
|
|
4
|
+
class ActiveRoad::AccessPoint
|
|
5
|
+
|
|
6
|
+
attr_accessor :location, :physical_road, :exit
|
|
7
|
+
alias_method :exit?, :exit
|
|
8
|
+
|
|
9
|
+
def initialize(attributes = {})
|
|
10
|
+
attributes.each do |k, v|
|
|
11
|
+
send("#{k}=", v)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Find access points from a location
|
|
16
|
+
def self.from(location, constraints = {})
|
|
17
|
+
physical_roads_filtered = ActiveRoad::PhysicalRoadFilter.new(constraints).filter
|
|
18
|
+
|
|
19
|
+
physical_roads_filtered.nearest_to(location, 100).collect do |physical_road|
|
|
20
|
+
new :location => location, :physical_road => physical_road
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Find access points to go to a location
|
|
25
|
+
def self.to(location, constraints = {})
|
|
26
|
+
physical_roads_filtered = ActiveRoad::PhysicalRoadFilter.new(constraints).filter
|
|
27
|
+
|
|
28
|
+
physical_roads_filtered.nearest_to(location, 100).collect do |physical_road|
|
|
29
|
+
new :location => location, :physical_road => physical_road, :exit => true
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def location_on_road(road = nil)
|
|
34
|
+
@location_on_road ||= physical_road.locate_point location
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def point_on_road
|
|
38
|
+
@point_on_road ||= physical_road.interpolate_point location_on_road
|
|
39
|
+
end
|
|
40
|
+
alias_method :to_geometry, :point_on_road
|
|
41
|
+
alias_method :geometry, :point_on_road
|
|
42
|
+
|
|
43
|
+
def access_to_road?(road)
|
|
44
|
+
physical_road == road
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def name
|
|
48
|
+
"Access on #{physical_road.objectid} @#{point_on_road.to_lat_lng} (for @#{location.to_lat_lng})"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
delegate :spherical_distance, :to => :point_on_road
|
|
52
|
+
|
|
53
|
+
def to_s
|
|
54
|
+
name
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def paths(constraints = {})
|
|
58
|
+
unless exit?
|
|
59
|
+
ActiveRoad::Path.all self, physical_road.junctions, physical_road
|
|
60
|
+
else
|
|
61
|
+
[ActiveRoad::AccessLink.new(:departure => self, :arrival => location)]
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# A junction is a connection between 1 to n physical roads
|
|
2
|
+
require "activerecord-postgres-hstore"
|
|
3
|
+
|
|
4
|
+
module ActiveRoad
|
|
5
|
+
class Junction < ActiveRoad::Base
|
|
6
|
+
serialize :tags, ActiveRecord::Coders::Hstore
|
|
7
|
+
attr_accessible :objectid, :tags, :geometry, :height, :waiting_constraint
|
|
8
|
+
|
|
9
|
+
validates_uniqueness_of :objectid
|
|
10
|
+
|
|
11
|
+
has_and_belongs_to_many :physical_roads, :class_name => "ActiveRoad::PhysicalRoad",:uniq => true
|
|
12
|
+
has_many :junction_conditionnal_costs, :class_name => "ActiveRoad::JunctionConditionnalCost"
|
|
13
|
+
|
|
14
|
+
%w[max_speed, max_slope].each do |key|
|
|
15
|
+
attr_accessible key
|
|
16
|
+
scope "has_#{key}", lambda { |value| where("properties @> hstore(?, ?)", key, value) }
|
|
17
|
+
define_method(key) do
|
|
18
|
+
properties && properties[key]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
define_method("#{key}=") do |value|
|
|
22
|
+
self.properties = (properties || {}).merge(key => value)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def location_on_road(road)
|
|
27
|
+
(@location_on_road ||= {})[road.id] ||= road.locate_point(geometry)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def paths(tags = {})
|
|
31
|
+
ActiveRoad::PhysicalRoadFilter.new(tags, physical_roads).filter.includes(:junctions).collect do |physical_road|
|
|
32
|
+
ActiveRoad::Path.all self, (physical_road.junctions - [self]), physical_road
|
|
33
|
+
end.flatten
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def access_to_road?(road)
|
|
37
|
+
physical_roads.include? road
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def to_geometry
|
|
41
|
+
geometry
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def to_s
|
|
45
|
+
"Junction @#{geometry.to_lat_lng}"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def name
|
|
49
|
+
physical_roads.join(" - ")
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module ActiveRoad
|
|
2
|
+
class JunctionConditionnalCost < ActiveRoad::Base
|
|
3
|
+
|
|
4
|
+
belongs_to :junction
|
|
5
|
+
belongs_to :start_physical_road, :class_name => 'ActiveRoad::PhysicalRoad', :foreign_key => 'start_physical_road_id'
|
|
6
|
+
belongs_to :end_physical_road, :class_name => 'ActiveRoad::PhysicalRoad', :foreign_key => 'end_physical_road_id'
|
|
7
|
+
|
|
8
|
+
validates_presence_of :junction_id
|
|
9
|
+
validates_presence_of :tags
|
|
10
|
+
validates_presence_of :cost
|
|
11
|
+
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module ActiveRoad
|
|
2
|
+
class LogicalRoad < ActiveRoad::Base
|
|
3
|
+
extend ActiveSupport::Memoizable
|
|
4
|
+
attr_accessible :objectid, :name
|
|
5
|
+
|
|
6
|
+
validates_uniqueness_of :objectid
|
|
7
|
+
|
|
8
|
+
has_many :physical_roads, :class_name => "ActiveRoad::PhysicalRoad", :inverse_of => :logical_road
|
|
9
|
+
|
|
10
|
+
has_many :numbers, :through => :physical_roads, :class_name => "ActiveRoad::StreetNumber"
|
|
11
|
+
|
|
12
|
+
def geometry
|
|
13
|
+
GeoRuby::SimpleFeatures::MultiLineString.from_line_strings physical_roads.map(&:geometry)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def at(value)
|
|
17
|
+
if Float === value
|
|
18
|
+
geometry_at_location value
|
|
19
|
+
else
|
|
20
|
+
geometry_at_number value
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def geometry_at_number(number)
|
|
25
|
+
numbers.find_or_initialize_by_number(number.to_s).tap do |number|
|
|
26
|
+
number.road = self
|
|
27
|
+
end.geometry if number.present?
|
|
28
|
+
end
|
|
29
|
+
memoize :geometry_at_number
|
|
30
|
+
|
|
31
|
+
def geometry_at_location(location)
|
|
32
|
+
geometry.interpolate_point(location) if geometry
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.find_all_by_bounds(bounds)
|
|
36
|
+
ne_corner, sw_corner = bounds.upper_corner, bounds.lower_corner
|
|
37
|
+
sql_box = "SetSRID('BOX3D(#{ne_corner.lng} #{ne_corner.lat}, #{sw_corner.lng} #{sw_corner.lat})'::box3d, #{ActiveRoad.srid})"
|
|
38
|
+
find :all, :conditions => "geometry && #{sql_box}"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|