trainline-eu / stations

List of stations and associated metadata
Open Data Commons Open Database License v1.0
104 stars 128 forks source link

Round geo coordinates to 6 decimal places #1346

Closed ConscritNeuneu closed 2 months ago

ConscritNeuneu commented 2 months ago

More precise location doesn't make sense.

The following script was run:

require "csv"

CSV_PARAMETERS = {
  :headers    => true,
  :col_sep    => ';',
  :encoding   => 'UTF-8'
}

def decimal_places(decimal)
  decimal =~ /\A-?\d{1,3}(\.(\d+))?\z/

  ($2 || "").length
end

csv = CSV.read("stations.csv", **CSV_PARAMETERS)

csv.each do |row|
  %w(latitude longitude).each do |key|
    coord = row[key]
    if decimal_places(coord) > 6
      row[key] = "%.6f" % coord.to_f.round(6)
      puts "Fix #{row["name"]} (#{row['id']}) #{key}: #{coord} → #{row[key]}"
    end
  end
end

File.write("stations.csv", csv.to_s(write_headers: true, **CSV_PARAMETERS))
github-actions[bot] commented 2 months ago

Stations changed

Truncated