rdist.earth()与成对坐标

rdist.earth()与成对坐标,r,coordinates,distance,R,Coordinates,Distance,我把坐标对转换成两个矩阵,如下所示: 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.

我把坐标对转换成两个矩阵,如下所示:

    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.4MB

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

foo
dist有更好的方法。但是如果你的R技能很低:你可以将第一个矩阵子集为子矩阵(比如说,每个子矩阵的大小是总矩阵的1/10),将每个子矩阵与第二个矩阵进行比较,然后在最后合并结果。我也有同样的问题,这就是我的想法

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 <- ohio.metro@coords
ohio.county035.coords <- ohio.county035@coords
ohio.county055.coords <- ohio.county055@coords
ohio.county085.coords <- ohio.county085@coords
ohio.county093.coords <- ohio.county093@coords
ohio.county103.coords <- ohio.county103@coords

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)
getwd()
setwd(“C://U R”)
图书馆(地图工具)
需要(rgdal)
#从当前工作目录(“.”)中读取SHAPEFILE.shp

PositS2010的一个侧面注:考虑阅读这个博客的替代品:LOL是的,我最终发现它后立即张贴,现在一切好
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 <- ohio.metro@coords
ohio.county035.coords <- ohio.county035@coords
ohio.county055.coords <- ohio.county055@coords
ohio.county085.coords <- ohio.county085@coords
ohio.county093.coords <- ohio.county093@coords
ohio.county103.coords <- ohio.county103@coords

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)