[postgis-users] Re: point in polygon using operator &&

Rosangela Silva rosangela.silva at zenitpolar.com.br
Tue May 20 12:23:24 PDT 2003


Ok, Dave, It's works.
Only a comment is change "=" for "==" and 
...where the_geom && GeometryFromText('POINT(-45.69439 -23.5642)',-1) that works too.

Thanks
Rosângela
  Use this:

  SELECT continent_name

  FROM continent

  WHERE the_geom && GeometryFromText('BOX3D(-45.69439 -23.5642, -45.69439 
  -23.5642)'::box3d,-1);

        AND distance(the_geom,GeometryFromText('POINT(-45.69439 
  -23.5642)',-1)) ==0;


  The && uses the index and only works on the bounding box.  
  The distance function is much more accurate and works on the actual 
  geometries.  NOTE: for points that are really-really-close to the edge 
  of your polygon, the distance function may be slightly off .  It might 
  give 0 if the point is just outside the polygon, and it might give a 
  very small number if the point is just inside the polygon.  


  This problem will be solved very soon when GEOS is integrated into 
  postgis and you'll be able to use relate on the two geometries.

  dave


  ----- Original Message ----- 
  From: Rosangela Silva 
  To: postgis-users at postgis.refractions.net 
  Sent: Tuesday, May 20, 2003 3:53 PM
  Subject: point in polygon using operator &&


  Hello all,

  I'm trying to use the operator && to find the polygon
  that contains a point. (Are there other way to do this in PostGIS?)

  So, I create the select below: 

  SELECT continent_name 

  FROM continent 

  WHERE the_geom && GeometryFromText('BOX3D(-45.69439 -23.5642, -45.69439 -23.5642)'::box3d,-1); 


  How the point doesn't have a box, I repeat the same coordinates.
  The continent is the world continent table.

  The result was: South America, Oceania.

  I became surprise by Oceania and I saw that Oceania is a multpolygon geometry.
  When the PostGIS generate the box of Oceania polygons, the result are the box resultant
  of all box isolated polygons. By this, my point is in Oceania too.
  See the select bellow:

  gisdb=# select continent, box3D(the_geom) from continent where continent='Oceania';
   continent |                         box3d
  ---------------+--------------------------------------------------------
   Oceania   | BOX3D(-180 -52.5780563354492 0,180 28.2215194702148 0)

  In another case, but in this case I didn't understand why, the result get 2 polygons having the
  same point, but this point ins't in the border of two polygons (I visually have shure!). 

  gisdb=# SELECT nomemunicp, uf FROM brmuni WHERE the_geom && GeometryFromText
  ('BOX3D(-45.69439 -23.5642, -45.69439 -23.5642)'::box3d,-1);
    nomemunicp   | uf
  -----------------------+----
   PARAIBUNA     | SP
   CARAGUATATUBA | SP


  Thanks
  Rosângela
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20030520/6247ae0e/attachment.html>


More information about the postgis-users mailing list