Learn R Programming

stars (version 0.1-1)

st_transform: transform features, or warp/resample grids in stars objects to a new coordinate reference system

Description

transform features, or warp/resample grids in stars objects to a new coordinate reference system

Usage

# S3 method for stars
st_transform(x, crs, ..., cellsize = NA_real_,
  segments = 100)

Arguments

x

object of class stars, with either raster or simple feature geometries

crs

object of class crs with target crs, or object of class stars with target grid

...

passed on

cellsize

cellsize in target coordinate reference system

segments

number of (total) segments to segmentize the bounding box before transforming to new crs

Details

For simple feature dimensions, st_transform is called, leading to lossless transformation. For gridded spatial data (dimensions x and y), see figure; the existing grid is transformed into a regular grid in the new coordinate reference system, using the same procedure as projectRaster (currently only with method='ngb'). This entails: (i) the envelope (bounding box polygon) is transformed into the new crs, possibly after segmentation (red box); (ii) a grid is formed in the new crs, touching the transformed envelope on its East and North side, (if cellsize is not given) with a cellsize similar to the origin cell size, with an extent that at least covers x; (iii) for each cell center of this new grid, the matching grid cell of x is used; if there is no match, an NA value is used.

Examples

Run this code
# NOT RUN {
geomatrix = system.file("tif/geomatrix.tif", package = "stars")
(x = read_stars(geomatrix))
new = st_crs(4326)
y = st_transform(x, new)
plot(st_transform(st_as_sfc(st_bbox(x)), new), col = NA, border = 'red')
plot(st_as_sfc(y, as_points=FALSE), col = NA, border = 'green', axes = TRUE, add = TRUE)
image(y, add = TRUE)
plot(st_as_sfc(y, as_points=TRUE), pch=3, cex=.5, col = 'blue', add = TRUE)
plot(st_transform(st_as_sfc(x, as_points=FALSE), new), add = TRUE)
# }

Run the code above in your browser using DataLab