Skip to content

Instantly share code, notes, and snippets.

@ozjimbob
Created April 28, 2021 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozjimbob/d78eafd9c5030683e3f72b9ab5e502a0 to your computer and use it in GitHub Desktop.
Save ozjimbob/d78eafd9c5030683e3f72b9ab5e502a0 to your computer and use it in GitHub Desktop.
Kill Bad Polygons Dead
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