[postgis-users] Finding intersection of polygon line with frame

David Blasby dblasby at refractions.net
Thu Oct 16 16:26:09 PDT 2003


Chris Faulkner wrote:
> This works fine. However, I would like to constrain the selection to only
> those polygons that cross the box3d. So any polygons that are wholly within,
> or entirely covering the box3d, then I would like to reject them. Only
> polygons whose lines cross the box3d should be included. How do I write such
> a query in postgis ?

Make sure you have GEOS installed and activated.

SELECT * FROM <table> WHERE
    the_Geom && <polygon> AND
    intersects(the_Geom, <polygon>) AND
    not(within(the_geom,<polygon>)

This will find any feature that intersects the polygon, but isnt inside it.

To find your <polygon>, either construct it yourself or you can have 
postgis construct it for you:

envelope(GeometryFromText('BOX3D(529000 179000,530000 180000)'::box3d,-1))




More information about the postgis-users mailing list