[postgis-users] (no subject)

Mark Cave-Ayland m.cave-ayland at webbased.co.uk
Tue Mar 16 03:16:03 PST 2004


> -----Original Message-----
> From: postgis-users-bounces at postgis.refractions.net 
> [mailto:postgis-users-bounces at postgis.refractions.net] On 
> Behalf Of David Sharp
> Sent: 16 March 2004 09:31
> To: postgis-users at postgis.refractions.net
> Subject: [postgis-users] (no subject)
> 
> 
> Hi , 
> 
> I just have a quick question , I am developing a gps/gis 
> application at the moment and I am using postgresql as my 
> database with postgis as a spatial extension. 
> I was wondering is it possible to calculate the distance 
> between an external point and a polygon . I am using lat/lon 
> as units . The error I am receiving is
> > 
> > when I enter
> > 
> > SELECT ('(10.9,-62.)'::point <@> '((18.418 -65.772,17.957 
> > -65.832,18.0515 -66.865,18.361 -66.986,18.418 
> > -65.772))'::polygon)::numeric(20,5);
> > 
> > 
> > ERROR:  Bad polygon external representation '((18.418 
> -65.772,17.957 
> > -65.832,18.0515 -66.865,18.361 -66.986,18.418 -65.772))'
> > 
> > Any help much appreciated
> > 
> > David Sharp


Hi David,

>From the query you've given above, it looks as if even though you have
the PostGIS spatial extensions installed, you are still using the
internal PostgreSQL geometric operators. I can't find the <@> operator
in the PostgreSQL documentation, but the format of the data vertices is
different which is why the polygon fails above. If you are not working
on an existing system then I would highly recommend using the PostGIS
functions over the internal ones :) Please take a good look at the
online documentation at http://postgis.refractions.net/docs/ if you're
not sure about this. 

The main advantage of using the PostGIS functions is that they are aware
of the projection of the data that you are working on, unlike the
unbuilt PostgreSQL geometric operators. As an example, the following
PostGIS query should give you what you need:

select distance(geometryfromtext('POINT(10.9 -62.0)', -1),
geometryfromtext('POLYGON((18.418 -65.772,17.957 -65.832,18.0515
-66.865,18.361 -66.986,18.418 -65.772))', -1));


Note that the distance returned will be in the units you are working in,
e.g. decimal degrees. If you want to convert it to metres/feet then you
will need to alter the query to reproject the lat/long points from a
sphere to a flat distance using the PostGIS distance_spheroid()
function.


Cheers,

Mark.

---

Mark Cave-Ayland
Webbased Ltd.
Tamar Science Park
Derriford
Plymouth
PL6 8BX
England

Tel: +44 (0)1752 764445
Fax: +44 (0)1752 764446


This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender. You
should not copy it or use it for any purpose nor disclose or distribute
its contents to any other person.





More information about the postgis-users mailing list