Learn R Programming

tmap (version 1.2)

bb: Bounding box generator

Description

Swiss army knife for bounding boxes. Modify an existing bounding box or create a new bounding box from scratch. See details.

Usage

bb(x = NA, ext = NULL, cx = NULL, cy = NULL, width = NULL,
  height = NULL, xlim = NULL, ylim = NULL, relative = FALSE,
  current.projection = NULL, projection = NULL)

Arguments

x
One of the following:
  • A shape (from classSpatialorRaster)
  • A bounding box (either 2 by 2 matrix or an
ext
Extension factor of the bounding box. If 1, the bounding box is unchanged. Values smaller than 1 reduces the bounding box, and values larger than 1 enlarges the bounding box. This argument is a shortcut for both width and height
cx
center x coordinate
cy
center y coordinate
width
width of the bounding box. These are either absolute or relative (depending on the argument relative).
height
height of the bounding box. These are either absolute or relative (depending on the argument relative).
xlim
limits of the x-axis. These are either absolute or relative (depending on the argument relative).
ylim
limits of the y-axis. See xlim.
relative
boolean that determines whether relative values are used for width, height, xlim and ylim or absolute. If x is unspecified, relative is set to "FALSE".
current.projection
projection string (see set_projection) of the that corresponds to the
projection
projection string (see set_projection) to transform the bounding box to.

Details

An existing bounding box (defined by x) can be modified as follows:
  • Using the extension factorext.
  • Changing the width and height withwidthandheight. The argumentrelavitvedetermines whether relative or absolute values are used.
  • Setting the x and y limits. The argumentrelavitvedetermines whether relative or absolute values are used.
A new bounding box can be created from scratch as follows:
  • Using the extension factorext.
  • Setting the center coorinatescxandcy, together with thewidthandheight.
  • Setting the x and y limitsxlimandylim

Examples

Run this code
## load shapes
data(NLD_muni)
data(World)

## get bounding box (similar to sp's function bbox)
bb(NLD_muni)

## extent it by factor 1.10
bb(NLD_muni, ext=1.10)

## convert to longlat
bb(NLD_muni, projection="longlat")

## change existing bounding box
bb(NLD_muni, ext=1.5)
bb(NLD_muni, width=2, relative = TRUE)
bb(NLD_muni, xlim=c(.25, .75), ylim=c(.25, .75), relative = TRUE)
bb("Limburg", projection = get_projection(NLD_muni))

tm_shape(World, bbox=bb("Italy", projection = "eck4")) + tm_polygons()
#identical: tm_shape(World, x="Italy", projection = "eck4") + tm_polygons()

## create new bounding box
tm_shape(NLD_muni, bbox=bb(cx=190000, cy=330000, width=50000, height=50000)) + tm_polygons()

Run the code above in your browser using DataLab