The function set_projection
sets the projection of a shape file. It is
a convenient wrapper of st_transform
(or st_transform_proj
, see details) 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.
set_projection(shp, projection = NA, current.projection = NA,
overwrite.current.projection = FALSE)get_projection(shp, guess.longlat = FALSE, output = c("character",
"crs", "epsg", "CRS"))
new projection. See get_proj4
for options. This argument is only used to transform the shp
. Use current.projection
to specify the current projection of shp
.
the current projection of shp
. See get_proj4
for possible options. Only use this if the current projection is missing or wrong.
logical that determines whether the current projection is overwritten if it already has a projection that is different.
if TRUE
, it checks if the coordinates are within -180/180 and -90/90, and if so, it returns the WGS84 longlat projection (which is get_proj4("longlat")
).
output format of the projection. One of "character"
, "crs"
(from sf
package), "epsg"
or "CRS"
(from sp
/rgdal
package)
set_projection
returns a (transformed) shape object with updated projection information. get_projection
returns the PROJ.4
character string of shp
.
For sf
objects, set_projection
first tries to use sf::st_transform
, which uses the GDAL API. For some projections, most notably Winkel Tripel ("wintri"
), is doesn't work. In these cases, set_projection
will use lwgeom::st_transform_proj
, which uses the PROJ.4 API.
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.