Skip to content

Instantly share code, notes, and snippets.

@zbrox
Created February 27, 2013 21:17
Show Gist options
  • Save zbrox/5051814 to your computer and use it in GitHub Desktop.
Save zbrox/5051814 to your computer and use it in GitHub Desktop.
Convert a GeoJSON file from RT90 (Swedish standard) coordinate system to WGS84
require 'rubygems'
require 'json'
require "swedishgrid"
def convert(coords)
grid = SwedishGrid.new(:rt90)
reversed = grid.grid_to_geodetic(coords[1], coords[0])
[reversed[1], reversed[0]]
end
file_name = 'rt90.geojson'
file = File.open(file_name, "r")
contents = file.read
geo_json = JSON.parse(contents)
geo_json['features'].each do |el|
el['geometry']['coordinates'].each do |polygon|
print '.'
polygon.map! do |coords|
if coords[0].is_a? Array
coords.map! do |c|
convert(c)
end
coords
else
convert(coords)
end
end
end
end
file = File.open(file_name, "w")
file.write(geo_json.to_json)
puts 'done!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment