[postgis-users] Splitting a Polygon with a Linestring

Andy Anderson aanderson at amherst.edu
Wed May 21 19:55:41 PDT 2008


If you use ST_Intersection(geometry_line, geometry_polygon) to return  
"a geometry that represents the point set intersection of the  
Geometries", the user-drawn line will be truncated to just the  
portion(s) that fall within the polygon. My tests results are either a  
LINESTRING or MULTILINESTRING, though where I expect a POINT it  
returns GEOMETRYCOLLECTION EMPTY (possibly due to round-off).

(P.S. you'll also need to allow for the case where the user leaves one  
end of the line inside the polygon, by extending it to the edge I  
would imagine.)

-- Andy

On May 21, 2008, at 2:21 PM, James Beaudoin wrote:

> I think the steps below will work but I have one question. I am  
> creating an application that allows a user to split a polygon by  
> drawing a linestring across the polygon they wish to change. The  
> crossing linestring has parts that are outside the polygon and I  
> want to remove that before I geomunion. What's the easiest way to do  
> that?
>
> - extract the lines that make up the polygon
> - add to this your crossing linestring
> - geomunion the lines together.
> - polygonize the union-ed set
>
> Thanks,
>
> Jim



More information about the postgis-users mailing list