wiki:UsersWikiplpgsqlfunctionsDistance

Version 1 (modified by robe, 15 years ago) ( diff )

--
-- ST_DWithin_Sphere(lonlat-point, lonlat-point, radius-in-meters) returns boolean
--
-- Meters/Degree @ 60N: select 1/distance_sphere('POINT(0
60)','POINT(1 60)') = 1.79866403673916e-05
--
CREATE OR REPLACE FUNCTION ST_DWithin_Sphere(geometry, geometry, float8)
        RETURNS boolean
        AS 'SELECT $1 && ST_Expand($2,$3 * 1.79866403673916e-05) AND
$2 && ST_Expand($1,$3 * 1.79866403673916e-05) AND ST_Distance_Sphere($1, $2) < $3'
        LANGUAGE 'SQL' IMMUTABLE;


Note: See TracWiki for help on using the wiki.