2. bbox

using SpatRasters, ArchGDAL

bbox

Base.@kwdef struct bbox
  xmin::Float64
  ymin::Float64
  xmax::Float64
  ymax::Float64
end
A = rand(70, 40)
b = bbox(70, 15, 140, 55) # China
bbox(70.0, 15.0, 140.0, 55.0)
ra = rast(A, b)
SpatRaster{Float64}: Raster
  A        : Matrix{Float64} | (70, 40) | 0.02 Mb
  b        : bbox(70.0, 15.0, 140.0, 55.0)
  cellsize : (1.0, 1.0)
  lon, lat : 70.5:1.0:139.5, 54.5:-1.0:15.5
  time     : nothing
  bands    : nothing
  nodata   : nothing

st_bbox

  • st_bbox(lon, lat) : construct bbox from lon, lat
  • st_bbox(ra) : retrieve bbox from SpatRaster
  • st_bbox(file) : get bbox from tiff or netcdf file directly
lon, lat = st_dims(ra)
st_bbox(lon, lat) == st_bbox(ra)
true
guanshan_dem
"/home/runner/work/SpatRasters.jl/SpatRasters.jl/data/GuanShan_dem250m.tif"
st_bbox(guanshan_dem)
bbox(110.7, 32.25, 111.025, 32.5)