2017-04-05 133 views
2

我有一個經度和緯度值的數據集,我想檢查他們是否在大多倫多地區。另外,用最近的人口普查大都會標記它們也足夠了。檢查R大多倫多地區內的經度/緯度

有沒有辦法做到這一點,最好使用R?

+0

看看ggmap軟件包和'geocode'或'revgeocode'函數。這可能適合你。 – Dave2e

回答

2

下面是一個如何使用rgdal包執行此操作的工作示例。還有很多其他方法可以做到這一點。我提供了一個鏈接,指出你可以在哪裏得到一個多倫多形狀文件,如果你還沒有的話。如果您有任何問題,請告訴我。

library(rgdal) 

myTestDF <- data.frame(MyDate = c("A","Toronto","C"), 
         latitude = c(74.3224,43.686094, 88.9237), 
         longitude = c(66.2222, -79.401350, -49.0074)) 

setwd("C:/WhereShapeFilesAre") 

#Download shape file from open data site and unzip contents into a folder this example uses the wgs84 format. 
#http://www1.toronto.ca/wps/portal/contentonly?vgnextoid=c1a6e72ced779310VgnVCM1000003dd60f89RCRD&vgnextchannel=75d6e03bb8d1e310VgnVCM10000071d60f89RCRD 

TorontoShape<- readOGR(".", "citygcs_regional_mun_wgs84") 

myTestPoints <- myTestDF 

coordinates(myTestPoints) <- ~ longitude + latitude 
proj4string(myTestPoints) <- proj4string(TorontoShape) 

cbind(myTestDF, over(myTestPoints, TorontoShape))