I am trying to identify the zip code for each set of lat/lon coordinate using a shapefile.
Lat Lon data is extracted from: https://data.cityofchicago.org/Public-Safety/Crimes-2017/d62x-nvdr (Crimes_-_2001_to_present.csv)
Shapefile: https://www2.census.gov/geo/tiger/PREVGENZ/zt/z500shp/ zt17_d00.shp (zip code definitions for the state of Illinois)
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")
This is the error I get:
Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘over’ for signature ‘"SpatialPolygonsDataFrame", "data.frame"’
What am I missing? Any help is appreciated!