[postgis-users] GeomFromText in a user function.

Charles E. Deaton CDeaton at corp.realcomp.com
Tue Apr 26 10:46:01 PDT 2011


I'm going to apologize up front for being a nood.

 

I have been trying to create a user function that I can call as needed
by passing in bbox coordinates. I have the standard SQL working as show
below;

 

SELECT *

FROM "MyTable" t

WHERE WITHIN(

GeomFromText('POLYGON((5 1, 8 4, 7 3, 6 2, 5 1))'),t.geom);

 

The above runs fine, they are not valid values based on the geom column
is based on lat/lon.

 

When I place it in a PostgreSQL function it keeps telling me "type
"geomfromtext" does not exist".

I have run out of ideas and can't find a lot on the net about PostgreSQL
function similar to this. Below is my last attempt:

 

CREATE OR REPLACE FUNCTION fn_Poly(double precision, double precision,
double precision, double precision, double precision, double precision,
double precision, double precision)

RETURNS SETOF " MyTable" AS

'SELECT *

FROM " MyTable" t

WHERE WITHIN(

GeomFromText('' || '''''''' || ''''POLYGON(('' ||

                $5 || '' '' || $1 || '', '' ||

                $8 || '' '' || $4 || '', '' ||

                $7 || '' '' || $3 || '', '' ||

                $6 || '' '' || $2 || '', '' ||

                $5 || '' '' || $1 ||

                ''))'')'''' || '''',t.geom)'

 

LANGUAGE sql;

 

Any help would be greatly appreciated. 

 

Charlie

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


More information about the postgis-users mailing list