point-in-polygon error
point-in-polygon error
От:
Don Isgitt <djisgitt@soundenergy.com>
Дата:
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 '( (3200000,10200000),(3187500,10262500),(3112500,10230000),(3112500,10187500),(3200000,10200000))'; ERROR: Bad point external representation '(latitude,longitude)' ERROR: Bad point external representation '(latitude,longitude)' 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. Thank you for your help. Don Isgitt
Re: point-in-polygon error
От:
Stephan Szabo <sszabo@megazone23.bigpanda.com>
Дата:
On Tue, 18 Jun 2002, 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 > '( > (3200000,10200000),(3187500,10262500),(3112500,10230000),(3112500,10187500),(3200000,10200000))'; > > ERROR: Bad point external representation '(latitude,longitude)' > ERROR: Bad point external representation '(latitude,longitude)' > > 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 guess that point '...' would be for point literals not a conversion to point. On my current machine, a function point(double, double) is defined which might do what you want.
Re: point-in-polygon error
От:
John Gray <jgray@azuli.co.uk>
Дата:
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