本文介绍了检查R中大多伦多地区内的经度/纬度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个经度和纬度值的数据集,我想检查它们是否在大多伦多地区.另外,将它们标记为最近的人口普查大都会"也足够了.
I have a dataset of Longitude and Latitude values and I want to check whether they are in the Greater Toronto Area. Alternative, labeling them with the Closest Census Metropolitan would suffice as well.
有没有一种方法可以做到这一点,最好使用R?
Is there a way to accomplish this, preferably using R?
推荐答案
这里是如何使用rgdal软件包执行此操作的示例.还有很多其他方法可以做到这一点.我提供了一个指向多伦多形状文件的链接,如果您还没有的话.如果您有任何疑问,请告诉我.
Here is a working example of how to do this with the rgdal package. There are plenty of other ways to do this. I provided a link to where you can get a Toronto shape file if you do not already have one. If you have any questions please let me know.
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))
这篇关于检查R中大多伦多地区内的经度/纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!