Learn R Programming

gdalraster

Overview

gdalraster is an R interface to the Raster API of the Geospatial Data Abstraction Library (GDAL). Bindings to a subset of the GDAL Vector API are included to provide utilities for managing vector data sources. Bindings to the GDAL Virtual Systems Interface (VSI) support file system operations and binary I/O on URLs, cloud storage services, Zip/GZip/7z/RAR, and in-memory files, as well as regular file systems. Calling signatures resemble the native C, C++ and Python APIs provided by the GDAL project.

Bindings to GDAL are implemented in the exposed C++ class GDALRaster along with several stand-alone functions, supporting:

  • manual creation of uninitialized raster datasets
  • creation from existing raster as template
  • read/set raster dataset parameters and metadata
  • low-level I/O
  • build/read/set color tables and raster attribute tables
  • virtual raster (VRT) for virtual cropping, resampling, kernel filtering, mosaicing
  • gdalwarp wrapper for reproject/resample/crop/mosaic
  • coordinate transformation
  • spatial reference systems
  • GDAL algorithms (dem_proc(), polygonize(), rasterize(), ...)
  • OGR vector utilities (ogrinfo(), ogr2ogr(), ogr_manage interface)
  • copy files/move/rename/delete raster and vector datasets
  • create/append to Seek-Optimized ZIP (SOZip)
  • abstraction of file system operations on URLs and cloud storage
  • Standard C binary file I/O through VSI (class VSIFile)

Additional functionality includes:

  • class RunningStats calculates mean and variance in one pass, and tracks the min, max, sum, and count (i.e., summary statistics on a data stream). The input data values are not stored in memory, so this class can be used to compute statistics for very large data streams.
  • class CmbTable identifies and counts unique combinations of integer values using a hash table.
  • combine() overlays multiple rasters so that a unique ID is assigned to each unique combination of input values. Pixel counts for each unique combination are obtained, and combination IDs are optionally written to an output raster.
  • calc() evaluates an R expression for each pixel in a raster layer or stack of layers. Individual pixel coordinates are available as variables in the R expression, as either x/y in the raster projected coordinate system or inverse projected longitude/latitude.
  • plot_raster() displays raster data using base R graphics.

gdalraster may be useful in applications that need scalable, low-level I/O, or prefer a direct GDAL API. Comprehensive documentation is provided in the package and online.

Installation

Install the released version from CRAN with:

install.packages("gdalraster")

CRAN provides pre-compiled binary packages for Windows and macOS. These do not require any separate installation of external libraries for GDAL.

From source code

Linux

GDAL >= 3.1.0 built with GEOS is required, but a more recent GDAL version is recommended, e.g., >= 3.6.4. GDAL as of version 3.9 requires PROJ >= 6.3.1, but a more recent version of PROJ is also recommended. PROJ requires sqlite3, and libxml2 is required for the imported R package xml2.

On Ubuntu, recent versions of geospatial libraries can be installed from the ubuntugis-unstable PPA with the following commands:

sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt update
sudo apt install libgdal-dev libgeos-dev libproj-dev libsqlite3-dev libxml2-dev

The versions in ubuntugis-unstable generally work well and are more up-to-date, but less recent versions in the ubuntugis-stable PPA could be used instead.

Package sf provides helpful instructions for installing the geospatial libraries on other Linux distributions.

With the dependent libraries available on the system, install from CRAN:

install.packages("gdalraster")

Or install the development version from GitHub using package remotes:

remotes::install_github("USDAForestService/gdalraster")

Windows

RTools is needed to install from source on Windows. RTools since version 4.2 includes GDAL, PROJ and all other dependent libraries that are needed to compile gdalraster. Note that CRAN releases periodic revisions to RTools that often include updates to the libraries as new versions become available. For example, release 6104 of RTools 4.4 contains GDAL 3.8.4 and PROJ 9.3.1.

With RTools installed:

# Install the development version from GitHub
remotes::install_github("USDAForestService/gdalraster")

macOS

GDAL and PROJ can be installed with Homebrew:

brew install pkg-config gdal proj

Then configure.args may be needed:

# Install the development version from GitHub
remotes::install_github("USDAForestService/gdalraster", configure.args = "--with-proj-lib=$(brew --prefix)/lib/")

Caution seems warranted on macOS with regard to mixing a source installation with installation of binaries from CRAN.

From R-universe

R-universe provides pre-compiled binary packages for Windows and macOS that track the development version of gdalraster. New packages are built usually within ~1 hour of the most recent commit.

# Install the development version from r-universe
install.packages("gdalraster", repos = c("https://usdaforestservice.r-universe.dev", "https://cran.r-project.org"))

Documentation

Copy Link

Version

Install

install.packages('gdalraster')

Monthly Downloads

717

Version

1.11.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

June 13th, 2024

Functions in gdalraster (1.11.1)

apply_geotransform

Apply geotransform (raster column/row to geospatial x/y)
bandCopyWholeRaster

Copy a whole raster band efficiently
CmbTable-class

Class for counting unique combinations of integers
addFilesInZip

Create/append to a potentially Seek-Optimized ZIP file (SOZip)
bbox_from_wkt

Get the bounding box of a geometry specified in OGC WKT format
VSIFile-class

Class wrapping the GDAL VSIVirtualHandle API for binary file I/O
GDALRaster-class

Class encapsulating a raster dataset and associated band objects
DEFAULT_NODATA

List of default nodata values by raster data type
RunningStats-class

Class to calculate mean and variance in one pass
DEFAULT_DEM_PROC

List of default DEM processing options
bbox_transform

Transform a bounding box to a different projection
createColorRamp

Create a color ramp
bbox_intersect

Bounding box intersection / union
buildRAT

Build a GDAL Raster Attribute Table with VALUE, COUNT
combine

Raster overlay for unique combinations
calc

Raster calculation
buildVRT

Build a GDAL virtual raster from a list of datasets
copyDatasetFiles

Copy the files of a dataset
bbox_to_wkt

Convert a bounding box to POLYGON in OGC WKT format
create

Create a new uninitialized raster
dump_open_datasets

Report open datasets
g_binary_op

Binary operations on WKT geometries
deleteDataset

Delete named dataset
epsg_to_wkt

Convert spatial reference from EPSG code to OGC Well Known Text
createCopy

Create a copy of a raster
fillNodata

Fill selected pixels by interpolation from surrounding areas
displayRAT

Display a GDAL Raster Attribute Table
dem_proc

GDAL DEM processing
g_area

Compute the area of a geometry
g_transform

Apply a coordinate transformation to a WKT geometry
footprint

Compute footprint of a raster
gdal_formats

Retrieve information on GDAL format drivers for raster and vector
g_buffer

Compute buffer of a WKT geometry
g_binary_pred

Geometry binary predicates operating on WKT
g_distance

Compute the distance between two geometries
g_centroid

Compute the centroid of a geometry
getCreationOptions

Return the list of creation options of a GDAL driver
geos_version

Get GEOS version
g_name

Extract the geometry type name from a WKT geometry
get_num_cpus

Get the number of processors detected by GDAL
g_length

Compute the length of a geometry
get_pixel_line

Raster pixel/line from geospatial x,y coordinates
get_usable_physical_ram

Get usable physical RAM reported by GDAL
gdalraster-package

Bindings to the GDAL Raster API
gdal_version

Get GDAL version
has_geos

Is GEOS available?
polygonize

Create a polygon feature layer from raster data
plot_raster

Display raster data
ogr2ogr

Convert vector data between different formats
ogr_define

OGR feature class definition for vector data
inv_project

Inverse project geospatial x/y coordinates to longitude/latitude
inv_geotransform

Invert geotransform
ogr_manage

Utility functions for managing vector data sources
ogrinfo

Retrieve information about a vector data source
get_config_option

Get GDAL configuration option
g_is_empty

Test if a geometry is empty
proj_search_paths

Get or set search path(s) for PROJ resource files
get_cache_used

Get the size of memory in use by the GDAL block cache
push_error_handler

Push a new GDAL CPLError handler
g_is_valid

Test if a geometry is valid
http_enabled

Check if GDAL CPLHTTP services can be useful (libcurl)
read_ds

Convenience wrapper for GDALRaster$read()
has_spatialite

Is SpatiaLite available?
renameDataset

Rename a dataset
pop_error_handler

Pop error handler off stack
proj_networking

Check, enable or disable PROJ networking capabilities
rasterize

Burn vector geometries into a raster
rasterToVRT

Create a GDAL virtual raster derived from one source dataset
proj_version

Get PROJ version
rasterFromRaster

Create a raster from an existing raster as template
srs_is_same

Do these two spatial references describe the same system?
transform_xy

Transform geospatial x/y coordinates
vsi_clear_path_options

Clear path specific configuration options
srs_is_geographic

Check if WKT definition is a geographic coordinate system
srs_to_wkt

Convert various spatial reference formats to Well Known Text
set_config_option

Set GDAL configuration option
sieveFilter

Remove small raster polygons
vsi_constants

Constants for VSIFile$seek()
vsi_rmdir

Delete a directory
srs_is_projected

Check if WKT definition is a projected coordinate system
vsi_rename

Rename a file
vsi_read_dir

Read names in a directory
vsi_copy_file

Copy a source file to a target filename
vsi_mkdir

Create a directory
vsi_curl_clear_cache

Clean cache associated with /vsicurl/ and related file systems
translate

Convert raster data between different formats
vsi_get_fs_options

Return the list of options associated with a virtual file system handler
vsi_get_fs_prefixes

Return the list of virtual file system handlers currently registered
vsi_get_disk_free_space

Return free disk space available on the filesystem
vsi_get_file_metadata

Get metadata on files
vsi_supports_rnd_write

Return whether the filesystem supports random write
vsi_supports_seq_write

Return whether the filesystem supports sequential write
vsi_sync

Synchronize a source file/directory with a target file/directory
vsi_unlink

Delete a file
warp

Raster reprojection and mosaicing
vsi_unlink_batch

Delete several files in a batch
vsi_stat

Get filesystem object info
vsi_set_path_option

Set a path specific option for a given path prefix