Election results in the London Borough of Sutton.
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

en2latlon.rb 818 B

12345678910111213141516171819202122232425262728293031
  1. # Convert OSGB36 eastings and northings to WGS84 latitudes and longitudes
  2. # $ ruby en2latlon.rb infile.csv > outfile.csv
  3. # http://adrianshort.org/2013/01/23/converting-eastings-and-northings-to-latitudes-and-longitudes-in-ruby/
  4. require 'csv'
  5. require_relative './OSGB36'
  6. lines = CSV.read(ARGV[0]) # read the whole file into an array of arrays
  7. easting_col = nil
  8. northing_col = nil
  9. (0..lines.size - 1).each do |i|
  10. if i == 0
  11. easting_col = lines[i].index("Eastings")
  12. northing_col = lines[i].index("Northings")
  13. lines[i] << "lat"
  14. lines[i] << "lng"
  15. else
  16. ll = OSGB36.en_to_ll(lines[i][easting_col].to_f, lines[i][northing_col].to_f)
  17. lines[i] << ll[:latitude]
  18. lines[i] << ll[:longitude]
  19. end
  20. end
  21. csv_str = CSV.generate do |csv|
  22. lines.each do |line|
  23. csv << line
  24. end
  25. end
  26. puts csv_str