Skip to contents

Helper function for creating custom map elements that are aligned with the axes of a map (base plot created with a SpatRaster and/or SpatVector). For example, you may need to know the coordinates for the upper-left corner of a map to add some information there.

Unlike the standard base plot, terra keeps the axis aligned with the data. For that reason you cannot use par()$usr to get these coordinates.

The coordinates returned by this function are used in, for example, add_legend such that a legend can be automatically placed in the a particular corner.

This function only returns meaningful results of the active plot (canvas) was create with a call to plot with a SpatRaster or SpatVector as first argument.

Usage

map_extent()

Examples

r <- rast(xmin=0, xmax=10, ymin=0, ymax=10, res=1, vals=1:100)
plot(r)


map_extent()
#>  xmin xmax ymin ymax  geo
#>     0   10    0   10 TRUE
par()$usr
#> [1]  0.0000000 10.0000000 -0.3244889 10.3244889