From: Paul Ramsey Date: Fri, 2 Oct 2009 01:38:02 +0000 (+0000) Subject: Make the units of st_distance(geography, geography) meters X-Git-Tag: 1.5.0b1~433 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=51e0a35518e387791ec65af8be089294cebf69a2;p=postgis Make the units of st_distance(geography, geography) meters git-svn-id: http://svn.osgeo.org/postgis/trunk@4577 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/postgis/geography.h b/postgis/geography.h index 8e1f3de39..4aae1c6eb 100644 --- a/postgis/geography.h +++ b/postgis/geography.h @@ -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. diff --git a/postgis/geography_distance.c b/postgis/geography_distance.c index 81713818b..7a6e4b538 100644 --- a/postgis/geography_distance.c +++ b/postgis/geography_distance.c @@ -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);