View source: R/rasterizeToReference.R
rasterizeToReference | R Documentation |
This function rasterizes vector data into a file that coincides (same extent, cellsize, projection, and cell alignment) with a reference raster file.
rasterizeToReference(
source,
destination,
reference,
burn,
attribute,
init,
type = "Byte",
allTouched = FALSE,
sql
)
source |
(character) path to a vector GIS file (such as a shapefile) that contains data to be rasterized. |
destination |
(character) path to a |
reference |
(character) path to a raster dataset
that defines the extent, cellsize, and projection of |
burn |
(optional, numeric) value to be burnt into grid
(everywhere the |
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.
|
type |
the type of grid to create.
Should be one of |
allTouched |
(optional, logical) defaults to |
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. |
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.
This function creates a new raster or writes values to an existing raster at the destination. It does not return anything.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.