2016-03-22 119 views
0

所以我已經將我對COORDS到2個矩陣看起來像這樣的:rdist.earth()與對座標

long1  lat1 
1 -1.290672 0.7124777 
2 -1.290643 0.7125160 
3 -1.290692 0.7125405 
4 -1.290724 0.7124929 
5 -1.290748 0.7124579 
6 -1.290766 0.7124353 

    long2  lat2 
1 -1.290643 0.7125160 
2 -1.290692 0.7125405 
3 -1.290724 0.7124929 
4 -1.290748 0.7124579 
5 -1.290766 0.7124353 
6 -1.290771 0.7124249 

試圖運行一個看似-簡單的命令,但它掛在我的機器。不知道爲什麼,因爲每個矩陣只有507550個元素和17.4 Mb。

foo <- rdist.earth(coords, coords2, miles=FALSE, R=6371) 

有沒有更簡單的方法來做到這一點???

+0

一個側面說明: 沒有考慮過閱讀這個博客的替代品: HTTP://www.r-bloggers。 com/great-circle-distance-calculation-in-r/ – InfiniteFlashChess

+0

哈哈是啊我發佈後立即發現它,現在一切都很好 – briahnah

回答

0
dist <- rdist.earth.vec(coords, coords2, miles=FALSE, R=6371) 
0

有更好的方法來做到這一點。但是,如果你的R技能是最小的:你可以將第一個矩陣矩陣分成子矩陣(每個矩陣的大小是總數的十分之一),對每個矩陣運算每個子矩陣,然後將結果合併到。最後我有同樣的問題,這就是我想出了

getwd() 
setwd("C:/_R") 
library(maptools) 
require(rgdal) 
# Read SHAPEFILE.shp from the current working directory (".") 
points2010 <- readOGR(dsn = "C:/_R", layer = "points_2010") 
metro <- readOGR(dsn = "C:/_R", layer = "selection") 
plot(points2010) 
plot(metro, axes=TRUE) 
head(points2010) 

library("rgeos") 
ohio.metro <- spTransform(points2010, CRS("+proj=longlat +datum=WGS84")) 
plot(ohio.metro, axes=TRUE) 

ohio.metro$COUNTYFP10<-substr(ohio.metro$id,3,5) 
countylist<-unique(ohio.metro$COUNTYFP10) 
# "035" "055" "085" "093" "103" 
ohio.county035 <- subset(ohio.metro, COUNTYFP10 == "035" ) 
ohio.county055 <- subset(ohio.metro, COUNTYFP10 == "055" ) 
ohio.county085 <- subset(ohio.metro, COUNTYFP10 == "085" ) 
ohio.county093 <- subset(ohio.metro, COUNTYFP10 == "093" ) 
ohio.county103 <- subset(ohio.metro, COUNTYFP10 == "103" ) 

plot(ohio.metro$COUNTYFP10) #counties in the metro 
plot(ohio.county035$COUNTYFP10) # counties inthe county 

plot(ohio.metro) #counties in the metro 
plot(ohio.county035) # counties inthe county 

#get the coordinats for the Great circle command 
ohio.metro.coords <- [email protected] 
ohio.county035.coords <- [email protected] 
ohio.county055.coords <- [email protected] 
ohio.county085.coords <- [email protected] 
ohio.county093.coords <- [email protected] 
ohio.county103.coords <- [email protected] 

library(fields) 
great_circle<-rdist.earth(ohio.county035.coords,ohio.metro.coords,miles=TRUE, R=NULL) #works 
great_circle<-rdist.earth(ohio.county055.coords,ohio.metro.coords,miles=TRUE, R=NULL) #works 
great_circle<-rdist.earth(ohio.county085.coords,ohio.metro.coords,miles=TRUE, R=NULL) #works 
great_circle<-rdist.earth(ohio.county093.coords,ohio.metro.coords,miles=TRUE, R=NULL) #works 
great_circle<-rdist.earth(ohio.county103.coords,ohio.metro.coords,miles=TRUE, R=NULL) #works 

library(matrixStats) 
bm<-rowMedians(great_circle) 
head(bm)