Skip to content

Instantly share code, notes, and snippets.

@mager
Created June 21, 2011 22:39
Show Gist options
  • Save mager/1039125 to your computer and use it in GitHub Desktop.
Save mager/1039125 to your computer and use it in GitHub Desktop.
Find centroid for Polygon
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