Created
October 20, 2015 13:03
-
-
Save jnicho02/490d46bafcc076d9db77 to your computer and use it in GitHub Desktop.
converting government renewable energy planning permission csv to geojson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not quite doing-the-do yet. Having some difficulties with the projection. Not helped by doing it on Windows...will try on my Mac