Last active
August 29, 2015 14:07
-
-
Save joshuajnoble/ca73a1f8f92b77d382ee to your computer and use it in GitHub Desktop.
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 | |
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