This accessory function interfaces with GDAL utilities (sen2r must be interfaced with a runtime GDAL environment, see check_gdal()). Python-based utilities are always called from a runtime GDAL; C-based ones are called using sf::gdal_utils().

gdalUtil(
  util = "info",
  source,
  destination = character(0),
  options = character(0),
  quiet = FALSE,
  formula = character(0),
  processing = character(0),
  colorfilename = character(0)
)

Arguments

util

Character: one among "info", "translate", "warp", "demprocessing" ,"buildvrt" (C-based), "calc" and "fillnodata" (Python-based). Other utilities were not implemented, since they are not used by sen2r.

source

path of input layer(s); for calc this can be more than one.

destination

Path of the output layer.

options

Character vector with GDAL options.

quiet

Logical: if TRUE, suppress printing of output for info (this argument is ignored in case package sys is not installed).

formula

(for util = "calc") Calculation in gdalnumeric syntax using +, -, /, *, or any numpy array functions (i.e. log10()).

processing

Character: processing options for util = "demprocessing".

colorfilename

Character: name of colour file for util = "demprocessing" (mandatory if processing="color-relief").

Value

A logical (invisible) indicating success (i.e., TRUE); in case of failure, an error is raised and FALSE is returned (in case of Python-based utilities).

Note

License: GPL 3.0

References

L. Ranghetti, M. Boschetti, F. Nutini, L. Busetto (2020). "sen2r": An R toolbox for automatically downloading and preprocessing Sentinel-2 satellite data. Computers & Geosciences, 139, 104473. DOI: 10.1016/j.cageo.2020.104473, URL: http://sen2r.ranghetti.info/.

Author

Luigi Ranghetti, phD (2020) luigi@ranghetti.info

Examples

# Define product names examplename <- system.file( "extdata/out/S2A2A_20190723_022_Barbellino_BOA_10.tif", package = "sen2r" ) # \donttest{ ## gdalinfo out0 <- gdalUtil("info", examplename, quiet = TRUE) message(out0)
#> Driver: GTiff/GeoTIFF #> Files: /home/lranghetti/share/git/github/ranghetti/sen2r/inst/extdata/out/S2A2A_20190723_022_Barbellino_BOA_10.tif #> Size is 24, 42 #> Coordinate System is: #> PROJCRS["WGS 84 / UTM zone 32N", #> BASEGEOGCRS["WGS 84", #> DATUM["World Geodetic System 1984", #> ELLIPSOID["WGS 84",6378137,298.257223563, #> LENGTHUNIT["metre",1]]], #> PRIMEM["Greenwich",0, #> ANGLEUNIT["degree",0.0174532925199433]], #> ID["EPSG",4326]], #> CONVERSION["UTM zone 32N", #> METHOD["Transverse Mercator", #> ID["EPSG",9807]], #> PARAMETER["Latitude of natural origin",0, #> ANGLEUNIT["degree",0.0174532925199433], #> ID["EPSG",8801]], #> PARAMETER["Longitude of natural origin",9, #> ANGLEUNIT["degree",0.0174532925199433], #> ID["EPSG",8802]], #> PARAMETER["Scale factor at natural origin",0.9996, #> SCALEUNIT["unity",1], #> ID["EPSG",8805]], #> PARAMETER["False easting",500000, #> LENGTHUNIT["metre",1], #> ID["EPSG",8806]], #> PARAMETER["False northing",0, #> LENGTHUNIT["metre",1], #> ID["EPSG",8807]]], #> CS[Cartesian,2], #> AXIS["(E)",east, #> ORDER[1], #> LENGTHUNIT["metre",1]], #> AXIS["(N)",north, #> ORDER[2], #> LENGTHUNIT["metre",1]], #> USAGE[ #> SCOPE["unknown"], #> AREA["World - N hemisphere - 6°E to 12°E - by country"], #> BBOX[0,6,84,12]], #> ID["EPSG",32632]] #> Data axis to CRS axis mapping: 1,2 #> Origin = (580560.000000000000000,5102120.000000000000000) #> Pixel Size = (10.000000000000000,-10.000000000000000) #> Metadata: #> AREA_OR_POINT=Area #> Image Structure Metadata: #> COMPRESSION=DEFLATE #> INTERLEAVE=PIXEL #> Corner Coordinates: #> Upper Left ( 580560.000, 5102120.000) ( 10d 2'30.01"E, 46d 4' 4.47"N) #> Lower Left ( 580560.000, 5101700.000) ( 10d 2'29.75"E, 46d 3'50.86"N) #> Upper Right ( 580800.000, 5102120.000) ( 10d 2'41.18"E, 46d 4' 4.37"N) #> Lower Right ( 580800.000, 5101700.000) ( 10d 2'40.92"E, 46d 3'50.76"N) #> Center ( 580680.000, 5101910.000) ( 10d 2'35.47"E, 46d 3'57.61"N) #> Band 1 Block=24x15 Type=UInt16, ColorInterp=Gray #> NoData Value=65535 #> Band 2 Block=24x15 Type=UInt16, ColorInterp=Undefined #> NoData Value=65535 #> Band 3 Block=24x15 Type=UInt16, ColorInterp=Undefined #> NoData Value=65535 #> Band 4 Block=24x15 Type=UInt16, ColorInterp=Undefined #> NoData Value=65535 #> Band 5 Block=24x15 Type=UInt16, ColorInterp=Undefined #> NoData Value=65535 #> Band 6 Block=24x15 Type=UInt16, ColorInterp=Undefined #> NoData Value=65535 #> Band 7 Block=24x15 Type=UInt16, ColorInterp=Undefined #> NoData Value=65535 #> Band 8 Block=24x15 Type=UInt16, ColorInterp=Undefined #> NoData Value=65535 #> Band 9 Block=24x15 Type=UInt16, ColorInterp=Undefined #> NoData Value=65535 #> Band 10 Block=24x15 Type=UInt16, ColorInterp=Undefined #> NoData Value=65535 #> Band 11 Block=24x15 Type=UInt16, ColorInterp=Undefined #> NoData Value=65535
## gdal_translate outname1 <- tempfile(fileext = ".tif") gdalUtil( "translate", examplename, outname1, options = c("-tr", "2", "2", "-r", "cubicspline", "-co", "COMPRESS=DEFLATE") )
#> 0...10...20...30...40...50...60...70...80...90...100 - done.
oldpar <- par(mfrow = c(1,2), mar = rep(0,4)) image(stars::read_stars(examplename), rgb = c(11,8,4))
#> Error in if (!useRaster) stop("rgb plotting not supported on this device"): valore mancante dove è richiesto TRUE/FALSE
image(stars::read_stars(outname1), rgb = c(11,8,4))
#> Error in if (!useRaster) stop("rgb plotting not supported on this device"): valore mancante dove è richiesto TRUE/FALSE
## gdalwarp outname2 <- tempfile(fileext = ".tif") gdalUtil( "warp", examplename, outname2, options = c("-t_srs", "EPSG:32633", "-co", "COMPRESS=DEFLATE") ) oldpar <- par(mfrow = c(1,2), mar = rep(0,4)) image(stars::read_stars(examplename), rgb = c(11,8,4))
#> Error in if (!useRaster) stop("rgb plotting not supported on this device"): valore mancante dove è richiesto TRUE/FALSE
image(stars::read_stars(outname2), rgb = c(11,8,4))
#> Error in if (!useRaster) stop("rgb plotting not supported on this device"): valore mancante dove è richiesto TRUE/FALSE
## gdal_calc outname3 <- tempfile(fileext = ".tif") ndvirefname <- system.file( "extdata/out/S2A2A_20190723_022_Barbellino_NDVI_10.tif", package = "sen2r" ) gdalUtil( "calc", rep(examplename,2), outname3, formula = "10000*(A.astype(float)-B)/(A+B)", options = c("--A_band", "8", "--B_band", "4", "--type", "Int16") ) oldpar <- par(mfrow = c(1,2), mar = rep(0,4)) image(stars::read_stars(ndvirefname))
#> Error in if (useRaster) { if (check_irregular(x, y)) stop(gettextf("%s can only be used with a regular grid", sQuote("useRaster = TRUE")), domain = NA) if (!is.character(col)) { col <- as.integer(col) if (any(!is.na(col) & col < 0L)) stop("integer colors must be non-negative") col[col < 1L] <- NA_integer_ p <- palette() col <- p[((col - 1L)%%length(p)) + 1L] } zc <- col[zi + 1L] dim(zc) <- dim(z) zc <- t(zc)[ncol(zc):1L, , drop = FALSE] rasterImage(as.raster(zc), min(x), min(y), max(x), max(y), interpolate = FALSE)} else .External.graphics(C_image, x, y, zi, col): valore mancante dove è richiesto TRUE/FALSE
image(stars::read_stars(outname3))
#> Error in if (useRaster) { if (check_irregular(x, y)) stop(gettextf("%s can only be used with a regular grid", sQuote("useRaster = TRUE")), domain = NA) if (!is.character(col)) { col <- as.integer(col) if (any(!is.na(col) & col < 0L)) stop("integer colors must be non-negative") col[col < 1L] <- NA_integer_ p <- palette() col <- p[((col - 1L)%%length(p)) + 1L] } zc <- col[zi + 1L] dim(zc) <- dim(z) zc <- t(zc)[ncol(zc):1L, , drop = FALSE] rasterImage(as.raster(zc), min(x), min(y), max(x), max(y), interpolate = FALSE)} else .External.graphics(C_image, x, y, zi, col): valore mancante dove è richiesto TRUE/FALSE
# }