spPoly2Rast: Spatial - Converts SpatialPolygons layer to raster.

View source: R/spPoly2Rast.R

spPoly2RastR Documentation

Spatial - Converts SpatialPolygons layer to raster.

Description

Converts SpatialPolygons layer to raster.

Usage

spPoly2Rast(
  polyv,
  polyv_dsn = NULL,
  polyv.att,
  polyv.lut = NULL,
  rastfn.template = NULL,
  NODATA = NULL,
  outfolder = NULL,
  outfn = "polyrast",
  outext = "img",
  outfn.pre = NULL,
  outfn.date = TRUE,
  overwrite = FALSE
)

Arguments

polyv

sf R object or String. Polygon data to convert to raster. Can be a spatial polygon object, full pathname to a shapefile, or name of a layer within a database.

polyv_dsn

String. Data source name (dsn; e.g., sqlite or shapefile pathname) of layer to convert. The dsn varies by driver. See gdal OGR vector formats (https://www.gdal.org/ogr_formats.html). Optional if polyv is sf object.

polyv.att

String. Name of attribute in polyv to rasterize.

polyv.lut

Data frame. Look up table of codes, if polyv.att is character or want to group codes.

rastfn.template

String. Full path name of raster to use as template for new raster.

NODATA

Number. The NODATA value for background values. If NODATA is NULL, and a NODATA value is defined on the rastfn.template raster, the default is the defined NODATA value, else it is defined based on its datatype (see DEFAULT_NODATA for default data values).

outfolder

String. If exportshp=TRUE, name of output folder. If NULL, the working directory is used.

outfn

String. Name of output raster. If NULL, default is 'polyrast'.

outext

String. Name of raster extension (fmt).

outfn.pre

String. Add a prefix to output name (e.g., "01").

outfn.date

Logical. If TRUE, add date to end of outfile (e.g., outfn_'date'.csv).

overwrite

Logical. If TRUE and exportshp=TRUE, overwrite files in outfolder.

Value

A list containing raster and raster information derived from the original polygon.

Note

On-the-fly projection conversion
The spTransform (sf) method is used for on-the-fly map projection conversion and datum transformation using PROJ.4 arguments. Datum transformation only occurs if the +datum tag is present in the both the from and to PROJ.4 strings. The +towgs84 tag is used when no datum transformation is needed. PROJ.4 transformations assume NAD83 and WGS84 are identical unless other transformation parameters are specified. Be aware, providing inaccurate or incomplete CRS information may lead to erroneous data shifts when reprojecting. See spTransform help documentation for more details.

If exportshp=TRUE:
The st_write (sf) function is called. The ArcGIS driver truncates variable names to 10 characters or less. Variable names are changed before export using an internal function (trunc10shp). If Spatial object has more than 1 record, it will be returned but not exported.

Author(s)

Tracey S. Frescino

Examples


# Get polygon vector layer from FIESTA external data
WYbhdistfn <- system.file("extdata",
                          "sp_data/WYbighorn_districtbnd.shp", 
                          package = "FIESTA")

# Turn polygon into raster
# Note: raster values must be numeric, therefore names were changed to
# numeric codes based on lookup table produced from the following code.                      
new_rast <- spPoly2Rast(polyv = WYbhdistfn,
                        polyv.att = "DISTRICTNA",
                        outfolder = tempdir())


FIESTA documentation built on Nov. 22, 2023, 1:07 a.m.