From b60e4037f779d0acd2c802fa9a6c73e7a493b49a Mon Sep 17 00:00:00 2001 From: "yama@muteki" Date: Sun, 5 Jun 2016 18:05:42 +0900 Subject: [PATCH] Simplify coordinates in seeds.rb --- app/helpers/application_helper.rb | 5 ++--- db/seeds.rb | 5 +++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5a2fb91..0a12046 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -23,9 +23,8 @@ def build_routes(bus_routes) { id: bus_route.id, tracks: bus_route.bus_route_tracks.map do |track| - coordinates = track.coordinates.map { |coordinate| { x: coordinate[0], y: coordinate[1] } } - SimplifyRb.simplify(coordinates, 0.0001).map do |coordinate| - { lat: coordinate[:x], lng: coordinate[:y] } + track.coordinates.map do |coordinate| + { lat: coordinate[0], lng: coordinate[1] } end.compact end } diff --git a/db/seeds.rb b/db/seeds.rb index f8a2dee..98f5e33 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -15,8 +15,9 @@ def load_bus_routes xml_path bus_route_track_progress = ProgressBar.create(title: "BusRouteTrack", total: doc.css('Curve').count, format: '%t: %J%% |%B|') doc.css('Curve').each do |node| gml_id = node['id'] - coordinates = node.at('posList').text.strip.each_line.map { |line| line.split.map(&:to_f) } - bus_route_track = BusRouteTrack.create(gml_id: "#{xml_path}/#{gml_id}", coordinates: coordinates) + coordinates = node.at('posList').text.strip.each_line.map { |line| { x: line.split[0].to_f, y: line.split[1].to_f } } + simplified_coordinates = SimplifyRb.simplify(coordinates, 0.0001).map { |c| [c[:x], c[:y]] } + bus_route_track = BusRouteTrack.create(gml_id: "#{xml_path}/#{gml_id}", coordinates: simplified_coordinates) bus_route_track_progress.increment end