From: | John Gray <jgray(at)azuli(dot)co(dot)uk> |
---|---|
To: | Don Isgitt <djisgitt(at)soundenergy(dot)com> |
Cc: | postgresql-general mailing list <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: point-in-polygon error |
Date: | 2002-06-18 22:06:12 |
Message-ID: | 1024437975.1716.26.camel@adzuki |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Stephan Szabo | 2002-06-18 22:10:53 | Re: Highly obscure and erratic |
Previous Message | Steve Atkins | 2002-06-18 21:57:12 | Web application frameworks supporting PostgreSQL |