| Title: | Data Source Name and Description Helpers for Use with 'GDAL' |
|---|---|
| Description: | Simple helpers for 'GDAL' data source names ('DSN'), prefix and suffix and other handling. 'GDAL' is the Geospatial Data Abstraction Library <https://gdal.org/>, not used by this package directly. |
| Authors: | Michael Sumner [aut, cre], Matt Dowle [ctb] (original idea for C_addr, from data.table::address) |
| Maintainer: | Michael Sumner <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-07-17 16:55:39 UTC |
| Source: | https://github.com/cran/dsn |
Return the type name of the GDAL data type.
gdal_datatypes() datatype(x)gdal_datatypes() datatype(x)
x |
integer as returned by GDAL, or osgeo.gdal.Open().GetDatatype() |
character string of the type name (the name of the constant in GDAL, e.g. GDT_Byte)
datatype(1) names(gdal_datatypes())datatype(1) names(gdal_datatypes())
Create a set of GCPs (ground control points) from dimension, extent
gcp_extent(dimension, extent = NULL) gcp_extent_arg(gcp)gcp_extent(dimension, extent = NULL) gcp_extent_arg(gcp)
dimension |
size of grid 'ncol,nrow' |
extent |
extent 'xmin,xmax,ymin,ymax' |
gcp |
ground control point ('col,row,x,y') |
gcp_extent returns the col,row,x,y values, gcp_extent_arg returns
formatted as a GDAL 'vrt://' connection string
gcp_extent(c(10, 20)) dsn <- sprintf("vrt://%s?%s", mem(volcano), gcp_extent_arg(gcp_extent(dim(volcano)))) gcp <- gcp_extent(dim(volcano), c(-180, 180, -90, 90)) gcp_extent_arg(gcp)gcp_extent(c(10, 20)) dsn <- sprintf("vrt://%s?%s", mem(volcano), gcp_extent_arg(gcp_extent(dim(volcano)))) gcp <- gcp_extent(dim(volcano), c(-180, 180, -90, 90)) gcp_extent_arg(gcp)
An array in memory can be referenced by a GDAL data source. The DSN points
directly at the memory of x, no copy is made.
mem( x, extent = NULL, projection = "", dimension = NULL, PIXELOFFSET = NULL, LINEOFFSET = NULL, BANDOFFSET = NULL )mem( x, extent = NULL, projection = "", dimension = NULL, PIXELOFFSET = NULL, LINEOFFSET = NULL, BANDOFFSET = NULL )
x |
an R array of numeric (double) type, see Details |
extent |
optional extent of the data in x,y c(xmin, xmax, ymin, ymax) |
projection |
projection string (optional, sets the SPATIALREFERENCE of the MEM driver since GDAL 3.7) |
dimension |
size in pixels c(PIXELS, LINES), defaults to |
PIXELOFFSET |
pixel offset |
LINEOFFSET |
line offset |
BANDOFFSET |
band offset |
The DSN is only valid while x is alive and unmodified: keep a reference
to x for as long as the DSN is in use, or R's garbage collector may free
or reuse that memory. For the same reason x must already be a double
array (storage.mode(x) <- "double" to convert beforehand); mem() will
not convert it for you, because converting makes a temporary copy whose
memory does not survive this function returning.
This DSN only works in the current R session, with GDAL read and query
tools (terra, sf, gdalcubes, vapour, gdalraster, etc.). Since GDAL 3.10,
opening a MEM:::DATAPOINTER DSN is disabled by default for security
reasons: set the configuration option GDAL_MEM_ENABLE_OPEN=YES (e.g.
Sys.setenv(GDAL_MEM_ENABLE_OPEN = "YES")) to allow it.
dimension defaults to dim(x); for an R matrix that is (nrow, ncol)
used as (PIXELS, LINES), so GDAL scanlines run down the columns of the R
matrix (memory order is preserved, orientation is transposed relative to
the on-screen orientation of graphics::image()).
character string, a DSN for use by GDAL
mem(volcano) m <- matrix(c(0, 0, 0, 1), 5L, 4L) mem(m)mem(volcano) m <- matrix(c(0, 0, 0, 1), 5L, 4L) mem(m)
Add required prefixes, or remove them. The /vsiXXX/ prefixes chain, exactly
as GDAL's virtual filesystem chains, so they compose by nesting, e.g.
vsizip(vsicurl(x)) gives "/vsizip//vsicurl/<x>".
vsicurl(x, sign = FALSE) vsizip(x) vsis3(x) vsitar(x) vsigzip(x) driver(x, driver = "") netcdf(x) unprefix(x) unvsicurl(x)vsicurl(x, sign = FALSE) vsizip(x) vsis3(x) vsitar(x) vsigzip(x) driver(x, driver = "") netcdf(x) unprefix(x) unvsicurl(x)
x |
character vector, of data source names (file paths, urls, database connection strings, or GDAL dsn) |
sign |
configure for automatic Planetary Computer signing by GDAL |
driver |
character vector of appropriate GDAL driver name |
character vector
vsicurl("https://netcdf-r-us.org/f.nc") driver("somefile.h5", "HDF5") unvsicurl("/vsicurl/https://netcdf-r-us.org/f.nc") unprefix("NETCDF:/u/user/somefile.nc") ## chaining virtual filesystems vsizip(vsicurl("https://host/data.zip/inner/layer.shp")) ## MPC signing mpc <- "https://sentinel2l2a01.blob.core.windows.net/sentinel2-l2/.../T43DFE_B04_10m.tif" vsicurl(mpc , sign = TRUE)vsicurl("https://netcdf-r-us.org/f.nc") driver("somefile.h5", "HDF5") unvsicurl("/vsicurl/https://netcdf-r-us.org/f.nc") unprefix("NETCDF:/u/user/somefile.nc") ## chaining virtual filesystems vsizip(vsicurl("https://host/data.zip/inner/layer.shp")) ## MPC signing mpc <- "https://sentinel2l2a01.blob.core.windows.net/sentinel2-l2/.../T43DFE_B04_10m.tif" vsicurl(mpc , sign = TRUE)
Subdataset and VRT connection strings.
sds(x, varname, driver, quote = TRUE)sds(x, varname, driver, quote = TRUE)
x |
character vector, of data source names (file paths, urls, database connection strings, or GDAL dsn) |
varname |
named of variable in DSN |
driver |
driver to use, e.g. "NETCDF", "HDF5" |
quote |
wrap the core dsn in escaped double quotes, or not |
character string of the form "DRIVER:%s:varname"
f <- "myfile.nc" sds(f, "variable", "NETCDF", quote = FALSE)f <- "myfile.nc" sds(f, "variable", "NETCDF", quote = FALSE)
Create a vrt connection from an input string and named arguments.
vrtcon(x, ...)vrtcon(x, ...)
x |
character vector, of data source names (file paths, urls, database connection strings, or GDAL dsn) |
... |
named arguments like 'a_srs="OGC:CRS84" |
As of writing (GDAL 3.7.0DEV 2022-12-12) the only available named arguments are 'a_srs', 'bands', 'a_ullr' but that doesn't stop this function.
character string in the form "vrt://%s?arg1&arg2"
vrtcon("myfile.nc", a_ullr = "0,90,360,-90", bands="1,2,1")vrtcon("myfile.nc", a_ullr = "0,90,360,-90", bands="1,2,1")