shift_and_rotate()
shifts a raster or vector by a specified horizontal
distance rotating the data around the dateline.
This function is particularly useful for working with rasters and vectors that span the dateline (e.g., the Russian territory).
Arguments
- x
A
SpatRaster
orSpatVector
object to be shifted and rotated.- dx
(optional) A numeric value indicating the amount of the horizontal shift in degrees. Positive values shift to the right, negative values shift to the left (default:
-45
).- precision
(optional) A numeric value specifying the number of decimal digits to use when rounding longitude and latitude coordinates (default:
5
).- overlap_tol
(optional) A numeric value specifying the tolerance for overlapping geometries when combining vectors. This value controls the allowable error when merging overlapping geometries (default:
0.1
).
Value
A object of the same class as x
that has been shifted and rotated
by the specified amount in degrees.
See also
Other raster functions:
shift_and_crop()
Examples
library(dplyr)
library(geodata)
library(terra)
## Raster example
if (curl::has_internet()) {
raster <-
expand.grid(
seq(-179.75, 179.75, by = 0.5),
seq(-89.75, 89.75, by = 0.5)
) |>
as_tibble() |>
rename(x = Var1, y = Var2) |>
mutate(value = rnorm(259200)) |>
rast(type = "xyz") %>%
`crs<-`("epsg:4326")
world_shape <- world(path = tempdir())
raster <- raster |> crop(world_shape, mask = TRUE)
raster |> plot()
raster |> shift_and_rotate(-45) |> plot()
raster |> shift_and_rotate(-90) |> plot()
raster |> shift_and_rotate(-135) |> plot()
raster |> shift_and_rotate(-180) |> plot()
raster |> plot()
raster |> shift_and_rotate(45) |> plot()
raster |> shift_and_rotate(90) |> plot()
raster |> shift_and_rotate(135) |> plot()
raster |> shift_and_rotate(180) |> plot()
}
## Vector example
if (curl::has_internet()) {
vector <- gadm(country = "rus", level = 0, path = tempdir())
vector |> plot()
vector |> shift_and_rotate(-45) |> plot()
vector |> shift_and_rotate(45) |> plot()
}