這裏是做了工作,借鑑@蠹蟲的回答
library(sp)
library(rgeos)
library(rgdal)
###
# Read in Area Unit (AU) boundaries
au <- readOGR("C:/Users/Peter Ellis/Documents/NZ", layer="AU12")
# Read in Territorial Authority (TA) boundaries
ta <- readOGR("C:/Users/Peter Ellis/Documents/NZ", layer="TA12")
###
# First cut - works ok when only one TA per area unit
x1 <- over(au, ta)
au_to_ta <- data.frame([email protected], TAid = x1)
###
# Second cut - find those with multiple intersections
# and replace TAid with that with the greatest area.
x2 <- over(au, ta, returnList=TRUE)
# This next loop takes around 10 minutes to run:
for (i in 1:nrow(au_to_ta)){
tmp <- length(x2[[i]])
if (tmp>1){
areas <- numeric(tmp)
for (j in 1:tmp){
areas[j] <- gArea(gIntersection(au[i,], ta[x2[[i]][j],]))
}
# Next line adds some tiny random jittering because
# there is a case (Kawerau) which is an exact tie
# in intersection area with two TAs - Rotorua and Whakatane
areas <- areas * rnorm(tmp,1,0.0001)
au_to_ta[i, "TAid"] <- x2[[i]][which(areas==max(areas))]
}
}
# Add names of TAs
au_to_ta$TA <- [email protected][au_to_ta$TAid, "NAME"]
####
# Draw map to check came out ok
png("check NZ maps for TAs.png", 900, 600, res=80)
par(mfrow=c(1,2), fg="grey")
plot(ta, [email protected]$NAME)
title(main="Original TA boundaries")
par(fg=NA)
plot(au, col=au_to_ta$TAid)
title(main="TA boundaries from aggregated\nArea Unit boundaries")
dev.off()

感謝代碼 - gArea和gIntersection在一起而形成的缺失環節我。這看起來應該起作用。如果是這樣,我會接受這個答案。 –
很高興聽到它。如果你能得到它的工作將是很好,如果你可以留下一個有效的代碼示例,因爲我不相信你是唯一一個試圖執行這樣一個顯而易見的重要任務,並努力尋找工具來做到這一點! – Silverfish
謝謝@Silverfish - 我已經添加了一個可以完成這項工作的答案,並且應該適用於其他人。 –