Parses a GDAL VRT file, validates that it is a simple mosaic, computes tile footprint polygons from the DstRect pixel coordinates and GeoTransform, and writes a GTI-compatible vector dataset (GeoPackage by default) with appropriate layer metadata.

vrt_to_gti(
  dsn,
  output,
  layer = "tile_index",
  location_field = "location",
  relative_paths = FALSE,
  overwrite = FALSE
)

Arguments

dsn

Character string. Path or URL to a VRT file. Supports /vsicurl/ prefixed URLs.

output

Character string. Output file path. The format is inferred from the extension: .gpkg for GeoPackage (default recommendation), .fgb for FlatGeoBuf. These formats support layer metadata required by GTI.

layer

Character string. Layer name in the output dataset. Defaults to "tile_index".

location_field

Character string. Name of the field that stores tile file paths. Defaults to "location" (the GTI default).

relative_paths

Logical. If TRUE, store paths relative to the output file location. If FALSE (default), store absolute/resolved paths.

overwrite

Logical. If TRUE, delete existing output file before writing.

Value

Invisibly, the output file path. The file can be opened as a GTI raster datasource, e.g. GTI:<output>.

Details

The function performs the following steps:

  1. Parse: Read the VRT XML and extract source information.

  2. Validate: Ensure the VRT is a simple mosaic (SimpleSource only, consistent bands, no resampling).

  3. Compute extents: Convert DstRect pixel coordinates to geographic extents using the VRT's GeoTransform. Extents are pixel-edge aligned.

  4. Resolve paths: Handle relativeToVRT attributes, resolving source file paths against the VRT location.

  5. Write: Create a GeoPackage (or FlatGeoBuf) with polygon footprints and a location field, using gdalraster::GDALVector.

  6. Set metadata: Write GTI layer metadata items (RESX, RESY, MINX, MINY, MAXX, MAXY, BAND_COUNT, DATA_TYPE, NODATA, SRS).

Examples

if (FALSE) { # \dontrun{
vrt_to_gti(
  dsn = "/vsicurl/https://example.com/REMA-2m_dem_ovr.vrt",
  output = "rema_tiles.gpkg"
)

# Open with GDAL
library(gdalraster)
ds <- new(GDALRaster, "GTI:rema_tiles.gpkg")
} # }