Skip to content

Instantly share code, notes, and snippets.

@paulmwatson
Created May 23, 2022 07:39
Show Gist options
  • Save paulmwatson/f162901904b077c2140e23773ee2f48f to your computer and use it in GitHub Desktop.
Save paulmwatson/f162901904b077c2140e23773ee2f48f to your computer and use it in GitHub Desktop.
Convert multiple feature/layers in a geoJSON file to individual files
# Creates multiple files from one geojson file
require 'json'
file = File.read('data.geojson')
data_hash = JSON.parse(file)
data_hash['features'].each do |feature|
file_name = feature['properties']['OBJECTID']
File.open("#{file_name}.geojson", 'w') do |f|
f.write(feature.to_json)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment