Learn R Programming

tmap (version 1.6-1)

set_projection: Set and get the map projection

Description

The function set_projection sets the projection of a shape file. It is a convenient wrapper of spTransform and projectRaster with shortcuts for commonly used projections. The projection can also be set directly in the plot call with tm_shape. This function is also used to set the current projection information if this is missing. The function get_projection is used to get the projection information.

Usage

set_projection(shp, projection = NA, current.projection = NA, overwrite.current.projection = FALSE)
get_projection(shp, as.CRS = FALSE)

Arguments

shp
shape object of class Spatial or Raster (see details).
projection
new projection. Either a CRS object or a character value. If it is a character, it can either be a PROJ.4 character string or a shortcut. See get_proj4 for a list of shortcut values. This argument is only used to transform the shp. Use current.projection to specify the current projection of shp.
current.projection
the current projection of shp. See projection for possible formats. Only use this if the current projection is missing or wrong.
overwrite.current.projection
logical that determines whether the current projection is overwritten if it already has a projection that is different.
as.CRS
should a CRS object be returned instead of a PROJ.4 character string? Default is FALSE.

Value

set_projection returns a (transformed) shape object with updated projection information. get_projection returns the PROJ.4 character string of shp.

Details

For raster objects, the projection method is based on the type of data. For numeric layers, the bilinear method is used, and for categorical layers the nearest neighbor. See projectRaster for details.