I am unable to get centroids from polygons in R. The confusing bit is, it used to work in the past and has suddenly stopped working! This is the piece of code:
polygon.centroids <- SpatialPointsDataFrame(gCentroid(polygon, byid = TRUE),
polygon@data, match.ID = FALSE)
I can also confirm that the proj4string for the polygon data already exists and is as follows:
proj4string: +proj=utm +zone=55 +south +ellps=GRS80 +units=m +no_defs
The error message that I am getting upon executing the centroids code is as follows:
Error in TopologyFunc(spgeom, id, byid, "rgeos_getcentroid") : no slot of name "proj4string" for this object of class "sf"
Any idea what's going on? As mentioned earlier, this code HAS WORKED OKAY in the past.
Thanks