Hi there!
I have a data frame with geo-located events. I want to convert each geo-location (i.e. the values of the variables latitude
and longitude
in each observation) into the equivalent grid cell from a shapefile (i.e. PRIO-Grids).
I tried the following code:
# 1. Combine the longitude and latitude
coordinates <- cbind(df$longitude, df$latitude))
# 2. Transform into spatial points
sp_points <- SpatialPoints(coordinates)
# 3. Upload shapefile
prio_grids_shapefile <- shapefile(C:\path\to\shapefile.shp)
# 4. Transform spatial points into grids
geo$prio_grids <- spTransform(sp_points, CRS(proj4string(prio_grids_shapefile)))
I get an error right away on step 2:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘coordinates’ for signature ‘"numeric"’
I confess I am clueless here, first time using GIS packages in R. I appreciate any help!
Thanks a lot!