Skip to content

frames_spatial() does not crop to ext if in projected CRS #142

@robe2037

Description

@robe2037

If input data to frames_spatial() are in a projected CRS and an ext is provided, the output map bounding box is modified relative to the default extent, but not cropped precisely to ext itself.

This appears to be because .ext() first projects the input extent into EPSG:4326 and then computes a bounding box for the projected extent. That bounding box is what is used in the extent calculations and then projected back to the desired output CRS. But because we reproject the bounding box of the projected extent (rather than the projected extent polygon itself), we don't actually recover the original input extent.

library(moveVis)
#> Read our accompanying open-access paper published in 'Methods in
#> Ecology and Evolution': https://doi.org/10.1111/2041-210X.13374

data("move_data")

move_data <- sf::st_transform(move_data, "epsg:32637")

m <- align_move(move_data)
#> Temporal resolution of 3.96 [min] is used to align trajectories.

# Set an extent in the data CRS:
ext <- sf::st_set_crs(
  sf::st_bbox(c(xmin = -1740000, ymin = 5740000, xmax = -1736000, ymax = 5747000)), 
  sf::st_crs(m)
)

fr <- frames_spatial(
  m,
  ext = ext,
  crs = sf::st_crs(m),
  crs_graticule = sf::st_crs(m)
)
#> Processing input data...
#> Approximated animation duration: ≈ 7.6s at 25 fps using 190 frames
#> CRS (projected):  WGS 84 / UTM zone 37N
#> Loading basemap 'streets' from map service 'osm'...
#> Assigning raster maps to frames...

# Output is not cropped to the provided extent:
fr[[1]]

Created on 2025-10-15 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions