Skip to content

Instantly share code, notes, and snippets.

@kurtraschke
Created Dec 17, 2012
Embed
What would you like to do?
Find bounding box and convex hull of agency coverage (as WKT) for a OneBusAway TDS.
from mustaine.client import HessianProxy
from shapely.geometry import box
from shapely.ops import cascaded_union
service = HessianProxy("http://172.16.2.32:8080/onebusaway-transit-data-federation-webapp/remoting/transit-data-service")
agencies = service.getAgenciesWithCoverage()
boxes = []
for agency in agencies:
minx = agency.lon - (agency.lonSpan / 2)
miny = agency.lat - (agency.latSpan / 2)
maxx = agency.lon + (agency.lonSpan / 2)
maxy = agency.lat + (agency.latSpan / 2)
b = box(minx, miny, maxx, maxy)
boxes.append(b)
bbox = cascaded_union(boxes)
hull = bbox.convex_hull
print hull.wkt
(minx, miny, maxx, maxy) = hull.bounds
print "minLat: " + str(miny)
print "minLon: " + str(minx)
print "maxLat: " + str(maxy)
print "maxLon: " + str(maxx)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment