Title: | Grouping Satellite Bands by Spectral and Spatial Resolution |
---|---|
Description: | Given raster files directly downloaded from various websites, it generates a raster structure where it merges them if they are tiles of the same scene and classifies them according to their spectral and spatial resolution for easy access by name. |
Authors: | Jose Samos [aut, cre] , Universidad de Granada [cph] |
Maintainer: | Jose Samos <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.1.1.9000 |
Built: | 2025-01-14 04:11:48 UTC |
Source: | https://github.com/josesamos/satres |
terra
SpatRaster
classReturns the multi-band raster of the indicated spatial resolution as an object
of class SpatRaster
from package terra
as_SpatRaster(sr, res) ## S3 method for class 'satres' as_SpatRaster(sr, res = NULL)
as_SpatRaster(sr, res) ## S3 method for class 'satres' as_SpatRaster(sr, res = NULL)
sr |
A |
res |
A string, spatial resolution. |
A vector of strings.
Other satellite exportation:
save_by_resolution()
esa <- system.file("extdata", "esa", package = "satres") sr <- satres(dir = esa) r <- sr |> as_SpatRaster("r1000m")
esa <- system.file("extdata", "esa", package = "satres") sr <- satres(dir = esa) r <- sr |> as_SpatRaster("r1000m")
Clips all bands of each spatial resolution according to the given polygon.
clip_bands(sr, polygon) ## S3 method for class 'satres' clip_bands(sr, polygon)
clip_bands(sr, polygon) ## S3 method for class 'satres' clip_bands(sr, polygon)
sr |
A |
polygon |
A |
It performs the operation independently of the CRS of the polygon and preserves the CRS of the bands.
A satres
object.
Other satellite transformation:
merge_tiles()
,
select_bands()
file <- system.file("extdata", "lanjaron.gpkg", package = "satres") lanjaron <- sf::st_read(file, layer = "lanjaron_bbox", quiet = TRUE) esa <- system.file("extdata", "esa", package = "satres") sr <- satres(dir = esa) |> clip_bands(polygon = lanjaron)
file <- system.file("extdata", "lanjaron.gpkg", package = "satres") lanjaron <- sf::st_read(file, layer = "lanjaron_bbox", quiet = TRUE) esa <- system.file("extdata", "esa", package = "satres") sr <- satres(dir = esa) |> clip_bands(polygon = lanjaron)
Returns all names of the multi-band raster that make up the object.
get_band_names(sr, res) ## S3 method for class 'satres' get_band_names(sr, res = NULL)
get_band_names(sr, res) ## S3 method for class 'satres' get_band_names(sr, res = NULL)
sr |
A |
res |
A string, spatial resolution. |
We can indicate the name of a certain spatial resolution to obtain only its names.
A vector of strings.
Other satellite definition:
get_spatial_resolution()
,
get_spectral_band_names()
,
satres()
esa <- system.file("extdata", "esa", package = "satres") sr <- satres(dir = esa, only_spectral_bands = FALSE) r <- sr |> get_band_names()
esa <- system.file("extdata", "esa", package = "satres") sr <- satres(dir = esa, only_spectral_bands = FALSE) r <- sr |> get_band_names()
Returns the spatial resolutions of the multi-band raster that make up the object.
get_spatial_resolution(sr) ## S3 method for class 'satres' get_spatial_resolution(sr)
get_spatial_resolution(sr) ## S3 method for class 'satres' get_spatial_resolution(sr)
sr |
A |
A vector of strings.
Other satellite definition:
get_band_names()
,
get_spectral_band_names()
,
satres()
esa <- system.file("extdata", "esa", package = "satres") sr <- satres(dir = esa) r <- sr |> get_spatial_resolution()
esa <- system.file("extdata", "esa", package = "satres") sr <- satres(dir = esa) r <- sr |> get_spatial_resolution()
Returns the band names of the multi-band raster that make up the object.
get_spectral_band_names(sr, res) ## S3 method for class 'satres' get_spectral_band_names(sr, res = NULL)
get_spectral_band_names(sr, res) ## S3 method for class 'satres' get_spectral_band_names(sr, res = NULL)
sr |
A |
res |
A string, spatial resolution. |
We can indicate the name of a certain spatial resolution to obtain only its band names.
A vector of strings.
Other satellite definition:
get_band_names()
,
get_spatial_resolution()
,
satres()
esa <- system.file("extdata", "esa", package = "satres") sr <- satres(dir = esa, only_spectral_bands = FALSE) r <- sr |> get_spectral_band_names()
esa <- system.file("extdata", "esa", package = "satres") sr <- satres(dir = esa, only_spectral_bands = FALSE) r <- sr |> get_spectral_band_names()
Merge objects whose bands are tiles of a mosaic.
merge_tiles(sr, ...) ## S3 method for class 'satres' merge_tiles(sr, ...)
merge_tiles(sr, ...) ## S3 method for class 'satres' merge_tiles(sr, ...)
sr |
A |
... |
|
The objects must have the same CRS, spatial resolution and bands.
A satres
object.
Other satellite transformation:
clip_bands()
,
select_bands()
esa_f <- system.file("extdata", "esa/f", package = "satres") esa_g <- system.file("extdata", "esa/g", package = "satres") sr2 <- satres(dir = esa_f) sr <- satres(dir = esa_g) |> merge_tiles(sr2)
esa_f <- system.file("extdata", "esa/f", package = "satres") esa_g <- system.file("extdata", "esa/g", package = "satres") sr2 <- satres(dir = esa_f) sr <- satres(dir = esa_g) |> merge_tiles(sr2)
The name of each element is the band identifier.
sat_band
sat_band
A vector.
Other satellite data:
sat_rest_msk
,
sat_rest
The name of each element is the raster identifier.
sat_rest
sat_rest
A vector.
Other satellite data:
sat_band
,
sat_rest_msk
Raster name patterns to treat and not consider bands.
sat_rest_msk
sat_rest_msk
A vector.
Other satellite data:
sat_band
,
sat_rest
Given a vector of compressed file names or the name of a folder containing compressed files, unzip the files to the given output folder. If no output folder is indicated, it is considered the same folder where the input files are.
sat_untarzip( file, out_dir = NULL, include_filename = NULL, only_show_files = FALSE )
sat_untarzip( file, out_dir = NULL, include_filename = NULL, only_show_files = FALSE )
file |
A string or string vector. |
out_dir |
A string or string vector, output folder. |
include_filename |
A boolean, include file name as a folder in the output. |
only_show_files |
A boolean, only show the files that would be unzipped, and the destination folders, not unzip them. |
We can indicate whether to include the file name (without the extension) as a folder in the output folder.
A vector of strings, name of the processed files.
f <- system.file("extdata", package = "satres") r <- sat_untarzip(f, only_show_files = TRUE) f1 <- system.file("extdata", "satres.zip", package = "satres") f2 <- system.file("extdata", "satres.tar", package = "satres") r <- sat_untarzip(c(f1, f2), only_show_files = TRUE)
f <- system.file("extdata", package = "satres") r <- sat_untarzip(f, only_show_files = TRUE) f1 <- system.file("extdata", "satres.zip", package = "satres") f2 <- system.file("extdata", "satres.tar", package = "satres") r <- sat_untarzip(c(f1, f2), only_show_files = TRUE)
satres
S3 classCreates a satres
object from a set of raster files.
satres(dir, out_dir = NULL, only_spectral_bands = TRUE)
satres(dir, out_dir = NULL, only_spectral_bands = TRUE)
dir |
A string or string vector, folder names. |
out_dir |
A string, output folder. |
only_spectral_bands |
A boolean, include only spectral bands. |
Given a folder name or a vector of folder names, containing satellite band raster files, creates an object containing all rasters grouped according to their spatial resolution.
If there are several rasters of the same area (tiles), it previously merges them to form a single raster of the total area.
A working folder where the virtual rasters are created can be indicated as a parameter. Additionally, we indicate whether we wish to process only the spectral band files (B1 to B12) or all available files.
A satres
object.
Other satellite definition:
get_band_names()
,
get_spatial_resolution()
,
get_spectral_band_names()
esa <- system.file("extdata", "esa", package = "satres") sr <- satres(dir = esa) sr <- satres(dir = esa, out_dir = tempdir(), only_spectral_bands = FALSE)
esa <- system.file("extdata", "esa", package = "satres") sr <- satres(dir = esa) sr <- satres(dir = esa, out_dir = tempdir(), only_spectral_bands = FALSE)
Saves multi-band raster files of the object according to its spatial resolution. The file names correspond to the resolution of each one.
save_by_resolution(sr, out_dir, only_show_files) ## S3 method for class 'satres' save_by_resolution(sr, out_dir = NULL, only_show_files = FALSE)
save_by_resolution(sr, out_dir, only_show_files) ## S3 method for class 'satres' save_by_resolution(sr, out_dir = NULL, only_show_files = FALSE)
sr |
A |
out_dir |
A string, output folder. |
only_show_files |
A boolean, only show the files that would be created, not create them. |
They are stored in the folder that is indicated or, if none is indicated, in the folder that was used to create the object.
A vector of strings, name of the saved files.
Other satellite exportation:
as_SpatRaster()
esa <- system.file("extdata", "esa", package = "satres") sr <- satres(dir = esa) f <- sr |> save_by_resolution(only_show_files = TRUE)
esa <- system.file("extdata", "esa", package = "satres") sr <- satres(dir = esa) f <- sr |> save_by_resolution(only_show_files = TRUE)
Select the bands of an object based on spatial resolution and band name.
select_bands(sr, res, bands) ## S3 method for class 'satres' select_bands(sr, res = NULL, bands = NULL)
select_bands(sr, res, bands) ## S3 method for class 'satres' select_bands(sr, res = NULL, bands = NULL)
sr |
A |
res |
A string, spatial resolution. |
bands |
A string, band name. |
A satres
object.
Other satellite transformation:
clip_bands()
,
merge_tiles()
esa <- system.file("extdata", "esa", package = "satres") sr <- satres(dir = esa) |> select_bands(res = c("r2000m", "r6000m"), bands = c("B02", "B03", "B04"))
esa <- system.file("extdata", "esa", package = "satres") sr <- satres(dir = esa) |> select_bands(res = c("r2000m", "r6000m"), bands = c("B02", "B03", "B04"))