Created
April 28, 2021 02:30
-
-
Save ozjimbob/d78eafd9c5030683e3f72b9ab5e502a0 to your computer and use it in GitHub Desktop.
Kill Bad Polygons Dead
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
remove_invalid_poly <- function(xx){ | |
to_fix=c() | |
for(i in 1:nrow(xx)){ | |
mn <- min(sapply(st_geometry(xx)[[i]], function(x) nrow(x[[1]]))) | |
if(mn < 4){ | |
to_fix <- c(to_fix,i) | |
} | |
} | |
for(fix_list in to_fix){ | |
aa = st_geometry(xx)[[fix_list]] | |
to_remove = c() | |
for(i in 1:length(aa)){ | |
nr <- nrow(aa[[i]][[1]]) | |
if(nr<4){ | |
to_remove <- c(to_remove,i) | |
} | |
} | |
to_remove <- rev(to_remove) | |
for(i in to_remove){ | |
st_geometry(xx)[[fix_list]][[i]]<-NULL | |
} | |
} | |
return(xx) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment