Skip to content

Instantly share code, notes, and snippets.

@leoluyi
Forked from jwass/convert.py
Created January 16, 2017 05:38
Show Gist options
  • Save leoluyi/c64ddbcc478e0ea0e2642206a4e75d24 to your computer and use it in GitHub Desktop.
Save leoluyi/c64ddbcc478e0ea0e2642206a4e75d24 to your computer and use it in GitHub Desktop.
Simple Shapefile to GeoJSON converter. Using the shapefile from here: http://www.mass.gov/anf/research-and-tech/it-serv-and-support/application-serv/office-of-geographic-information-massgis/datalayers/senate2012.html it will result in an error "ValueError: Record's geometry type does not match collection schema's geometry type: 'Polygon' != 'Unk…
import fiona
import fiona.crs
def convert(f_in, f_out):
with fiona.open(f_in) as source:
with fiona.open(
f_out,
'w',
driver='GeoJSON',
crs = fiona.crs.from_epsg(4326),
schema=source.schema) as sink:
for rec in source:
sink.write(rec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment