diff options
| author | Xinhui | 2016-02-22 14:17:18 +0100 | 
|---|---|---|
| committer | Xinhui | 2016-02-22 14:17:18 +0100 | 
| commit | d49f47b4ac1db2cd88b96d830772bb7773924601 (patch) | |
| tree | 191c7b9cda9edf939792e7780df4e7460d685a4a /app/models/chouette/pt_link.rb | |
| parent | 633004afc5861a6e8158948ddfecd73bf4dd86a8 (diff) | |
| download | chouette-core-d49f47b4ac1db2cd88b96d830772bb7773924601.tar.bz2 | |
Merge model from ninoxe gem
Diffstat (limited to 'app/models/chouette/pt_link.rb')
| -rw-r--r-- | app/models/chouette/pt_link.rb | 37 | 
1 files changed, 37 insertions, 0 deletions
diff --git a/app/models/chouette/pt_link.rb b/app/models/chouette/pt_link.rb new file mode 100644 index 000000000..8a4e368ea --- /dev/null +++ b/app/models/chouette/pt_link.rb @@ -0,0 +1,37 @@ +require 'geokit' + +class Chouette::PtLink < Chouette::ActiveRecord +  # FIXME http://jira.codehaus.org/browse/JRUBY-6358 +  self.primary_key = "id" + +  include Geokit::Mappable + +  def geometry +    the_geom +  end + +  def self.import_csv +    csv_file = Rails.root + "chouette_pt_links.csv" +    if File.exists?( csv_file) +      csv = CSV::Reader.parse(File.read(csv_file)) + +      slug = csv.shift.first + +      Network::Base.find_by_slug( slug).tune_connection + +      csv.each do |row| +        origin = Chouette::StopArea.find_by_objectid( row[0]) +        destination = Chouette::StopArea.find_by_objectid( row[1]) + +        raise "unknown origin #{row[0]}" unless origin +        raise "unknown destination #{row[1]}" unless destination + +        Chouette::PtLink.create( :departure_id => origin.id, +                                 :arrival_id => destination.id, +                                 :the_geom => GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb( row[2])) +      end +    end +     +  end + +end  | 
