diff options
| author | Luc Donnet | 2013-07-10 11:22:01 +0200 | 
|---|---|---|
| committer | Luc Donnet | 2013-07-10 11:22:01 +0200 | 
| commit | 006522962b2feb2f28446991866522acd5d4886d (patch) | |
| tree | 0f5e9f879e102613467bac4879dc5d87b8ec4fc8 | |
| parent | ead284b277486b9731e740e7d94e88e09d2f987d (diff) | |
| download | chouette-core-006522962b2feb2f28446991866522acd5d4886d.tar.bz2 | |
Add stop place connection link access point and access link to kml export
| -rw-r--r-- | Gemfile.lock | 4 | ||||
| -rw-r--r-- | app/exporters/chouette/kml/access_link_exporter.rb | 27 | ||||
| -rw-r--r-- | app/exporters/chouette/kml/access_point_exporter.rb | 28 | ||||
| -rw-r--r-- | app/exporters/chouette/kml/connection_link_exporter.rb | 27 | ||||
| -rw-r--r-- | app/exporters/chouette/kml/exporter.rb | 32 | ||||
| -rw-r--r-- | app/exporters/chouette/kml/itl_exporter.rb | 28 | ||||
| -rw-r--r-- | app/views/api/kml/access_links/index.kml.erb | 73 | ||||
| -rw-r--r-- | app/views/api/kml/access_points/index.kml.erb | 70 | ||||
| -rw-r--r-- | app/views/api/kml/connection_links/index.kml.erb | 70 | ||||
| -rw-r--r-- | db/schema.rb | 18 | ||||
| -rw-r--r-- | spec/exporters/chouette/kml/exporter_spec.rb | 6 | 
11 files changed, 379 insertions, 4 deletions
| diff --git a/Gemfile.lock b/Gemfile.lock index 9211580e1..43684a552 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@  GIT    remote: git://github.com/dryade/georuby-ext.git -  revision: 014bb8903d08bdf9fb946e06ac757c8213158b88 +  revision: 69e3460141d831f0ad76780ee2b3f0a925a744f8    specs:      georuby-ext (0.0.2)        activesupport @@ -15,7 +15,7 @@ GIT  GIT    remote: git://github.com/dryade/ninoxe.git -  revision: 8e555ff5bd94250c98940878c052f449f4d14d7f +  revision: 148f0dfabdd5d21c95afff614a4c7403815ced9b    specs:      ninoxe (0.1.2)        activerecord (~> 3.1) diff --git a/app/exporters/chouette/kml/access_link_exporter.rb b/app/exporters/chouette/kml/access_link_exporter.rb new file mode 100644 index 000000000..0a02443df --- /dev/null +++ b/app/exporters/chouette/kml/access_link_exporter.rb @@ -0,0 +1,27 @@ +class Chouette::Kml::AccessLinkExporter +  include ERB::Util +  attr_accessor :access_links, :template + +  def initialize(access_links) +    @access_links = access_links +    @template = File.open('app/views/api/kml/access_links/index.kml.erb' ){ |f| f.read } +  end + +  def render() +    ERB.new(@template).result(binding) +  end + +  def kml_name +    "access_links" +  end + +  def file_extension +    ".kml" +  end + +  def save(directory, name = nil) +    File.open(directory + "/" + (name || kml_name) + file_extension, "w+") do |f| +      f.write(render) +    end if access_links.present? +  end +end diff --git a/app/exporters/chouette/kml/access_point_exporter.rb b/app/exporters/chouette/kml/access_point_exporter.rb new file mode 100644 index 000000000..17791f95f --- /dev/null +++ b/app/exporters/chouette/kml/access_point_exporter.rb @@ -0,0 +1,28 @@ +class Chouette::Kml::AccessPointExporter +  include ERB::Util +  attr_accessor :access_points, :template + +  def initialize(access_points) +    @access_points = access_points +    @template = File.open('app/views/api/kml/access_points/index.kml.erb' ){ |f| f.read } +  end + +  def render() +    ERB.new(@template).result(binding) +  end + +  def kml_name +    "access_points" +  end + +  def file_extension +    ".kml" +  end + +  def save(directory, name = nil) +    File.open(directory + "/" + (name || kml_name) + file_extension, "w+") do |f| +      f.write(render) +    end if access_points.present? +  end +end + diff --git a/app/exporters/chouette/kml/connection_link_exporter.rb b/app/exporters/chouette/kml/connection_link_exporter.rb new file mode 100644 index 000000000..dba998a21 --- /dev/null +++ b/app/exporters/chouette/kml/connection_link_exporter.rb @@ -0,0 +1,27 @@ +class Chouette::Kml::ConnectionLinkExporter +  include ERB::Util +  attr_accessor :connection_links, :template + +  def initialize(connection_links) +    @connection_links = connection_links +    @template = File.open('app/views/api/kml/connection_links/index.kml.erb' ){ |f| f.read } +  end + +  def render() +    ERB.new(@template).result(binding) +  end + +  def kml_name +    "connection_links" +  end + +  def file_extension +    ".kml" +  end + +  def save(directory, name = nil) +    File.open(directory + "/" + (name || kml_name) + file_extension, "w+") do |f| +      f.write(render) +    end if connection_links.present? +  end +end diff --git a/app/exporters/chouette/kml/exporter.rb b/app/exporters/chouette/kml/exporter.rb index 33f99a054..2f1ca2cf3 100644 --- a/app/exporters/chouette/kml/exporter.rb +++ b/app/exporters/chouette/kml/exporter.rb @@ -14,7 +14,7 @@ class Chouette::Kml::Exporter      elsif object == "line"        ids.present? ? referential.lines.find( ids.split(",") ): referential.lines      else -      [] +      referential.lines      end        end @@ -24,7 +24,7 @@ class Chouette::Kml::Exporter        FileUtils.rm(zip_file_path) if File.exists? zip_file_path         -      Dir.mktmpdir{ |temp_dir| +      Dir.mktmpdir(nil, "/tmp"){ |temp_dir|          lines_collected = lines( options[:o], options[:id] )          lines_collected.each do |line| @@ -50,6 +50,34 @@ class Chouette::Kml::Exporter            stop_area_exporter.save(temp_dir, "commercial_stop_areas")          end       +        if(options[:o].present?) # Add all objects +          stop_places = referential.stop_areas.stop_place +          Chouette::Kml::StopAreaExporter.new( stop_places ).tap do |stop_area_exporter| +            stop_area_exporter.save(temp_dir, "stop_places") +          end + +          itls = referential.stop_areas.itl +          Chouette::Kml::StopAreaExporter.new( itls ).tap do |stop_area_exporter| +            stop_area_exporter.save(temp_dir, "itls") +          end +           +          connection_links = referential.connection_links +          Chouette::Kml::ConnectionLinkExporter.new( connection_links ).tap do |connection_link_exporter| +            connection_link_exporter.save(temp_dir) +          end + +          access_links = referential.access_links +          Chouette::Kml::AccessLinkExporter.new( access_links ).tap do |access_link_exporter| +            access_link_exporter.save(temp_dir) +          end + +          access_points = referential.access_points +          Chouette::Kml::AccessPointExporter.new( access_points ).tap do |access_point_exporter| +            access_point_exporter.save(temp_dir) +          end +           +        end +          ::Zip::ZipFile.open(zip_file_path, ::Zip::ZipFile::CREATE) do |zipfile|            Dir[File.join(temp_dir, '*.kml')].each do |f|              zipfile.add(File.basename(f), f) diff --git a/app/exporters/chouette/kml/itl_exporter.rb b/app/exporters/chouette/kml/itl_exporter.rb new file mode 100644 index 000000000..12b61bec8 --- /dev/null +++ b/app/exporters/chouette/kml/itl_exporter.rb @@ -0,0 +1,28 @@ +class Chouette::Kml::ItlExporter +  include ERB::Util +  attr_accessor :itls, :template + +  def initialize(itls) +    @itls = itls +    @template = File.open('app/views/api/kml/itls/index.kml.erb' ){ |f| f.read } +  end + +  def render() +    ERB.new(@template).result(binding) +  end + +  def kml_name +    "itls" +  end + +  def file_extension +    ".kml" +  end + +  def save(directory, name = nil) +    File.open(directory + "/" + (name || kml_name) + file_extension, "w+") do |f| +      f.write(render) +    end if itls.present? +  end +end + diff --git a/app/views/api/kml/access_links/index.kml.erb b/app/views/api/kml/access_links/index.kml.erb new file mode 100644 index 000000000..2a08f75cd --- /dev/null +++ b/app/views/api/kml/access_links/index.kml.erb @@ -0,0 +1,73 @@ +<?xml version="1.0" encoding="UTF-8"?> +<kml xmlns="http://www.opengis.net/kml/2.2"> +  <Document> +    <name>liens acces arrets</name> +    <% @access_links.each do |access_link| %>     +      <Placemark id="<%= access_link.objectid %>" > +        <name><%=  access_link.name %></name>     +        <ExtendedData> +          <Data name="access_point_id"> +            <value><%= access_link.access_point_id %></value> +          </Data> +          <Data name="stop_area_id"> +            <value><%= access_link.stop_area_id %></value> +          </Data> +          <Data name="object_id"> +            <value><%= access_link.objectid %></value> +          </Data> +          <Data name="object_version"> +            <value><%= access_link.object_version %></value> +          </Data> +          <Data name="creation_time"> +            <value><%= access_link.creation_time %></value> +          </Data> +          <Data name="creator_id"> +            <value><%= access_link.creator_id %></value> +          </Data> +          <Data name="name"> +            <value><%= access_link.name %></value> +          </Data> +          <Data name="comment"> +            <value><%= access_link.comment %></value> +          </Data> +          <Data name="link_distance"> +            <value><%= access_link.link_distance %></value> +          </Data> +                    <Data name="link_type"> +            <value><%= access_link.link_type %></value> +          </Data> +          <Data name="default_duration"> +            <value><%= access_link.default_duration %></value> +          </Data> +          <Data name="frequent_traveller_duration"> +            <value><%= access_link.frequent_traveller_duration %></value> +          </Data> +          <Data name="occasional_traveller_duration"> +            <value><%= access_link.occasional_traveller_duration %></value> +          </Data> +          <Data name="mobility_restricted_traveller_duration"> +            <value><%= access_link.mobility_restricted_traveller_duration %></value> +          </Data> +          <Data name="mobility_restricted_suitability"> +            <value><%= access_link.mobility_restricted_suitability %></value> +          </Data> +          <Data name="stairs_availability"> +            <value><%= access_link.stairs_availability %></value> +          </Data> +          <Data name="lift_availability"> +            <value><%= access_link.lift_availability %></value> +          </Data>           +          <Data name="int_user_needs"> +            <value><%= access_link.int_user_needs %></value> +          </Data>           +          <Data name="link_orientation"> +            <value><%= access_link.link_orientation %></value> +          </Data> +        </ExtendedData>         +     +        <%= access_link.geometry_presenter.geometry.kml_representation.html_safe %> +      </Placemark> +    <% end %> +  </Document> +</kml> + diff --git a/app/views/api/kml/access_points/index.kml.erb b/app/views/api/kml/access_points/index.kml.erb new file mode 100644 index 000000000..ac04dfc56 --- /dev/null +++ b/app/views/api/kml/access_points/index.kml.erb @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="UTF-8"?> +<kml xmlns="http://www.opengis.net/kml/2.2"> +  <Document> +    <name>access</name> +    <% @access_points.each do |access_point| %>     +      <Placemark id="<%= access_point.objectid %>" > +        <name><%=  access_point.name %></name>     +        <ExtendedData> +          <Data name="object_id"> +            <value><%= access_point.objectid %></value> +          </Data> +          <Data name="object_version"> +            <value><%= access_point.object_version %></value> +          </Data> +          <Data name="creation_time"> +            <value><%= access_point.creation_time %></value> +          </Data> +          <Data name="creator_id"> +            <value><%= access_point.creator_id %></value> +          </Data> +          <Data name="name"> +            <value><%= access_point.name %></value> +          </Data> +          <Data name="comment"> +            <value><%= access_point.comment %></value> +          </Data> +          <Data name="longitude"> +            <value><%= access_point.longitude %></value> +          </Data> +          <Data name="latitude"> +            <value><%= access_point.latitude %></value> +          </Data> +          <Data name="long_lat_type"> +            <value><%= access_point.long_lat_type %></value> +          </Data> +          <Data name="country_code"> +            <value><%= access_point.country_code %></value> +          </Data> +          <Data name="street_name"> +            <value><%= access_point.street_name %></value> +          </Data> +          <Data name="contained_in"> +            <value><%= access_point.contained_in %></value> +          </Data> +          <Data name="openning_time"> +            <value><%= access_point.openning_time %></value> +          </Data> +          <Data name="closing_time"> +            <value><%= access_point.closing_time %></value> +          </Data> +          <Data name="access_type"> +            <value><%= access_point.access_type %></value> +          </Data>           +          <Data name="lift_availability"> +            <value><%= access_point.lift_availability %></value> +          </Data>           +          <Data name="mobility_restricted_suitability"> +            <value><%= access_point.mobility_restricted_suitability %></value> +          </Data>           +          <Data name="stairs_availability"> +            <value><%= access_point.stairs_availability %></value> +          </Data>           +        </ExtendedData>         +     +        <%= access_point.geometry_presenter.geometry.kml_representation.html_safe %> +      </Placemark> +    <% end %> +  </Document> +</kml> + diff --git a/app/views/api/kml/connection_links/index.kml.erb b/app/views/api/kml/connection_links/index.kml.erb new file mode 100644 index 000000000..30144047a --- /dev/null +++ b/app/views/api/kml/connection_links/index.kml.erb @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="UTF-8"?> +<kml xmlns="http://www.opengis.net/kml/2.2"> +  <Document> +    <name>correspondances</name> +    <% @connection_links.each do |connection_link| %>     +      <Placemark id="<%= connection_link.objectid %>" > +        <name><%=  connection_link.name %></name>     +        <ExtendedData> +          <Data name="departure_id"> +            <value><%= connection_link.departure_id %></value> +          </Data> +          <Data name="arrival_id"> +            <value><%= connection_link.arrival_id %></value> +          </Data> +          <Data name="object_id"> +            <value><%= connection_link.objectid %></value> +          </Data> +          <Data name="object_version"> +            <value><%= connection_link.object_version %></value> +          </Data> +          <Data name="creation_time"> +            <value><%= connection_link.creation_time %></value> +          </Data> +          <Data name="creator_id"> +            <value><%= connection_link.creator_id %></value> +          </Data> +          <Data name="name"> +            <value><%= connection_link.name %></value> +          </Data> +          <Data name="comment"> +            <value><%= connection_link.comment %></value> +          </Data> +          <Data name="link_distance"> +            <value><%= connection_link.link_distance %></value> +          </Data> +          <Data name="link_type"> +            <value><%= connection_link.link_type %></value> +          </Data> +          <Data name="default_duration"> +            <value><%= connection_link.default_duration %></value> +          </Data> +          <Data name="frequent_traveller_duration"> +            <value><%= connection_link.frequent_traveller_duration %></value> +          </Data> +          <Data name="occasional_traveller_duration"> +            <value><%= connection_link.occasional_traveller_duration %></value> +          </Data> +          <Data name="mobility_restricted_traveller_duration"> +            <value><%= connection_link.mobility_restricted_traveller_duration %></value> +          </Data> +          <Data name="mobility_restricted_suitability"> +            <value><%= connection_link.mobility_restricted_suitability %></value> +          </Data> +          <Data name="stairs_availability"> +            <value><%= connection_link.stairs_availability %></value> +          </Data> +          <Data name="lift_availability"> +            <value><%= connection_link.lift_availability %></value> +          </Data>           +          <Data name="int_user_needs"> +            <value><%= connection_link.int_user_needs %></value> +          </Data>           +        </ExtendedData>         +     +        <%= connection_link.geometry_presenter.geometry.kml_representation.html_safe %> +      </Placemark> +    <% end %> +  </Document> +</kml> + diff --git a/db/schema.rb b/db/schema.rb index f967e6b0a..3db8121f2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -204,6 +204,16 @@ ActiveRecord::Schema.define(:version => 20130708084944) do      t.integer  "organisation_id", :limit => 8    end +  create_table "geometry_columns", :id => false, :force => true do |t| +    t.string  "f_table_catalog",   :limit => 256, :null => false +    t.string  "f_table_schema",    :limit => 256, :null => false +    t.string  "f_table_name",      :limit => 256, :null => false +    t.string  "f_geometry_column", :limit => 256, :null => false +    t.integer "coord_dimension",                  :null => false +    t.integer "srid",                             :null => false +    t.string  "type",              :limit => 30,  :null => false +  end +    create_table "group_of_lines", :force => true do |t|      t.string   "objectid",       :null => false      t.integer  "object_version" @@ -360,6 +370,14 @@ ActiveRecord::Schema.define(:version => 20130708084944) do      t.integer "line_id",      :limit => 8    end +  create_table "spatial_ref_sys", :id => false, :force => true do |t| +    t.integer "srid",                      :null => false +    t.string  "auth_name", :limit => 256 +    t.integer "auth_srid" +    t.string  "srtext",    :limit => 2048 +    t.string  "proj4text", :limit => 2048 +  end +    create_table "stop_areas", :force => true do |t|      t.integer  "parent_id",                       :limit => 8      t.string   "objectid",                                                                     :null => false diff --git a/spec/exporters/chouette/kml/exporter_spec.rb b/spec/exporters/chouette/kml/exporter_spec.rb index f44e8f201..2a733e0a4 100644 --- a/spec/exporters/chouette/kml/exporter_spec.rb +++ b/spec/exporters/chouette/kml/exporter_spec.rb @@ -36,6 +36,12 @@ describe Chouette::Kml::Exporter do        ::Zip::ZipFile.open(zip_file_path).size.should == 6      end +    it "should return a zip file with 6 kml files" do +      subject.export(zip_file_path, {:export_id => 1, :o => "", :id => "" } )   +      File.exists?(zip_file_path).should be_true +      ::Zip::ZipFile.open(zip_file_path).size.should == 6 +    end +        end | 
