[postgis-users] distance() Unit's

Alex Mayrhofer axelm-postgis at nona.net
Mon Jan 9 00:47:31 PST 2006


Adam wrote:
> I'm finding all the cities within a certian distance using the DISTANCE 
> function.
> 
> What is the unit of measurement for the distance?
> Can it be set to miles or feet?

Hi Adam,

the units of the result are the units of the original data. If you are using 
lat/lon data, the results will be in those "latlon" units (which means that 
the actual distance will vary by latitude).

> I checked the documentation but didn't find anything.
> 
> geo=# SELECT name FROM city_locations WHERE distance (the_geom, 'POINT( 
> -88.0501 41.8616 )' ) < 0.1;

If you need "proper" distances you will either need to reproject the map 
data from lat/lon, eg. into UTM. See the documentation about transform() on 
how to do this.

Or: you may also want to look into the "distance_sphere()" and 
"distance_spheroid()" functions - a query using this would probably look like

SELECT name, distance_sphere(the_geom, 'POINT(-88.0501 41.8616)') FROM 
city_locations WHERE expand('POINT(-88.0501 41.8616)', 0.1) && the_geom AND 
distance_sphere(the_geom, 'POINT(-88.0501 41.8616)') < 1000;

(disclaimer: untested - should return all cities less than 1000 meters from 
the given POINT - you need to check the expand() distance for it's relations 
to the maximum distance... This would also make use of on index over the_geom)

cheers

alex mayrhofer
--
http://nona.net/features/map/



More information about the postgis-users mailing list