Package 'dsn'

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, not used by this package directly.
Authors: Michael Sumner [aut, cre], Matt Dowle [ctb] (wrote the source code used here in C_addr, originally in data.table)
Maintainer: Michael Sumner <[email protected]>
License: MIT + file LICENSE
Version: 0.0.1.9011
Built: 2024-11-30 07:50:11 UTC
Source: https://github.com/hypertidy/dsn

Help Index


Return the type name of the GDAL data type.

Description

Return the type name of the GDAL data type.

Usage

gdal_datatypes()

datatype(x)

Arguments

x

integer as returned by GDAL, or osgeo.gdal.Open().GetDatatype()

Value

character string of the type name (the name of the constant in GDAL, e.g. GDT_Byte)

Examples

datatype(1)
names(gdal_datatypes())

Create a set of GCPs (ground control points) from dimension, extent

Description

Create a set of GCPs (ground control points) from dimension, extent

Usage

gcp_extent(dimension, extent = NULL)

gcp_extent_arg(gcp)

Arguments

dimension

size of grid 'ncol,nrow'

extent

extent 'xmin,xmax,ymin,ymax'

gcp

ground control point ('col,row,x,y')

Value

gcp_extent returns the col,row,x,y values, gcp_extent_arg returns formatted as a GDAL 'vrt://' connection string

Examples

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)

Generate a data source name (DSN) for the GDAL MEM driver

Description

An array in memory can be referenced by a GDAL data source.

Usage

mem(
  x,
  extent = NULL,
  projection = "",
  PIXELOFFSET = 0L,
  LINEOFFSET = 0L,
  BANDOFFSET = 1L
)

Arguments

x

an R array, must be of numeric type (integer is converted to double)

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)

Details

This DSN will only work in R, and is only for use with GDAL read and query tools (so terra, sf, gdalcubes, vapour, etc.).

Value

character string, a DSN for use by GDAL

Examples

m <- matrix(as.integer(c(0L, 0, 0, 1)), 5L, 4L)
mem(m)
mem(volcano)

Prefix handlers for GDAL data source names

Description

Add required prefixes, or remove them.

Usage

vsicurl(x, sign = FALSE)

driver(x, driver = "")

netcdf(x)

unprefix(x)

unvsicurl(x)

Arguments

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

Value

character vector

Examples

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")

## MPC signing
mpc <- "https://sentinel2l2a01.blob.core.windows.net/sentinel2-l2/.../T43DFE_B04_10m.tif"
vsicurl(mpc , sign = TRUE)

Wrapping handlers for GDAL data source names

Description

Subdataset and VRT connection strings.

Usage

sds(x, varname, driver, quote = TRUE)

Arguments

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

Value

character string of the form "DRIVER:%s:varname"

Examples

f <- "myfile.nc"
sds(f, "variable", "NETCDF", quote = FALSE)

VRT connection

Description

Create a vrt connection from an input string and named arguments.

Usage

vrtcon(x, ...)

Arguments

x

character vector, of data source names (file paths, urls, database connection strings, or GDAL dsn)

...

named arguments like 'a_srs="OGC:CRS84"

Details

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.

Value

character string in the form "vrt://%s?arg1&arg2"

Examples

vrtcon("myfile.nc", a_ullr = "0,90,360,-90", bands="1,2,1")