Skip to content

Instantly share code, notes, and snippets.

@jwass
Created August 15, 2013 21:52
Show Gist options
  • Save jwass/6245313 to your computer and use it in GitHub Desktop.
Save jwass/6245313 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