R/sp_feature_ids.R

Defines functions sp_feature_ids

Documented in sp_feature_ids

#' Function to get ids from spatial objects.
#' 
#' @author Stuart K. Grange
#' 
#' @param sp Spatial object. 
#' 
#' @export
sp_feature_ids <- function(sp) {
  
  # Points
  if (grepl("points", sp_class(sp), ignore.case = TRUE))
    id <- row.names(sp@data)
  
  # Lines
  if (grepl("line", sp_class(sp), ignore.case = TRUE)) {
    
    id <- sapply(slot(sp, "lines"), slot, "ID")
    
    # Stip names for lines
    id <- as.vector(id)
    
  }
  
  # Polygons
  if (grepl("polygon", sp_class(sp), ignore.case = TRUE))
    id <- sapply(slot(sp, "polygons"), slot, "ID")
  
  # Return
  id
  
}
skgrange/gissr documentation built on Feb. 24, 2024, 2:55 p.m.