Convert data frame to SpatialPolygons object.
Details
Each row in the data frame df
contains both coordinates and labels (or keys) that identify to which polygon the coordinates belong. This function groups the data frame according to keys
and forms a SpatialPolygons
object from the coordinates in each group. It is important that all rings are closed, that is, that the last row of each group is identical to the first row. Since keys
can be of length greater than one, we identify each polygon with a new key by forming an MD5 hash made out of the respective keys
variables that in themselves are unique (and therefore the hashed key is also unique). For lon-lat coordinates use proj = CRS("+proj=longlat +ellps=sphere")
.