diff -c -N -r --exclude=CVS /usr/local/src/postgres-cvs/contrib/earthdistance/Makefile earthdistance/Makefile *** /usr/local/src/postgres-cvs/contrib/earthdistance/Makefile Thu Sep 6 05:49:29 2001 --- earthdistance/Makefile Mon Sep 9 18:04:38 2002 *************** *** 1,4 **** ! # $Header: /projects/cvsroot/contrib/earthdistance/Makefile,v 1.11 2001/09/06 10:49:29 petere Exp $ subdir = contrib/earthdistance top_builddir = ../.. --- 1,4 ---- ! # $Header: /cvsroot/contrib/earthdistance/Makefile,v 1.11 2001/09/06 10:49:29 petere Exp $ subdir = contrib/earthdistance top_builddir = ../.. *************** *** 7,11 **** --- 7,12 ---- MODULES = earthdistance DATA_built = earthdistance.sql DOCS = README.earthdistance + REGRESS = earthdistance include $(top_srcdir)/contrib/contrib-global.mk diff -c -N -r --exclude=CVS /usr/local/src/postgres-cvs/contrib/earthdistance/README.earthdistance earthdistance/README.earthdistance *** /usr/local/src/postgres-cvs/contrib/earthdistance/README.earthdistance Mon Jun 19 09:01:20 2000 --- earthdistance/README.earthdistance Tue Sep 17 07:30:49 2002 *************** *** 1,3 **** --- 1,13 ---- + --------------------------------------------------------------------- + I corrected a bug in the geo_distance code where two double constants + were declared as int. I changed the distance function to use the + haversine formula which is more accurate for small distances. + I added a regression test to the package. I added a grant statement + to give execute access for geo_distance to public. + + Bruno Wolff III + September 2002 + --------------------------------------------------------------------- Date: Wed, 1 Apr 1998 15:19:32 -0600 (CST) From: Hal Snyder To: vmehr@ctp.com diff -c -N -r --exclude=CVS /usr/local/src/postgres-cvs/contrib/earthdistance/earthdistance.c earthdistance/earthdistance.c *** /usr/local/src/postgres-cvs/contrib/earthdistance/earthdistance.c Wed Mar 21 21:59:09 2001 --- earthdistance/earthdistance.c Mon Sep 9 18:04:38 2002 *************** *** 6,13 **** /* Earth's radius is in statute miles. */ ! const int EARTH_RADIUS = 3958.747716; ! const int TWO_PI = 2.0 * M_PI; double *geo_distance(Point *pt1, Point *pt2); --- 6,13 ---- /* Earth's radius is in statute miles. */ ! const double EARTH_RADIUS = 3958.747716; ! const double TWO_PI = 2.0 * M_PI; double *geo_distance(Point *pt1, Point *pt2); *************** *** 50,55 **** --- 50,56 ---- long2, lat2; double longdiff; + double sino; double *resultp = palloc(sizeof(double)); /* convert degrees to radians */ *************** *** 65,72 **** if (longdiff > M_PI) longdiff = TWO_PI - longdiff; ! *resultp = EARTH_RADIUS * acos ! (sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(longdiff)); return resultp; } --- 66,75 ---- if (longdiff > M_PI) longdiff = TWO_PI - longdiff; ! sino = sqrt(sin(fabs(lat1-lat2)/2.)*sin(fabs(lat1-lat2)/2.) + ! cos(lat1) * cos(lat2) * sin(longdiff/2.)*sin(longdiff/2.)); ! if (sino > 1.) sino = 1.; ! *resultp = 2. * EARTH_RADIUS * asin(sino); return resultp; } diff -c -N -r --exclude=CVS /usr/local/src/postgres-cvs/contrib/earthdistance/earthdistance.sql.in earthdistance/earthdistance.sql.in *** /usr/local/src/postgres-cvs/contrib/earthdistance/earthdistance.sql.in Thu Aug 16 17:24:43 2001 --- earthdistance/earthdistance.sql.in Tue Sep 17 07:33:09 2002 *************** *** 1,16 **** --------------- geo_distance ! DROP FUNCTION geo_distance (point, point); ! CREATE FUNCTION geo_distance (point, point) RETURNS float8 ! AS 'MODULE_PATHNAME' LANGUAGE 'c' ! WITH (isstrict); ! ! SELECT geo_distance ('(1,2)'::point, '(3,4)'::point); --------------- geo_distance as operator <@> - DROP OPERATOR <@> (point, point); CREATE OPERATOR <@> ( leftarg = point, rightarg = point, --- 1,12 ---- + begin; --------------- geo_distance ! CREATE OR REPLACE FUNCTION geo_distance (point, point) RETURNS float8 ! LANGUAGE 'c' IMMUTABLE STRICT AS 'MODULE_PATHNAME'; --------------- geo_distance as operator <@> CREATE OPERATOR <@> ( leftarg = point, rightarg = point, *************** *** 18,24 **** commutator = <@> ); ! -- ( 87.6, 41.8) is in Chicago ! -- (106.7, 35.1) is in Albuquerque ! -- The cities are about 1100 miles apart ! SELECT '(87.6,41.8)'::point <@> '(106.7,35.1)'::point; --- 14,24 ---- commutator = <@> ); ! -- ! -- By default this function is made executable by anyone. To restrict ! -- access by default, comment out the following grant command. ! -- ! ! grant execute on function geo_distance(point, point) to public; ! ! commit; diff -c -N -r --exclude=CVS /usr/local/src/postgres-cvs/contrib/earthdistance/expected/earthdistance.out earthdistance/expected/earthdistance.out *** /usr/local/src/postgres-cvs/contrib/earthdistance/expected/earthdistance.out Wed Dec 31 18:00:00 1969 --- earthdistance/expected/earthdistance.out Tue Sep 17 07:37:21 2002 *************** *** 0 **** --- 1,158 ---- + -- + -- Test earth distance functions + -- + -- + -- first, define the datatype. Turn off echoing so that expected file + -- does not depend on contents of earthdistance.sql or cube.sql. + -- + \set ECHO none + -- + -- Test getting the distance between two points using geo_distance. + -- + select geo_distance('(0,0)'::point,'(0,0)'::point)::numeric(20,5); + geo_distance + -------------- + 0.00000 + (1 row) + + select geo_distance('(0,0)'::point,'(180,0)'::point)::numeric(20,5); + geo_distance + -------------- + 12436.77274 + (1 row) + + select geo_distance('(0,0)'::point,'(0,90)'::point)::numeric(20,5); + geo_distance + -------------- + 6218.38637 + (1 row) + + select geo_distance('(0,0)'::point,'(90,0)'::point)::numeric(20,5); + geo_distance + -------------- + 6218.38637 + (1 row) + + select geo_distance('(0,0)'::point,'(1,0)'::point)::numeric(20,5); + geo_distance + -------------- + 69.09318 + (1 row) + + select geo_distance('(0,0)'::point,'(0,1)'::point)::numeric(20,5); + geo_distance + -------------- + 69.09318 + (1 row) + + select geo_distance('(0,30)'::point,'(1,30)'::point)::numeric(20,5); + geo_distance + -------------- + 59.83626 + (1 row) + + select geo_distance('(0,30)'::point,'(0,31)'::point)::numeric(20,5); + geo_distance + -------------- + 69.09318 + (1 row) + + select geo_distance('(0,60)'::point,'(1,60)'::point)::numeric(20,5); + geo_distance + -------------- + 34.54626 + (1 row) + + select geo_distance('(0,60)'::point,'(0,61)'::point)::numeric(20,5); + geo_distance + -------------- + 69.09318 + (1 row) + + select geo_distance('(87.6,41.8)'::point,'(106.7,35.1)'::point)::numeric(20,5); + geo_distance + -------------- + 1129.18983 + (1 row) + + select (geo_distance('(87.6,41.8)'::point,'(106.7,35.1)'::point)*5280.*12.*2.54/100.)::numeric(20,5); + numeric + --------------- + 1817254.87730 + (1 row) + + -- + -- Test getting the distance between two points using the <@> operator. + -- + select ('(0,0)'::point <@> '(0,0)'::point)::numeric(20,5); + numeric + --------- + 0.00000 + (1 row) + + select ('(0,0)'::point <@> '(180,0)'::point)::numeric(20,5); + numeric + ------------- + 12436.77274 + (1 row) + + select ('(0,0)'::point <@> '(0,90)'::point)::numeric(20,5); + numeric + ------------ + 6218.38637 + (1 row) + + select ('(0,0)'::point <@> '(90,0)'::point)::numeric(20,5); + numeric + ------------ + 6218.38637 + (1 row) + + select ('(0,0)'::point <@> '(1,0)'::point)::numeric(20,5); + numeric + ---------- + 69.09318 + (1 row) + + select ('(0,0)'::point <@> '(0,1)'::point)::numeric(20,5); + numeric + ---------- + 69.09318 + (1 row) + + select ('(0,30)'::point <@> '(1,30)'::point)::numeric(20,5); + numeric + ---------- + 59.83626 + (1 row) + + select ('(0,30)'::point <@> '(0,31)'::point)::numeric(20,5); + numeric + ---------- + 69.09318 + (1 row) + + select ('(0,60)'::point <@> '(1,60)'::point)::numeric(20,5); + numeric + ---------- + 34.54626 + (1 row) + + select ('(0,60)'::point <@> '(0,61)'::point)::numeric(20,5); + numeric + ---------- + 69.09318 + (1 row) + + select ('(87.6,41.8)'::point <@> '(106.7,35.1)'::point)::numeric(20,5); + numeric + ------------ + 1129.18983 + (1 row) + + select (('(87.6,41.8)'::point <@> '(106.7,35.1)'::point)*5280.*12.*2.54/100.)::numeric(20,5); + numeric + --------------- + 1817254.87730 + (1 row) + diff -c -N -r --exclude=CVS /usr/local/src/postgres-cvs/contrib/earthdistance/sql/earthdistance.sql earthdistance/sql/earthdistance.sql *** /usr/local/src/postgres-cvs/contrib/earthdistance/sql/earthdistance.sql Wed Dec 31 18:00:00 1969 --- earthdistance/sql/earthdistance.sql Tue Sep 17 07:35:34 2002 *************** *** 0 **** --- 1,45 ---- + -- + -- Test earth distance functions + -- + + -- + -- first, define the datatype. Turn off echoing so that expected file + -- does not depend on contents of earthdistance.sql or cube.sql. + -- + \set ECHO none + \i earthdistance.sql + \set ECHO all + + -- + -- Test getting the distance between two points using geo_distance. + -- + + select geo_distance('(0,0)'::point,'(0,0)'::point)::numeric(20,5); + select geo_distance('(0,0)'::point,'(180,0)'::point)::numeric(20,5); + select geo_distance('(0,0)'::point,'(0,90)'::point)::numeric(20,5); + select geo_distance('(0,0)'::point,'(90,0)'::point)::numeric(20,5); + select geo_distance('(0,0)'::point,'(1,0)'::point)::numeric(20,5); + select geo_distance('(0,0)'::point,'(0,1)'::point)::numeric(20,5); + select geo_distance('(0,30)'::point,'(1,30)'::point)::numeric(20,5); + select geo_distance('(0,30)'::point,'(0,31)'::point)::numeric(20,5); + select geo_distance('(0,60)'::point,'(1,60)'::point)::numeric(20,5); + select geo_distance('(0,60)'::point,'(0,61)'::point)::numeric(20,5); + select geo_distance('(87.6,41.8)'::point,'(106.7,35.1)'::point)::numeric(20,5); + select (geo_distance('(87.6,41.8)'::point,'(106.7,35.1)'::point)*5280.*12.*2.54/100.)::numeric(20,5); + + -- + -- Test getting the distance between two points using the <@> operator. + -- + + select ('(0,0)'::point <@> '(0,0)'::point)::numeric(20,5); + select ('(0,0)'::point <@> '(180,0)'::point)::numeric(20,5); + select ('(0,0)'::point <@> '(0,90)'::point)::numeric(20,5); + select ('(0,0)'::point <@> '(90,0)'::point)::numeric(20,5); + select ('(0,0)'::point <@> '(1,0)'::point)::numeric(20,5); + select ('(0,0)'::point <@> '(0,1)'::point)::numeric(20,5); + select ('(0,30)'::point <@> '(1,30)'::point)::numeric(20,5); + select ('(0,30)'::point <@> '(0,31)'::point)::numeric(20,5); + select ('(0,60)'::point <@> '(1,60)'::point)::numeric(20,5); + select ('(0,60)'::point <@> '(0,61)'::point)::numeric(20,5); + select ('(87.6,41.8)'::point <@> '(106.7,35.1)'::point)::numeric(20,5); + select (('(87.6,41.8)'::point <@> '(106.7,35.1)'::point)*5280.*12.*2.54/100.)::numeric(20,5);