Learn R Programming

plotKML (version 0.5-4)

vect2rast: Convert points, lines and/or polygons to rasters

Description

Converts any "SpatialPoints*", "SpatialLines*", or "SpatialPolygons*" object to a raster map, and (optional) writes it to an external file (GDAL-supported formats; writes to SAGA GIS format by default).

Usage

## S3 method for class 'SpatialPoints':
vect2rast(obj, fname = names(obj)[1], cell.size, bbox, 
      file.name, silent = FALSE, method = c("raster", "SAGA")[1], 
      FIELD = 0, MULTIPLE = 1, LINE_TYPE = 0, GRID_TYPE = 2, ...)
## S3 method for class 'SpatialLines':
vect2rast(obj, fname = names(obj)[1], cell.size, bbox, 
      file.name, silent = FALSE, method = c("raster", "SAGA")[1], 
      FIELD = 0, MULTIPLE = 1, LINE_TYPE = 1, GRID_TYPE = 2, ...)
## S3 method for class 'SpatialPolygons':
vect2rast(obj, fname = names(obj)[1], cell.size, bbox,
      file.name, silent = FALSE, method = c("raster", "SAGA")[1], 
      FIELD = 0, MULTIPLE = 0, LINE_TYPE = 1, GRID_TYPE = 2, ...)

Arguments

obj
Spatial-PointsDataFrame,-LinesDataFrame or -PolygonsDataFrame object
fname
character; target variable
cell.size
numeric; output cell size
bbox
matrix; output bounding box
file.name
character; (optional) output file name
silent
logical; specifies whether to print the output
method
character; output rasterization engine (either raster package or SAGA GIS)
FIELD
integer; target column in the output shape file (see rsaga.get.usage("grid_gridding", 0))
MULTIPLE
integer; method for multiple values (see rsaga.get.usage("grid_gridding", 0))
LINE_TYPE
integer; method for lines (see rsaga.get.usage("grid_gridding", 0))
GRID_TYPE
integer; preferred target grid type (see rsaga.get.usage("grid_gridding", 0))
...
additional arguments that can be passed to the raster::rasterize command

Value

  • Returns an object of type "SpatialGridDataFrame".

Details

This function basically extends the rasterize function available in the raster package. The advantage of vect2rast, however, is that it requires no input from the user's side i.e. it automatically determines the grid cell size and the bounding box based on the properties of the input data set. The grid cell size is estimated based on the density/size of features in the map (nndist function in http://www.spatstat.org{spatstat} package): (a) in the case of "SpatialPoints" cell size is determined as half the mean distance between the nearest points; (b) in the case of "SpatialLines" half cell size is determined as half the mean distance between the lines; (c) in the case of polygon data cell size is determined as half the median size (area) of polygons of interest. For more details see http://dx.doi.org/10.1016/j.cageo.2005.11.008{Hengl (2006)}. To process larger vector maps consider using method="SAGA".

References

  • Hengl T., (2006)http://dx.doi.org/10.1016/j.cageo.2005.11.008{Finding the right pixel size}. Computers and Geosciences, 32(9): 1283-1298.
  • Raster package (http://CRAN.R-project.org/package=raster)
  • SpatStat package (http://www.spatstat.org)

See Also

vect2rast.SpatialPoints, raster::rasterize, spatstat::nndist

Examples

Run this code
data(eberg)
library(sp)
library(maptools)
library(spatstat)
coordinates(eberg) <- ~X+Y
data(eberg_zones)
# point map:
x <- vect2rast(eberg, fname = "SNDMHT_A")
image(x)
# polygon map:
x <- vect2rast(eberg_zones)
image(x)
# for large data sets use SAGA GIS:
x <- vect2rast(eberg_zones, method = "SAGA")

Run the code above in your browser using DataLab