Skip to content

Instantly share code, notes, and snippets.

@jnicho02
Created October 20, 2015 13:03
Show Gist options
  • Save jnicho02/490d46bafcc076d9db77 to your computer and use it in GitHub Desktop.
Save jnicho02/490d46bafcc076d9db77 to your computer and use it in GitHub Desktop.
converting government renewable energy planning permission csv to geojson
require 'csv'
require 'rgeo'
require 'proj4'
require 'rgeo/geo_json'
require 'json'
csv_text = File.read('Public_Database_-_Sept_2015.csv')
csv = CSV.parse(csv_text, :headers => true)
features = []
coder = RGeo::GeoJSON::Coder.new
csv.each do |row|
if row.to_hash["X-coordinate"]
rowhash = row.to_hash
x = rowhash["X-coordinate"].gsub(",","")
y = rowhash["Y-coordinate"].gsub(",","")
point = RGeo::Geographic.projected_factory(:srid => 27700).point(x, y)
feature = RGeo::GeoJSON::Feature.new(point, rowhash["Ref ID"], rowhash)
puts x + " " + y + " " + feature.geometry.as_text
features << feature
end
end
collection = RGeo::GeoJSON::FeatureCollection.new(features)
hash = coder.encode(collection)
File.write('Public_Database_-_Sept_2015.geojson', hash.to_json)
@jnicho02
Copy link
Author

not quite doing-the-do yet. Having some difficulties with the projection. Not helped by doing it on Windows...will try on my Mac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment