카운티 소포 수준의 파일을 가지고 있으며, 같은 주인뿐만 아니라 마일 (약 1610 미터) 내의 소포 수를 계산하려고합니다. 솔루션을 통해 작업 해본 결과 샘플 코드가 아래에 나와 있지만 상당히 비효율적이며 메모리 집약적입니다. 나는 공개적으로 데이터를 게시하지만, 여기에 몇 가지 만들어 코드로 문제가 없습니다큰 데이터 세트가있는 반경 내의 포인트 수 - R
library(rgdal)
library(rgeos)
library(geosphere)
nobs<-1000 # number of observations
nowners<-50 # number of different owners
crs<-"+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
long<-runif(nobs,min=-94.70073, max=-94.24141) #roughly adair county in iowa
lat<-runif(nobs,min=41.15712,max=41.50415) #roughly adair county in iowa
coords<-cbind(long,lat)
owner<-sample(1:nowners,nobs, replace=T) # give id's to owners
df<-as.data.frame(owner)
centroids<-SpatialPointsDataFrame(coords,df,proj4string = CRS(crs)) # make spatial dataframe
d<-distm(centroids) # distance from centroids to other centroid
numdif<-matrix(0,length(owner)) #vectors of 0s to be replaced in loop
numtot<-matrix(0,length(owner))
for (i in 1:length(owner)) {
same_id<-df$owner[i]==owner ## identify locations with same owner ID
numdif[i]<-as.numeric(sum(d[i,]<1609.34 & same_id==F)) #different parcel owners
numtot[i]<-as.numeric(sum(d[i,]<1609.34)) #total parcels
}
결과 "numdif"와 "numtot"벡터 줘 내가 원하는 : 다른와 이웃 소포의 수의 벡터 소유자 및 합계입니다. 그러나이 프로세스는 엄청나게 큰 "nobs"를 가진 내 카운티의 경우 엄청나게 많은 시간과 메모리를 필요로합니다. 일부 카운티는 50-75,000 회의 관측치를 가지고 있습니다 (결과 행렬 m은 수십억 개의 요소를 가지고 있으며 아마도 내가 가진 것보다 훨씬 많은 메모리가 필요할 것입니다). 속도와 메모리 관점 모두에서이 문제에 접근하는 더 좋은 방법에 대해 생각해 본 사람이 있습니까? 도움말 크게 감사드립니다.
예제 데이터를 생성 한 경우 매우 유용합니다. 참조 : https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5965451#5965451 – RobertH
@RobertH, 감사합니다. 나는 그렇게했습니다 – winitheju