Learn R Programming

raster (version 1.6-10)

linesToRaster: Lines to raster

Description

Lines to raster conversion. Lines are rasterized by assining values to cells that are crossed by the lines.

Usage

linesToRaster(lns, raster, field=0, overlap='last', mask=FALSE, updateRaster=FALSE, updateValue="NA", filename="", ...)

Arguments

lns
SpatialLines or a SpatialLinesDataFrame object (sp package), or an object inheriting from SpatialLines
raster
RasterLayer object
field
The index of the column in lns (if it is a SpatialLinesDataFrame) to be transfered to the RasterLayer (or the name of that field)
overlap
Character. Determines what values to assign to cells with overlapping lines. Choose from 'first', 'last', 'sum', 'min', or 'max'
mask
Logical. If TRUE the values of the input RasterLayer are 'masked' by the lines. I.e. cells that are touched by the lines retain their values, the other cells become NA
updateRaster
Logical. If TRUE the values of the input RasterLayer are updated where the polygons overlap cells
updateValue
Character. Select areas to be updated with the lines values (if updateRaster == TRUE) by the current cell values. Either 'all', 'NA', '!NA', or 'zero'
filename
Character. output filename
...
Additional arguments. See Details.

Details

For SpatialLines, the 'field' argument is ignored. The line index is used as attribute. The following additional arguments can be passed, to replace default values for this function rll{ overwrite Logical. If TRUE, "filename" will be overwritten if it exists format Character. Output file type. See writeRaster datatype Character. Output data type. See dataType progress Character. "text", "window", or "" (the default, no progress bar) }

See Also

polygonsToRaster, pointsToRaster

Examples

Run this code
cds1 <- rbind(c(-180,-20), c(-140,55), c(10, 0), c(-140,-60))
cds2 <- rbind(c(-10,0), c(140,60), c(160,0), c(140,-55))
cds3 <- rbind(c(-125,0), c(0,60), c(40,5), c(15,-45))

lines <- SpatialLines(list(Lines(list(Line(cds1)), "1"), Lines(list(Line(cds2)), "2"), Lines(list(Line(cds3)), "3") ))

r <- raster(ncols=90, nrows=45)
r <- linesToRaster(lines, r)
plot(r)
plot(lines, add=TRUE)

r <- linesToRaster(lines, r, overlap='count')
plot(r)

r[] = 1:ncell(r)
r <- linesToRaster(lines, r, mask=TRUE)
plot(r)

Run the code above in your browser using DataLab