Skip to content
Snippets Groups Projects
Commit 7f690408 authored by Francesco Sabatini's avatar Francesco Sabatini
Browse files

A98 - optimized for multipolygons

parent 681cfd94
Branches main
No related tags found
No related merge requests found
......@@ -60,9 +60,13 @@ PredExtr <- function(x.shp, myfunction=NA, output=NA,
toassign <- header.shp[i.toassign,]
print(paste(length(toassign), "plots not matched directly - seek for NN"))
if(length(toassign)>0){
## explode multipolygon
mypredictor.expl <- explode(mypredictor) %>%
as_Spatial()
# Crack if multipolygon
if(any( (st_geometry_type(mypredictor %>% st_as_sf)) == "MULTIPOLYGON")) {
## explode multipolygon
mypredictor.expl <- explode(mypredictor) %>%
as_Spatial()
} else {
mypredictor.expl <- mypredictor}
nearest <- foreach(i=1:length(toassign), .packages=c('raster'), .combine=rbind) %dopar% {
print(i)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment