rasterizeToReference: Rasterize vector data

View source: R/rasterizeToReference.R

rasterizeToReferenceR Documentation

Rasterize vector data

Description

This function rasterizes vector data into a file that coincides (same extent, cellsize, projection, and cell alignment) with a reference raster file.

Usage

rasterizeToReference(
  source,
  destination,
  reference,
  burn,
  attribute,
  init,
  type = "Byte",
  allTouched = FALSE,
  sql
)

Arguments

source

(character) path to a vector GIS file (such as a shapefile) that contains data to be rasterized.

destination

(character) path to a .tif file that will either be created or added to.

reference

(character) path to a raster dataset that defines the extent, cellsize, and projection of destination if destination does not already exist.

burn

(optional, numeric) value to be burnt into grid (everywhere the source has data)

attribute

(optional, character) the column name in the source to extract values from

init

(optional, numeric) if supplied this value will be written into the grid as a background value prior to rasterizing. init can only be used if the destination does not already exist.

type

the type of grid to create. Should be one of "Byte", "UInt16", "Int16", "UInt32", "Int32", "Float32","Float64" or for convenience you may also use the terra package's designations.

allTouched

(optional, logical) defaults to FALSE. If TRUE "all pixels touched by lines or polygons will be updated, not just those on the line render path, or whose center point is within the polygon" see "-at" flag description for gdal_rasterize

sql

(optional, character) An SQL statement to be applied to the data source. This can be used to filter or sort the data prior to burning.

Details

If the file at destination exists the new pixels will be overlaid on existing data such that existing data will persist where it does not underlie the vector data in source.

Either the burn or attribute argument should be used to set the value assigned to cells. The default type ("Byte") supports integers 0 to 255. If you are writing real numbers or outside of that range be sure to set type to something appropriate. Similarly, if you are only writing a few values you may want to set type to something that supports fewer values such as "Byte".

When creating a new file the CRS of the source must match that of the reference and this used to be checked with raster::compareCRS() but with updates to the PROJ library and the switch to WKT representations I don't currently have a good way to check if two projections are equivalent. Its now up to the user to make sure that they are.

In contrast if you are overlaying data on an existing file then the underlying gdal_rasterize function will reproject while rasterizing.

Value

This function creates a new raster or writes values to an existing raster at the destination. It does not return anything.


ethanplunkett/rasterPrep documentation built on Sept. 17, 2024, 1:05 p.m.