R/tm_shape.R

Defines functions tm_shape

Documented in tm_shape

#' Shape (spatial object) specification
#' 
#' Specify a shape, which is a spatial object from one of these spatial object
#' class packages: [`sf`][`sf::sf`], [`stars`][stars::st_as_stars()], or `terra`.
#' 
#' @param shp Spatial object
#' @param name Name of the shape
#' @param is.main Is `shp` the main shape, which determines the crs and
#'   bounding box of the map?
#' @param crs CRS to which `shp` is reprojected (only used if `is.main = TRUE`)
#' @param bbox Bounding box of he map (only used if `is.main = TRUE`)
#' @param unit Unit of the coordinates
#' @param filter Filter features
#' @param ... to catch deprecated arguments from version < 4.0
#' @import tmaptools
#' @import sf
#' @import stars
#' @import units
#' @import grid
#' @import cols4all
#' @import classInt
#' @import htmltools
#' @import htmlwidgets
#' @import widgetframe
#' @import leaflet
#' @import leafsync
#' @import leafem
#' @import leaflegend
#' @import stats
#' @importFrom rlang missing_arg expr
#' @importFrom grDevices col2rgb colorRampPalette colors dev.off dev.size png rgb
#' @import utils
#' @example ./examples/tm_shape.R  
#' @export
tm_shape = function(shp, 
					bbox = NULL,
					crs = NULL,
					is.main = NA,
					name = NULL,
					unit = NULL,
					filter = NULL,
					...) {
	args = as.list(match.call(expand.dots = TRUE)[-1])

	if ("projection" %in% names(args)) {
		v3_instead_message(arg_old = "projection", arg_new = "crs", fun = "tm_shape")
		crs = args$projection
	}
	
	if (missing(shp)) {
		do.call(tm_options, args[intersect(names(args), c("bbox", "crs", "set.bounds", "set.view", "set.zoom.limits"))])
	} else {
		tm_element_list(tm_element(shp = shp,
								   is.main = is.main,
								   crs = crs,
								   bbox = bbox,
								   unit = unit,
								   filter = filter,
								   shp_name = ifelse(is.null(name) == TRUE, deparse(substitute(shp))[1], name), 
								   subclass = "tm_shape"))
	}
}
r-tmap/tmap documentation built on June 23, 2024, 9:58 a.m.