I'm trying to play along with this vignette on combining spatial data by Roger Bivand & have run into the thorny issue that Spatial* objects (most importantly SpatialPolygons) depend on a data.frame's row names to communicate between the IDs used for plotting & the associated data.
So while it's handy to have sp@data as a data.table for various operations where I'm comfortable using data.table syntax (merging, adding/dropping columns, etc.), I found that I needed setDF at a step used to match a Spatial* object's IDs to its data (specifically these lines on page 3: row.names(nc90_df) <- paste(nc90_df$ST, nc90_df$CO, sep = ""); nc90b <- SpatialPolygonsDataFrame(nc90a, nc90_df)).
I was thinking it would be convenient for setDF to have an argument, rownames parallel to setDT's keep.rownames to simultaneously assign non-sequential row names to the result, ideally (for parsimony) evaluating within the data.table's environment, e.g. setDF(sp@data, rownames = paste0(ST, CO)), though explicitly calling the data.table environment would also be simple: setDF(sp@data, rownames = sp@data[, paste0(ST, CO)])
I'm trying to play along with this vignette on combining spatial data by Roger Bivand & have run into the thorny issue that
Spatial*objects (most importantlySpatialPolygons) depend on adata.frame's row names to communicate between the IDs used for plotting & the associated data.So while it's handy to have
sp@dataas adata.tablefor various operations where I'm comfortable usingdata.tablesyntax (merging, adding/dropping columns, etc.), I found that I neededsetDFat a step used to match aSpatial*object's IDs to its data (specifically these lines on page 3:row.names(nc90_df) <- paste(nc90_df$ST, nc90_df$CO, sep = ""); nc90b <- SpatialPolygonsDataFrame(nc90a, nc90_df)).I was thinking it would be convenient for
setDFto have an argument,rownamesparallel tosetDT'skeep.rownamesto simultaneously assign non-sequential row names to the result, ideally (for parsimony) evaluating within thedata.table's environment, e.g.setDF(sp@data, rownames = paste0(ST, CO)), though explicitly calling thedata.tableenvironment would also be simple:setDF(sp@data, rownames = sp@data[, paste0(ST, CO)])