[postgis-users] Selecting geocoded postal codes within a given distance ( miles for example )

Paul Ramsey pramsey at refractions.net
Tue Dec 17 09:25:20 PST 2002


Then the fastest way to get something in operation is to calculate the 
miles/longitude value for somewhere in the south of Texas and use that 
everwhere. Construct query boxes in lat/lon using the (fixed) 
miles/latitude and miles/longitude values and then compare distances 
using distance_spheroid... the SQL will end up looking something like:

select * from postaltable where
   the_geom && BOX3D( X - R * Lon/Miles , Y - R * Lat/Miles , etc etc )
   and
   distance_spheroid( POINT( X Y ) , the_geom , SPHEROID ) < R

Note that I have completely bastardized the constructors for the various 
objects above in the interests of understandability. I assume you can 
fill out the details yourself...

P.

Hugh W. O'Brien wrote:
> Unfortunately, I must support all US postal codes so all of continental 
> US and it's territories.  I might also have to include support for 
> Canada in the future.


-- 
       __
      /
      | Paul Ramsey
      | Refractions Research
      | Email: pramsey at refractions.net
      | Phone: (250) 885-0632
      \_




More information about the postgis-users mailing list