Determine whether a shape is within a distance of a point

29 views
Skip to first unread message

Garrett Kajmowicz

unread,
May 18, 2011, 11:55:41 AM5/18/11
to Geospatial Python
I've grabbed the US ZIP code shape data which specifies ZIP codes as a
series of polygons, specified in latitude/longitude. I'm trying to
figure out how to tell if a ZIP code is within a distance of a fixed
point (eg. all ZIP codes within 50 miles of a specified airport).

I was going to take the approach that if all of the points defining
the area are within the specified range that the whole area is. There
are formula which will provide for the distance. However, this
requires processing all coordinates one-by-one. Is there a standard
library function which would do this processing on the shape for me,
preferably faster than something that I'd code by hand?

Dennis Follensbee Jr.

unread,
May 19, 2011, 11:45:32 AM5/19/11
to Geospatial Python
There are a couple great packages for doing spatial searching with
python:

http://pypi.python.org/pypi/Rtree/
http://gispython.org/shapely/docs/1.2/manual.html

I used these libraries and have experienced excellent results.

If you need something a little more robust, try PostGIS.

Dennis

Geospatial Python

unread,
May 22, 2011, 10:56:27 PM5/22/11
to Geospatial Python
Garrett,

Check out this post I did in 2009 on that exact topic:

http://geospatialpython.com/2009/02/zippity-doo-dah.html

One of the links on that post should do what you need. As Dennis
alluded to most people end up using a database of some sort to do this
efficiently as pro grammatically you would have to process all
coordinates. Otherwise you'll end up creating some kind of tiered
database-like structure anyway to not process all of the coordinates.

Let us know if you can't make it work.

- Joel
Reply all
Reply to author
Forward
0 new messages