r-spatial / sf

Simple Features for R
https://r-spatial.github.io/sf/
Other
1.32k stars 293 forks source link

[Feature] provide method for `st_transform()` on a bbox object #2415

Closed JosiahParry closed 1 month ago

JosiahParry commented 1 month ago

Presently I know the extent of a bounding box that I am interested in EPSG:4326. However, I would like to translate those into a bounding box for EPSG:3857.

I would like to be able to pass a bounding box into st_transform() like so:

c(xmin = -71,
  ymin = 43,
  xmax = -67,
  ymax = 47.5) |> 
  sf::st_bbox(crs = 4326) |> 
  sf::st_transform(3857)

but there is no method. Instead, this has to be done a bit circuitously:

c(xmin = -71,
  ymin = 43,
  xmax = -67,
  ymax = 47.5) |> 
  sf::st_bbox(crs = 4326) |> 
  sf::st_as_sfc() |> 
  sf::st_transform(3857) |> 
  sf::st_bbox()

It would be nice if this could be turned into an S3 method

edzer commented 1 month ago

See #1558 and #2197

edzer commented 1 month ago

this GDAL function would do the right thing IMO; for EPSG:3857 it wouldn't matter (except when the bbox crosses the antemeridian) but for others it does.