diff options
| author | Marc Florisson | 2013-07-23 09:30:19 +0200 |
|---|---|---|
| committer | Marc Florisson | 2013-07-23 09:30:19 +0200 |
| commit | 59f686b05bd0bd98fb10c39f19074e7261f75a76 (patch) | |
| tree | 6b45ca0bb089d63f31632c0164441b7332d42926 /app/exporters | |
| parent | 7d85b099b281da38e354c9c2de88da4cde525dfa (diff) | |
| download | chouette-core-59f686b05bd0bd98fb10c39f19074e7261f75a76.tar.bz2 | |
fix kml export
Diffstat (limited to 'app/exporters')
| -rw-r--r-- | app/exporters/chouette/kml/exporter.rb | 68 | ||||
| -rw-r--r-- | app/exporters/chouette/kml/journey_pattern_exporter.rb | 2 | ||||
| -rw-r--r-- | app/exporters/chouette/kml/stop_area_exporter.rb | 53 |
3 files changed, 77 insertions, 46 deletions
diff --git a/app/exporters/chouette/kml/exporter.rb b/app/exporters/chouette/kml/exporter.rb index 5c488883c..046d5d29f 100644 --- a/app/exporters/chouette/kml/exporter.rb +++ b/app/exporters/chouette/kml/exporter.rb @@ -1,4 +1,4 @@ -class Chouette::Kml::Exporter +class Chouette::Kml::Exporter attr_reader :referential attr_reader :kml_export @@ -10,69 +10,57 @@ class Chouette::Kml::Exporter def lines(object, ids) if object == "network" - ids.present? ? referential.networks.find( ids.split(",") ).collect(&:lines).flatten : referential.networks.collect(&:lines).flatten + ids.present? ? referential.networks.find( ids.split(",") ).collect(&:lines).flatten : referential.networks.collect(&:lines).flatten elsif object == "company" ids.present? ? referential.companies.find( ids.split(",") ).collect(&:lines).flatten : referential.companies.collect(&:lines).flatten elsif object == "line" ids.present? ? referential.lines.find( ids.split(",") ): referential.lines else referential.lines - end + end end - def export(zip_file_path, options = {}) - begin + def export(zip_file_path, options = {}) + begin referential.switch - FileUtils.rm(zip_file_path) if File.exists? zip_file_path + FileUtils.rm(zip_file_path) if File.exists? zip_file_path kml_export.log_messages.create( :severity => "ok", :key => "EXPORT", :arguments => {"0" => "KML"}) Dir.mktmpdir(nil, "/tmp"){ |temp_dir| - - lines_collected = lines( options[:o], options[:id] ) + + lines_collected = lines( options[:o], options[:id] ).sort_by(&:name) Chouette::Kml::LineExporter.save( lines_collected, temp_dir, kml_export) - - routes = lines_collected.collect(&:routes).flatten.uniq + + routes = lines_collected.collect(&:routes).flatten.uniq.sort_by(&:name) Chouette::Kml::RouteExporter.save( routes, temp_dir, kml_export) journey_patterns = routes.map { |r| r.journey_patterns}.flatten Chouette::Kml::JourneyPatternExporter.save( journey_patterns, temp_dir, kml_export) - - stop_areas = lines_collected.collect(&:stop_areas).flatten.uniq - Chouette::Kml::StopAreaExporter.new( stop_areas, temp_dir ).tap do |stop_area_exporter| - stop_area_exporter.save( "stop_areas") - end - kml_export.log_messages.create( :severity => "ok", :key => "EXPORT|QUAY_AND_BOARDING_POSITION_COUNT", :arguments => {"0" => stop_areas.size}) - - commercial_stop_areas = lines_collected.collect(&:commercial_stop_areas).flatten.uniq - Chouette::Kml::StopAreaExporter.new( commercial_stop_areas, temp_dir ).tap do |stop_area_exporter| - stop_area_exporter.save( "commercial_stop_areas") - end - kml_export.log_messages.create( :severity => "ok", :key => "EXPORT|COMMERCIAL_COUNT", :arguments => {"0" => commercial_stop_areas.size}) - + + stop_areas = lines_collected.collect(&:stop_areas).flatten.uniq.sort_by(&:name) + Chouette::Kml::StopAreaExporter.save( stop_areas, temp_dir, kml_export, "Quay") + + commercial_stop_areas = lines_collected.collect(&:commercial_stop_areas).flatten.uniq.sort_by(&:name) + Chouette::Kml::StopAreaExporter.save( stop_areas, temp_dir, kml_export, "CommercialStopPoint") + if(options[:o].present?) # Add all objects - stop_places = referential.stop_areas.stop_place - Chouette::Kml::StopAreaExporter.new( stop_places, temp_dir ).tap do |stop_area_exporter| - stop_area_exporter.save( "stop_places") - end - kml_export.log_messages.create( :severity => "ok", :key => "EXPORT|STOP_PLACE_COUNT", :arguments => {"0" => stop_places.size}) + stop_places = referential.stop_areas.stop_place.sort_by(&:name) + Chouette::Kml::StopAreaExporter.save( stop_areas, temp_dir, kml_export, "StopPlace") - itls = referential.stop_areas.itl - Chouette::Kml::StopAreaExporter.new( itls, temp_dir ).tap do |stop_area_exporter| - stop_area_exporter.save( "itls") - end - kml_export.log_messages.create( :severity => "ok", :key => "EXPORT|ITL_COUNT", :arguments => {"0" => itls.size}) - - connection_links = referential.connection_links + itls = referential.stop_areas.itl.sort_by(&:name) + Chouette::Kml::StopAreaExporter.save( stop_areas, temp_dir, kml_export, "ITL") + + connection_links = referential.connection_links.sort_by(&:name) Chouette::Kml::ConnectionLinkExporter.save( connection_links, temp_dir, kml_export) - access_links = referential.access_links + access_links = referential.access_links.sort_by(&:name) Chouette::Kml::AccessLinkExporter.save(access_links, temp_dir, kml_export) - access_points = referential.access_points + access_points = referential.access_points.sort_by(&:name) Chouette::Kml::AccessPointExporter.save(access_points, temp_dir, kml_export) - + end ::Zip::ZipFile.open(zip_file_path, ::Zip::ZipFile::CREATE) do |zipfile| @@ -85,7 +73,7 @@ class Chouette::Kml::Exporter # Always cleanup files #FileUtils.remove_entry(temp_directory) end - end - + end + end diff --git a/app/exporters/chouette/kml/journey_pattern_exporter.rb b/app/exporters/chouette/kml/journey_pattern_exporter.rb index f5addc4bc..df693f11c 100644 --- a/app/exporters/chouette/kml/journey_pattern_exporter.rb +++ b/app/exporters/chouette/kml/journey_pattern_exporter.rb @@ -12,7 +12,7 @@ class Chouette::Kml::JourneyPatternExporter end def kml_name - "/line_#{journey_pattern.route.line_id}_route_#{journey_pattern.route.id}_journey_attern_#{journey_pattern.id}.kml" + "/line_#{journey_pattern.route.line_id}_route_#{journey_pattern.route.id}_journey_pattern_#{journey_pattern.id}.kml" end def self.save( journey_patterns, directory, kml_export) diff --git a/app/exporters/chouette/kml/stop_area_exporter.rb b/app/exporters/chouette/kml/stop_area_exporter.rb index 246fc114c..8696f4018 100644 --- a/app/exporters/chouette/kml/stop_area_exporter.rb +++ b/app/exporters/chouette/kml/stop_area_exporter.rb @@ -1,10 +1,11 @@ class Chouette::Kml::StopAreaExporter include ERB::Util - attr_accessor :stop_areas, :directory, :template + attr_accessor :stop_areas, :directory, :template, :area_type - def initialize(stop_areas,directory) + def initialize(stop_areas,directory,area_type) @stop_areas = stop_areas @directory = directory + @area_type = area_type @template = File.open('app/views/api/kml/stop_areas/index.kml.erb' ){ |f| f.read } end @@ -12,16 +13,58 @@ class Chouette::Kml::StopAreaExporter ERB.new(@template).result(binding) end + def layer_name + case area_type + when "CommercialStopPoint" + "Arrets commerciaux" + when 'Quay', 'BoardingPosition' + "Arrets physiques" + when "StopPlace" + "Poles d'echange" + when "ITL" + "ITL" + end + end + + def self.local_key(area_type) + case area_type + when "CommercialStopPoint" + "EXPORT|COMMERCIAL_COUNT" + when 'Quay', 'BoardingPosition' + "EXPORT|QUAY_AND_BOARDING_POSITION_COUNT" + when "StopPlace" + "EXPORT|STOP_PLACE_COUNT" + when "ITL" + "EXPORT|ITL_COUNT" + end + end + def kml_name - "stop_areas" + case area_type + when 'Quay', 'BoardingPosition' + "stop_areas" + when "CommercialStopPoint" + "commercial_stop_areas" + when "StopPlace" + "stop_places" + when "ITL" + "itls" + end end def file_extension ".kml" end - def save( name = nil) - File.open(directory + "/" + (name || kml_name) + file_extension, "w+") do |f| + def self.save( models, directory, kml_export, area_type) + self.new( models, directory, area_type).tap do |specific_exporter| + specific_exporter.save + end + kml_export.log_messages.create( :severity => "ok", :key => self.local_key(area_type), :arguments => {"0" => models.size}) + end + + def save + File.open(File.join(directory, kml_name + file_extension), "w+") do |f| f.write(render) end if stop_areas.present? end |
