Learn R Programming

plotKML (version 0.2-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

vect2rast(obj, ...)

Arguments

obj
Spatial-PointsDataFrame,-LinesDataFrame or -PolygonsDataFrame object
...
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 based on the properties of the input data set. The optimal 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)
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