Skip to content

Instantly share code, notes, and snippets.

@joshuajnoble
Last active August 29, 2015 14:07
Show Gist options
  • Save joshuajnoble/ca73a1f8f92b77d382ee to your computer and use it in GitHub Desktop.
Save joshuajnoble/ca73a1f8f92b77d382ee to your computer and use it in GitHub Desktop.
import json
from shapely.geometry import Polygon
from shapely.geometry import MultiPolygon
with open("all_simplified.geojson") as f:
data = json.load(f)
for feature in data['features']:
print feature['properties']['GEOID']
if feature['geometry']['type'] == "MultiPolygon":
polys = []
for coordinateSet in feature['geometry']['coordinates']:
for coordinate in coordinateSet:
if len(coordinate) > 0:
polygon = Polygon(coordinate)
polys.append(polygon)
mPolygon = MultiPolygon(polys)
print feature['properties']['GEOID']+"," + str(mPolygon.area) + "," + str(mPolygon.centroid.x) + "," + str(mPolygon.centroid.y)
else:
for coordinate in feature['geometry']['coordinates']:
if len(coordinate) > 0:
polygon = Polygon(coordinate)
print feature['properties']['GEOID']+"," + str(polygon.area) + "," + str(polygon.centroid.x) + "," + str(polygon.centroid.y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment