I have two shapefiles with more than 1000 polygons each, and they represent two types of agricultural fields in the same area, which means they should be different types.

Some of the polygons are partly or completely overlapped - what I want to do is to delete those polygons - from both shapefiles - that are overlapped. Are there any methods for doing this in R using pachage sf or rgdal?

| improve this question | | | | |
  • 1
    Clarification needed. You have two shapefiles, call them A and B. You want to create two new shapefiles, A' and B' where A' is the set of all features from A that do not touch or overlap or intersect any features in B, and where B' is similar for features in B not overlapping any features in A? Or is there a possibility of features in A overlapping with other features in A? – Spacedman Jul 7 '19 at 19:18

Given two sets of features A and B coloured red and blue:


Then select only those from A that don't overlap any B and vice versa:

> Adash = A[lengths(st_intersects(A,B))==0,]
> Bdash = B[lengths(st_intersects(B,A))==0,]

this works by virtue of the element of the intersection list having zero-length when a feature has no intersections.

When plotted:


| improve this answer | | | | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.