Created
November 6, 2024 21:53
-
-
Save mhweber/1913d7dc26097aebfabd638cc63d9faf to your computer and use it in GitHub Desktop.
Filter overlapping sf polygon features in a spatial data frame in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # poly is any polygon spatial data frame | |
| overlap <- st_intersection(poly) | |
| overlap <- overlap[overlap$n.overlaps > 1, ] | |
| # The result of st_intersection contains a column called n.overlaps | |
| # that represents the number of overlaps for the resulting geometry. | |
| # If n.overlaps > 1 then multiple polygons are overlaping. | |
| overlap <- overlap |> | |
| dplyr::filter(grepl("POLYGON", st_geometry_type(geom))) |> | |
| dplyr::filter(as.numeric(st_area(overlap)) > 100) | |
| # This filtering reduces what is returned to only results that are of | |
| # polygon geometry type and with a significant area |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment