Created
June 21, 2011 22:39
-
-
Save mager/1039125 to your computer and use it in GitHub Desktop.
Find centroid for Polygon
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
from itertools import ifilter | |
from shapely.geometry import Polygon | |
from simplegeo import context | |
client = context.Client('your-key','your-secret') | |
context_response = client.get_context(37.775255,-122.40289) | |
neighborhood = next(ifilter(lambda feature: feature['classifiers'][0]['category'] == 'Neighborhood', context_response['features']), None) | |
neighborhood_handle = neighborhood['handle'] | |
neighborhood_boundary = Polygon(client.get_feature(neighborhood_handle).to_dict()['geometry']['coordinates'][0]) | |
centroid = neighborhood_boundary.centroid.wkt | |
print centroid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment