매우 큰 벡터 파일을 25m로 래스터 화하고 '클러스터'패키지로 성공한 적이 있습니다. 특정 데이터에 대해 잘 작동하는 here 및 here을 적용했습니다.폭설을 사용하여 R의 폴리곤을 래스터 화합니다.
그러나 래스터 화가 필요하고 강설량을 사용하는 클러스터에 액세스 할 수있는 더 큰 벡터 파일이 생겼습니다. 저는 클러스터 기능에 익숙하지 않고 sfLapply를 설정하는 방법을 모르겠습니다. sfLapply 클러스터에라고 나는 일관되게 오류의 다음과 같은 종류의 무엇입니까 :
Error in checkForRemoteErrors(val) :
one node produced an error: 'quote(96)' is not a function, character or symbol
Calls: sfLapply ... clusterApply -> staticClusterApply -> checkForRemoteErrors
내 전체 코드 : 나는 기능과 sfLapply을 변경, 여러 가지를 시도했습니다
library(snowfall)
library(rgeos)
library(maptools)
library(raster)
library(sp)
setwd("/home/dir/")
# Initialise the cluster...
hosts = as.character(read.table(Sys.getenv('PBS_NODEFILE'),header=FALSE)[,1]) # read the nodes to use
sfSetMaxCPUs(length(hosts)) # make sure the maximum allowed number of CPUs matches the number of hosts
sfInit(parallel=TRUE, type="SOCK", socketHosts=hosts, cpus=length(hosts), useRscript=TRUE) # initialise a socket cluster session with the named nodes
sfLibrary(snowfall)
# read in required data
shp <- readShapePoly("my_data.shp")
BNG <- "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs"
crs(shp) <- BNG
### rasterize the uniques to 25m and write (GB and clipped) ###
rw <- raster(res=c(25,25), xmn=0, xmx=600000, ymn=0, ymx=1000000, crs=BNG)
# Number of polygons features in SPDF
features <- 1:nrow(shp[,])
# Split features in n parts
n <- 96
parts <- split(features, cut(features, n))
rasFunction = function(X, shape, raster, nparts){
ras = rasterize(shape[nparts[[X]],], raster, 'CODE')
return(ras)
}
# Export everything in the workspace onto the cluster...
sfExportAll()
# Distribute calculation across the cluster nodes...
rDis = sfLapply(n, fun=rasFunction,X=n, shape=shp, raster=rw, nparts=parts) # equivalent of sapply
rMerge <- do.call(merge, rDis)
writeRaster(rMerge, filename="my_data_25m", format="GTiff", overwrite=TRUE)
# Stop the cluster...
sfStop()
, 하지만 난 그냥 달릴 수 없어. 감사
래스터 화 (큰) 벡터 데이터로 속도를 찾고 있다면'gdalUtils :: gdal_rasterize'를보십시오. 이것은 보통'raster :: rasterize'보다 훨씬 빠릅니다. – joberlin
ok 고맙습니다. – Sam
rasFunction을 삭제하고 rDis를 "rDis = sfLapply (1 : n, fun = function (x) rasterize (shp [parts [[x]], rw)로 변경했습니다. , 'CODE')) "하지만 지금은 checkForRemoteErrors (val)에서 오류가 발생합니다. 노드가 오류를 생성했습니다. 첫 번째 오류 : '데이터'는 벡터 형식이어야하며 'NULL'입니다. 엉망진창. – Sam