]> granicus.if.org Git - postgis/commitdiff
Make the units of st_distance(geography, geography) meters
authorPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 2 Oct 2009 01:38:02 +0000 (01:38 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 2 Oct 2009 01:38:02 +0000 (01:38 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@4577 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/geography.h
postgis/geography_distance.c

index 8e1f3de3997a124876804fbb2832d2d26abc4e04..4aae1c6eb24a5aafae0dcd69e7cb56d70cb3b8c7 100644 (file)
@@ -9,6 +9,13 @@
  *
  **********************************************************************/
 
+/*
+** Spherical radius.
+** Moritz, H. (1980). Geodetic Reference System 1980, by resolution of the XVII General Assembly of the IUGG in Canberra.
+** http://en.wikipedia.org/wiki/Earth_radius
+*/
+
+#define WGS84_RADIUS 6371009.0
 
 /**********************************************************************
 **  GIDX structure. 
index 81713818bfc37939eeb73d09342b028ce91b525a..7a6e4b5385cf08583975a4b463b7448211e58a1c 100644 (file)
@@ -60,6 +60,7 @@ Datum geography_distance_sphere(PG_FUNCTION_ARGS)
        
        /* Read our tolerance value. */
        tolerance = PG_GETARG_FLOAT8(2);
+       tolerance = tolerance / WGS84_RADIUS;
 
        /* Calculate the distance */
        distance = lwgeom_distance_sphere(lwgeom1, lwgeom2, &gbox1, &gbox2, tolerance);
@@ -70,6 +71,8 @@ Datum geography_distance_sphere(PG_FUNCTION_ARGS)
                elog(ERROR, "Error in geography_distance_sphere calculation.");
                PG_RETURN_NULL();
        }
+       
+       distance = distance * WGS84_RADIUS;
 
        /* Clean up, but not all the way to the point arrays */
        lwgeom_release(lwgeom1);