Re: point-in-polygon error - Mailing list pgsql-general

From John Gray
Subject Re: point-in-polygon error
Date
Msg-id 1024437975.1716.26.camel@adzuki
Whole thread Raw
In response to point-in-polygon error  (Don Isgitt <djisgitt@soundenergy.com>)
List pgsql-general
On Tue, 2002-06-18 at 21:03, Don Isgitt wrote:
> No response to my first plea; maybe this time.
>
> Hi.
>
> I am trying to determine if some lat/longs stored in a database are
> contained within a defined polygon using the very nice builtin operators
>
> and types of postgresql; to wit,
>
> gds2=> select count(*) from master where point '(latitude,longitude)' @
> polygon
> '((10200000),(3187500,10262500),(3112500,10230000),(3112500,10187500),(3200000,10200000))';
>
> ERROR:  Bad point external representation '(latitude,longitude)'
> ERROR:  Bad point external representation '(latitude,longitude)'
>

The problem is that the string '(latitude,longitude)' is a string and
therefore the latitude and longitude values aren't substituted. The
following appears to work for me (in a recent version):

SELECT COUNT(*) FROM master
     WHERE point(latitude,longitude) @
'((3200000,10200000),
(3187500,10262500),
(3112500,10230000),
(3112500,10187500),
(3200000,10200000))'::polygon;

You could use various other forms - but this is a simple syntax that
seems to work.

There have been recent discussions about the polygon intersection
operators (check archives). I believe they may only check the case where
the point lies in the containing rectangular bounding box of the polygon
(full polygon inclusion is a tough mathematical problem, apparently).

> I have tried several variations on this theme to no avail. What am I
> doing wrong?
>
> I am using version 6.5.2, latitude and longitude are float.
>
I would advise you to upgrade -6.5.2 is a very old version (current is
7.2.1). If you are interested in geometric/geographic operators and
types for postgres, you could also look at PostGIS (
http://postgis.refractions.net ).

I hope this helps.


Regards

John

--
John Gray
Azuli IT
www.azuli.co.uk



pgsql-general by date:

Previous
From: Steve Atkins
Date:
Subject: Web application frameworks supporting PostgreSQL
Next
From: "Ian Harding"
Date:
Subject: CAST(null as date)...