spsample()을 사용하여 shapefile 목록에서 각 shapefile에 임의의 점을 배치해야합니다. 불규칙한 쉐이프 파일의 경우에는 긴 프로세스로 판명되었으므로 spsample()이 문제가되는 작고 먼 폴리곤을 삭제하여 간단히 쉐이프 파일을 작성해야합니다.spsample()을 사용하여 임의의 점을 배치하기위한 shapefile을 단순화합니다.
각 폴리곤의 크기와 다른 모든 다각형과의 평균 거리를 알아야합니다. 이 계산 속도를 높이는 방법을 찾고 있는데 아마도 좀 더 우아하고 빠른 방법으로 할 수있을 것입니다. 다음과 같은 시도가 있지만 알고리즘을 간소화하는 데 너무 많은 시간이 걸립니다.
#program tries to place random points on shapefile shapes[[i]] if it fails after 300 seconds it goes though to simplifying part and swaps the old shapefile with a simplified version.
d <- shapes[[i]]
Fdist <- list()
for(m in 1:dim(d)[1]) {
pDist <- vector()
for(n in 1:dim(d)[1]) {
pDist <- append(pDist, gDistance(d[m,],d[n,]))
}
Fdist[[m]] <- pDist
[email protected]$mean[m]<-mean(Fdist[[m]])
[email protected]$gArea[m]<-gArea(d[m,])
}
#drop small and remote polygons
d.1<-d[[email protected]$gArea>=quantile([email protected]$gArea, prob = seq(0, 1, length=11), type=5)[[1]] & ([email protected]$mean<=quantile([email protected]$mean, prob = seq(0, 1, length=11), type=5)[[10]]),]
#replace with simplified polygon
shapes[[i]]<-d.1
나는 모든 제안에 감사드립니다.
감사 필! 나는 sm_simplify와 vectorization을 모두 적용했고, ** 빨리 ** 많이 실행되었습니다! – Juta
@juta 정말 도움이 된 것을 기쁘게 생각합니다! – Phil