-
-
Save valdezm/dd606c1a7a9de8658df9b1fa26102b04 to your computer and use it in GitHub Desktop.
Convert shapefile to GeoJSON with ogr and Python
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
import json | |
import ogr | |
driver = ogr.GetDriverByName('ESRI Shapefile') | |
shp_path = r'C:\GIS\Temp\Counties.shp' | |
data_source = driver.Open(shp_path, 0) | |
fc = { | |
'type': 'FeatureCollection', | |
'features': [] | |
} | |
lyr = data_source.GetLayer(0) | |
for feature in lyr: | |
fc['features'].append(feature.ExportToJson(as_object=True)) | |
with open('counties.json', 'wb') as f: | |
json.dump(fc, f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment