R/getcenterofpolygons.R

Defines functions getcenterofpolygons

Documented in getcenterofpolygons

#' Get the Center of a Bunch of Polygons
#'
#' @param polygons a SpatialPolygonsDataFrame
#'
#' @return a two column data frame with the longitude and latitude of the center point of polygons
#' @export
#'
getcenterofpolygons  <- function(polygons) {

  blob  <- rgeos::gUnaryUnion(polygons)
  center  <- blob@polygons[[1]]@labpt

  dplyr::data_frame(lon = center[1], lat = center[2])

}
crazybilly/rmapcounties documentation built on Jan. 4, 2024, 6:32 a.m.