[postgis-users] Help with spatial query

Carl Anderson carl.anderson at vadose.org
Tue Apr 5 18:24:47 PDT 2005


Brent Wood wrote:

>I'm trying to make sense of the various spatial operators. I need to join a
>table of cells to a table of lines, to create a table where there is a record
>for each case where a line passes entirely or partially through a cell.
>
>Looking at the OGC specs was a bit of help, but can anyone explain the
>difference between the intersects, overlaps & crosses functions:
>
>ie:
>
>select 
>.... 
>where
>  lines.geom && cell.geom and
><one of>
>  intersects(lines.geom, cell.geom)
>  overlaps(lines.geom, cell.geom)
>  crosses(lines.geom, cells.geom)
>
>I figure I should be using crosses for this query, but don't undertand the
>distinction between these.  
>  
>
L -   references the Line geometry
A -  references the cell, Polygon (area) geometry

intersects (L,A)  -  line and polygon (cell) touch or overlay in any way
overlaps (L,A) - is not defined for a line vs polygon  test
crosses (L,A) - line is part in and part out of the polygon, but not 
wholly inside
within (L,A) - the line is wholly inside the polygon
contains (A,L) - the line is wholly inside the polygon

you may want 
    intersects (lines.geom, cells.geom)
or if you want to ignore the touches only relationship
   ( crosses (lines.geom, cells.geom) or within(lines.geom, cells.geom) )
or
   ( intersects (lines.geom, cells.geom) and not touches(lines.geom, 
cells.geom) )


C.

>
>Thanks,
>
>  Brent Wood
>_______________________________________________
>postgis-users mailing list
>postgis-users at postgis.refractions.net
>http://postgis.refractions.net/mailman/listinfo/postgis-users
>  
>




More information about the postgis-users mailing list