我有一些大的shapefile,有数百万个多边形,我需要解散。根据shapefile,我需要按组解散或只使用view
。我一直在使用st_union
function,它一直适用于大多数sf应用程序。虽然当我在st_par
上使用此函数时它会返回一个列表但我无法弄清楚如何平行化sf dissolve函数st_union
。
任何建议都会对您有所帮助!这是一个小代码片段来说明我的观点。
st_union
答案 0 :(得分:1)
我认为您可以通过对原始st_par
function进行少量修改来解决您的具体问题
然而,这只是一个快速而大胆的修复,这可能会破坏该函数的其他用途的代码
该函数的作者当然可以提供更好的解决方案......
library(parallel)
# Paralise any simple features analysis.
st_par <- function(sf_df, sf_func, n_cores, ...){
# Create a vector to split the data set up by.
split_vector <- rep(1:n_cores, each = nrow(sf_df) / n_cores, length.out = nrow(sf_df))
# Perform GIS analysis
split_results <- split(sf_df, split_vector) %>%
mclapply(function(x) sf_func(x), mc.cores = n_cores)
# Combine results back together. Method of combining depends on the output from the function.
if ( length(class(split_results[[1]]))>1 | class(split_results[[1]])[1] == 'list' ){
result <- do.call("c", split_results)
names(result) <- NULL
} else {
result <- do.call("rbind", split_results)
}
# Return result
return(result)
}