我想用shapefile識別每組緯度/經度座標的郵政編碼。將經度/緯度點映射到R中的一個形狀文件
緯度經度數據摘自:https://data.cityofchicago.org/Public-Safety/Crimes-2017/d62x-nvdr(犯罪_-_ 2001_to_present.csv)
Shape文件: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)中的錯誤: 無法找到函數'over'進行簽名的繼承方法'「SpatialPolygonsD ataFrame「,」data.frame「'
我錯過了什麼?任何幫助表示讚賞!
您正試圖創建一個從CSV和SpatialPolygonsDataFrame一個逗號分隔的文件,他們有完全不同的尺寸標註。您需要以不同的方式將數據與該SPDF文件組合在一起。嘗試共享'str(zip.map)'輸出以及綁定的目的與我們是什麼。我明白你最終在尋找什麼,但是如何實現這一目標?如果我能看到數據,我可能會提供幫助。 – sconfluentus
我還沒有爲你的數據嘗試過,但是你可能想在'splancs'包中查找'?inout'。這是一種測試一組點是否落入多邊形(shapefile)的方法,它可能會讓您更接近您所需的。對不起,這不是確切的解決方案。 –