[postgis-users] Polygon contains with Lat/Lon

Michael O'Sullivan mos at i3sp.com
Tue Feb 25 04:06:24 PST 2003


Hi all,

I have a question on finding out whether a given point is contained by a 
polygon when using a geographic projection i.e. Lat/Long polygons.

I am currently using the dataset below

http://www.soest.hawaii.edu/pwessel/gshhs/gshhs.html

as a basis for performing isAtSea/OnLand queries.

The dataset is a set of polygons of lat/long positions. The data is 
quite detailed (polygons with over 100,000 points).

I have managed to convert the data to postgis format and loaded it into 
my database. I saw someone did this on the mailing list a year or two 
ago but the file they had provided was corrupted and gzip was unable to 
uncompress all the file. If anyone is interested in this data I can send 
you a perl script to parse the gshhs data sets and produce postgis copy 
files.

Anyway, I have been using the ~ operator to locate Polygons in my 
database which contain a point. Unfortunately the bounding box nature of 
the ~ operator is causing points to be contained by multiple countries, 
as the bounding box of the polygons end up including other countries 
(and ocean positions).

I have seen a few emails in the archive regarding truly_inside, and 
people questioning how to determine if a given point is inside a 
polygon. Having read the postgis doco on functions I can't see anything 
that looks like it will help me apart from truly_inside.

Looking at

truly_inside(geometryA,geometryB)

The doco says

returns true if any part of B is within the bounding box of A.

I have tried using this but I am not sure if it is OK to use this with 
Lat/Lon coords. I am seeing the opposite results to doco


I see it return true if any part of A is within the bounding box of B

navitag=# select summary(the_geom) from testtable where gid = 1;
                                 summary
-----------------------------------------------------------------------
  Object 0 is a POLYGON() with 1 rings
      + ring 0 has 169598 points

navitag=# select extent(the_geom) from testtable where gid =1;
                     extent
----------------------------------------------
  BOX3D(-179.99844 -34.83044 0,180 77.71958 0)
(1 row)

navitag=# select truly_inside(GeometryFromText('POINT(151 -33)',4269), 
the_geom) from testtable where gid = 1;
  truly_inside
--------------
  t
(1 row)

navitag=# select truly_inside(the_geom, GeometryFromText('POINT(151 
-33)',4269)) from testtable where gid = 1;
  truly_inside
--------------
  f
(1 row)


I see that the distance function returns 0 if a point is inside a 
polygon - but I am not in a cartesian coordinate space (I am in lat 
long) - so that isn't an option. I don't think projection into a 
cartesian corrdinate system is an option because the extent of these 
polygons is so large.

Can anybody suggest how I might go about this? Am I on the correct path 
with truly_inside?


Thanks in advance,

Michael

-- 
Michael O'Sullivan <mos at i3sp.com>
"A good man always knows his limitations" - HC




More information about the postgis-users mailing list