Skip to content

Instantly share code, notes, and snippets.

@schuyler
Forked from mager/get-centroid.py
Created June 22, 2011 17:46
Show Gist options
  • Save schuyler/1040656 to your computer and use it in GitHub Desktop.
Save schuyler/1040656 to your computer and use it in GitHub Desktop.
Find centroid for Polygon
from shapely.geometry import asShape
from simplegeo import context
client = context.Client('your-key','your-secret')
context_response = client.get_context(37.775255,-122.40289)
neighborhoods = [feature for feature in context_response['features'] if feature['classifiers'][0]['category'] == 'Neighborhood']
if neighborhoods:
neighborhood_handle = neighborhoods[0]['handle']
neighborhood_boundary = asShape(client.get_feature(neighborhood_handle).to_dict()['geometry'])
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