• You're one step from joining GIS Mapping Forum – Remote Sensing, Surveying & Software Solutions.
    Create a free account to post, follow threads, and never miss an update.  Sign up free →

Splitting polygons by lines using sf in R

geoscanpro126

Member
Joined
Jul 11, 2025
Messages
6
I'm currently working on a project in R with the sf package, and I need to figure out how to split a bunch of polygons using some intersecting lines. I've got a shapefile that contains various polygons and a separate layer of lines that run through them, and I want to cut the polygons along these lines.

Has anyone done this before? I've tried using st_split() and st_collection_extract() in a few different ways, but I'd really appreciate hearing what's worked for you. Also, if there are any specific issues or quirks I should keep an eye on, that'd be great.

Thanks in advance for any tips, code snippets, or resources you can share
 
I'm currently working on a project in R with the sf package, and I need to figure out how to split a bunch of polygons using some intersecting lines. I've got a shapefile that contains various polygons and a separate layer of lines that run through them, and I want to cut the polygons along these lines.

Has anyone done this before? I've tried using st_split() and st_collection_extract() in a few different ways, but I'd really appreciate hearing what's worked for you. Also, if there are any specific issues or quirks I should keep an eye on, that'd be great.

Thanks in advance for any tips, code snippets, or resources you can share
I've worked with st_split() and it should do the trick if your geometries are valid and both layers are in the same CRS. Have you tried running st_make_valid() on your polygons 1st or checked for multipart geometry issues? Also worth verifying if the lines intersect the polygons cleanly without hanging edges.
 
You have to make sure both your polygons and lines are in the same CRS and all the geometries are valid, most times when things don't split as expected, it's often because the lines aren't truly intersecting the polygons, even if they look like they do
 
@geoscanpro126 my first thought when st_split() doesn't behave as expected is always topology and single geometries. Make sure your lines are LINESTRING (not MULTILINESTRING if possible, or st_union() them if they form a single cutting path). And sometimes, processing polygons one by one helps if you're dealing with a MULTIPOLYGON layer
 
Back
Top