flip_y_spat: Flip values on the y-axis direction, and negate the...

flip_y_spatrasterR Documentation

Flip values on the y-axis direction, and negate the Y-Coordinates of SpatRaster and SpatVector Objects

Description

These internal functions flip the y-coordinates of SpatRaster and SpatVector objects from the terra package. For rasters, the function vertically flips the raster and adjusts its extent accordingly. For vectors, the function negates the y-coordinates of all geometries, supporting both point and polygon/line types.

Usage

flip_y_spatraster(data)

flip_y_spatvector(data)

Arguments

data

A SpatRaster or SpatVector object from the terra package.

Details

These functions are intended for internal use to facilitate coordinate transformations. When visualizing spatial data, it is often necessary to flip the y-axis to put the origin at the top left corner. However, a lot of elements have to be visualized with ggplot2::geom_sf(), which won't work with ggplot2::scale_y_reverse(). See also this GitHub issue comment. So we need these functions to flip the values along the y-axis and negate the y-coordinates. This way, we can remove the negative sign from the y-axis labels to mimick the behavior of scale_y_reverse().#'

Value

For flip_y_spatraster, a SpatRaster object with flipped y-coordinates and adjusted extent. For flip_y_spatvector, a SpatVector object with y-coordinates negated.


plotthis documentation built on June 8, 2025, 11:11 a.m.