[postgis-users] Newbie questions on what geometry to use

mark thomas javaguru at bellsouth.net
Wed Jul 5 07:45:24 PDT 2006


Chris, 

Don't forget that the spatial functions perform calculations in the
units of the input geometries, so for example if you have a point
geometry in decimal degrees and you call Buffer(the_geom, 1) it will
buffer the input geometry by 1 decimal degree.  You'll have to convert
your input (miles) to the correct units (decimal degrees).  To save you
some time, here are the functions in PL/PGSQL:


-- function to convert miles into decimal degrees
create or replace function convertMilesToDecimalDegrees(numeric) returns numeric as $$
begin
    -- $1 = radius in miles
    -- x = ($1 * 63360) = convert to meters (i.e. 63360 meters/mile)
    -- x = (x * 0.0254) = convert to inches (i.e. 0.0254 inches/meter)
    -- x = (x / 1852) = convert to nautical miles (i.e. 1852 meters/nautical mile)
    -- x = (x / 60) = convert to decimal degrees of latitude =
    --      (i.e. 1 nautical mile = 1 decimal minute; therefore nautical miles/60 = decimal degrees
    return (((($1 * 63360) * 0.0254) / 1852) / 60);
end;
$$ language plpgsql;

--function to buffer a geometry by a radius whose value is specified in miles
create or replace function getBufferedGeometry(geometry,numeric) returns geometry as $$
declare g geometry;
begin
    select Buffer($1,convertMilesToDecimalDegrees($2)) into g;
    return g;
end;
$$ language plpgsql;


Hope this helps.

Regards,

Mark Thomas
 

On Tue, 2006-07-04 at 12:00 -0700,
postgis-users-request at postgis.refractions.net wrote:

> [postgis-users] Newbie questions on what geometry to use

Mark Thomas
Senior Software Engineer
Awarix Corporation
mthomas at awarix.com
http://www.awarix.com

"Commit to the Lord whatever you do, 
    and your plans will succeed." - Proverbs 16:3


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20060705/8e1e42ad/attachment.html>


More information about the postgis-users mailing list