vect2rast {plotKML} | R Documentation |
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).
## S4 method for signature '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, ... ) ## S4 method for signature '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, ... ) ## S4 method for signature '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, ... )
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 |
MULTIPLE |
integer; method for multiple values (see |
LINE_TYPE |
integer; method for lines (see |
GRID_TYPE |
integer; preferred target grid type (see |
... |
additional arguments that can be passed to the |
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 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 Hengl (2006). To process larger vector maps consider using method="SAGA"
.
Returns an object of type "SpatialGridDataFrame"
.
Tomislav Hengl
Hengl T., (2006) Finding the right pixel size. Computers and Geosciences, 32(9): 1283-1298.
Raster package (https://CRAN.R-project.org/package=raster)
SpatStat package (http://www.spatstat.org)
vect2rast.SpatialPoints
, raster::rasterize
, spatstat::nndist
## Not run: 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") ## End(Not run)