【发布时间】:2017-08-30 02:01:09
【问题描述】:
我正在尝试使用 shapefile 识别每组纬度/经度坐标的邮政编码。
经纬度数据提取自:https://data.cityofchicago.org/Public-Safety/Crimes-2017/d62x-nvdr (Crimes_-_2001_to_present.csv)
形状文件:https://www2.census.gov/geo/tiger/PREVGENZ/zt/z500shp/ zt17_d00.shp(伊利诺伊州邮政编码定义)
library(rgeos)
library(maptools)
ccs<-read.csv("Crimes_-_2001_to_present.csv")
zip.map <- readOGR("zt17_d00.shp")
latlon<-ccs[,c(20,21)]
str(latlon)
'data.frame': 6411517 obs. of 2 variables:
$ Latitude : num 42 41.7 41.9 41.8 42 ...
$ Longitude: num -87.7 -87.6 -87.7 -87.6 -87.7 ...
coordinates(latlon) = ~Longitude+Latitude
write.csv(cbind(latlon,over(zip.map,latlon)),"zip.match.csv")
这是我得到的错误:
(函数(类,fdef,mtable)中的错误: 无法找到签名“SpatialPolygonsDataFrame”、“data.frame”的函数“over”的继承方法
我错过了什么?任何帮助表示赞赏!
【问题讨论】:
-
您正在尝试从 CSV 和 SpatialPolygonsDataFrame 创建逗号分隔文件,它们的尺寸完全不同。您需要以不同的方式将数据与该 SPDF 文件组合。尝试与我们分享
str(zip.map)输出以及绑定的目的是什么。我了解您最终要寻找的东西,但是 cbind 是如何通过您的方法实现的呢?如果我能看到数据,我可能会提供帮助。 -
我还没有为你的数据尝试过这个,但你可能想在
splancs包中查找?inout。这是一种测试一组点是否落在多边形(shapefile)内的方法,这可能会让你更接近你需要的东西。抱歉,这不是确切的解决方案。
标签: r geospatial geocoding latitude-longitude shapefile