i have dataset of longitude , latitude values , want check whether in greater toronto area. alternative, labeling them closest census metropolitan suffice well.
is there way accomplish this, preferably using r?
here working example of how rgdal package. there plenty of other ways this. provided link can toronto shape file if not have one. if have 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 open data site , unzip contents folder example uses 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))
Comments
Post a Comment