point-in-polygon error

Started by Don Isgittalmost 24 years ago3 messagesgeneral
Jump to latest
#1Don 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

#2Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Don Isgitt (#1)
Re: point-in-polygon error

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.

#3John Gray
jgray@azuli.co.uk
In reply to: Don Isgitt (#1)
Re: point-in-polygon error

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