Skip to content

Commit

Permalink
Simplify coordinates in seeds.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
yamamuteki committed Jun 5, 2016
1 parent 81e7fba commit b60e403
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 2 additions & 3 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 3 additions & 2 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b60e403

Please sign in to comment.