检查 Longitude/Latitude 是否在 R 的大多伦多地区

Checking if Longitude/Latitude within Greater Toronto Area in R

我有一个经度和纬度值的数据集,我想检查它们是否在大多伦多地区。或者,用 Closest Census Metropolitan 标记它们也足够了。

有没有办法实现这个,最好是使用 R?

这是一个工作示例,说明如何使用 rgdal 包执行此操作。还有很多其他方法可以做到这一点。如果您还没有多伦多形状文件,我提供了一个 link 到哪里可以获得多伦多形状文件。如果您有任何问题,请告诉我。

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))