Note can use scale=0,1 to convert literally any raster to image this way too.

gdal_raster_nara(
  dsn,
  target_crs = "",
  target_ext = numeric(),
  target_dim = numeric(),
  target_res = numeric(),
  bands = NULL,
  resample = "near",
  silent = FALSE,
  options = ""
)

Arguments

dsn

a raster source for GDAL

target_crs

target crs (optional)

target_ext

target extent (optional, xmin,xmax,ymin,ymax)

target_dim

target dimension (optional, ncol,nrow - one value can be 0)

target_res

target resolution (optional, resx, resy)

bands

which bands to read (we could read just the second green band, for example)

resample

optional resampling algo (near is default, use bilinear or cubic or see GDAL doc)

silent

keep quiet

options

options for the gdalwarp binary (can use c("-tr", xres, yres) in place of target_res for example)

Value

list in ximage() gdal_raster_ format as per vapour package

Examples

dsn <- "vrt:///vsicurl/http://s3.amazonaws.com/com.modestmaps.bluemarble/0-r0-c0.jpg"
dsn <- paste0(dsn, "?a_ullr=-20037508,20037508,20037508,-20037508&a_srs=EPSG:900913")
gdal_raster_nara(dsn, target_dim = c(36, 36))
#> gdalinfo - unable to open 'vrt:///vsicurl/http://s3.amazonaws.com/com.modestmaps.bluemarble/0-r0-c0.jpg?a_ullr=-20037508,20037508,20037508,-20037508&a_srs=EPSG:900913'.
#> Error in vapour_raster_info(dsn[1]): GDAL was unable to open ^^
#png <- system.file("img", "Rlogo.png", package="png")
## for dumb imagery we need to specify NO_GEOTRANSFORM or set the native affine transform
#gdal_raster_nara(sprintf("vrt://%s?a_gt =0,1,0,76,0,-1", png)) #, options = c("-to", "SRC_METHOD=NO_GEOTRANSFORM"))