1. SpatRaster
SpatRaster
SpatRaster
is a simple spatial raster with WGS84 projection, abbreviated as rast
.
Base.@kwdef mutable struct SpatRaster{T,N} <: AbstractSpatRaster{T,N}
::AbstractArray{T,N}
A::bbox = bbox(-180.0, -90.0, 180.0, 90.0)
b::NTuple{2,Real}
cellsize::AbstractVector{<:Real}
lon::AbstractVector{<:Real}
lat::Union{AbstractVector,Nothing} = nothing
time::Union{AbstractVector{String},Nothing} = nothing
bands::String = "Raster"
name::Union{AbstractVector{T},Nothing} = nothing
nodataend
A
: The raster data array where T is the element type and N is the number of dimensionsb
: Bounding box defining the spatial extent, defaults to global extentbbox(-180.0, -90.0, 180.0, 90.0)
cellsize
: Cell size in degrees as (longitude_size, latitude_size)
lon
: Longitude coordinates for each columnlat
: Latitude coordinates for each rowtime
: Time dimension values (optional)bands
: Band names for multi-band rasters (optional)name
: Name identifier for the raster, defaults to “Raster”nodata
: No-data values for each band (optional)
Construction
using SpatRasters
using Dates
= Date(2010, 1, 1):Day(1):Date(2010, 1, 10)
dates = length(dates)
ntime
= rast(rand(180, 90, ntime); time=dates)
ra ra
SpatRaster{Float64}: Raster A : Array{Float64, 3} | (180, 90, 10) | 1.24 Mb b : bbox(-180.0, -90.0, 180.0, 90.0) cellsize : (2.0, 2.0) lon, lat : -179.0:2.0:179.0, 89.0:-2.0:-89.0 time : 2010-01-01 ~ 2010-01-10, ntime=10 bands : nothing nodata : nothing
= rand(70, 40)
A = bbox(70, 15, 140, 55) # China
b 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
Subset
ra[i, j]
will automatically alterlon
,lat
andbbox
. If both ofi
andj
are integer, value of ra.A[i, j] will be retrieved.ra[i, j, k]
will additionally alterbands
, andtime
1, 1]
ra[1:10, 1:10] ra[
SpatRaster{Float64}: Raster A : Array{Float64, 3} | (10, 10, 10) | 0.01 Mb b : bbox(-180.0, 70.0, -160.0, 90.0) cellsize : (2.0, 2.0) lon, lat : -179.0:2.0:-161.0, 89.0:-2.0:71.0 time : 2010-01-01 ~ 2010-01-10, ntime=10 bands : nothing nodata : nothing
1:10, 1:10, 1:2] ra[
SpatRaster{Float64}: Raster A : Array{Float64, 3} | (10, 10, 2) | 0.0 Mb b : bbox(-180.0, 70.0, -160.0, 90.0) cellsize : (2.0, 2.0) lon, lat : -179.0:2.0:-161.0, 89.0:-2.0:71.0 time : 2010-01-01 ~ 2010-01-02, ntime=2 bands : nothing nodata : nothing
1:10, 1:10, 1:1] ra[
SpatRaster{Float64}: Raster A : Array{Float64, 3} | (10, 10, 1) | 0.0 Mb b : bbox(-180.0, 70.0, -160.0, 90.0) cellsize : (2.0, 2.0) lon, lat : -179.0:2.0:-161.0, 89.0:-2.0:71.0 time : 2010-01-01 ~ 2010-01-01, ntime=1 bands : nothing nodata : nothing
1:10, 1:10, 1] ra[
SpatRaster{Float64}: Raster A : Matrix{Float64} | (10, 10) | 0.0 Mb b : bbox(-180.0, 70.0, -160.0, 90.0) cellsize : (2.0, 2.0) lon, lat : -179.0:2.0:-161.0, 89.0:-2.0:71.0 time : 2010-01-01 ~ 2010-01-01, ntime=1 bands : nothing nodata : nothing
crop
截取部分范围