[GIS] Converting from kilometers to degrees distances

coordinate systemdistancepostgis

We have geometries in a Postgis database with SRID WGS84 and we have found lookups directly in degrees to be much faster than in kilometres, because the database can skip the projections I would think.

So, having a reference point in coordinates and a distance threshold in kilometres, is there a somewhat precise way to convert the distance to degrees for the lookup?

Example: Finding all locations within 10 Km of POINT(-3, 40). How do I convert the 10 Km to a degree value?

Best Answer

The length of degree in north-south is about the same so you could use 1/110574 degree/meter as a factor. However, the farther to south or north you go the bigger the error is in east-west direction.

For example, take these two shapes which have a 1 degree buffer in EPSG:4326 transformed into EPSG:32630 (UTM zone 30N). First one is from 40°N and the second from higher north at 70°N.

SELECT ST_Transform(ST_Buffer(ST_GeomFromText('POINT (-3 40)',4326),1),32630);
SELECT ST_Transform(ST_Buffer(ST_GeomFromText('POINT (-3 70)',4326),1),32630);

Draw them side by side and it is easy to see that in UTM projection the area of the degree buffer is oval and it gets quite narrow at 70°N. The height of both ovals is about 220 km and widths at 40° and 70° are about 170 km and 80 km, respectively. I wouldn't call even the oval at 40°N as somewhat precise. For more accurate results you can use this calculator http://www.csgnetwork.com/degreelenllavcalc.html

enter image description here