Skip to content

Instantly share code, notes, and snippets.

View schuyler's full-sized avatar

Schuyler Erle schuyler

View GitHub Profile
@schuyler
schuyler / get-centroid.py
Created June 22, 2011 17:46 — forked from mager/get-centroid.py
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