Learn R Programming

ursa (version 3.9.4)

polygonize: Raster to vector (polygon) conversion.

Description

Representing each raster cell as a polygon. In comparison to common GIS raster to vector conversion, where neighbor cells with the same value are combined to the single polygon, the number of output polygons is equal to number of non-NA values.

Usage

polygonize(obj, fname, engine = c("native", "sp", "sf"), verbose = NA, ...)

Arguments

obj

Object of class ursaRaster.

fname

Missing or character. If specified, then ESRI Shapefile is created. Default is missing.

engine

Character keyword from list c("native","sp","sf"). Define package with tools for creating spatial data. If engine="sp", then functions from package sp are used. If engine="sf", then functions from package sf are used. If engine="native", then appropriate package is used based on loaded namespaces before.

verbose

Logical. If TRUE then convertion is attended by progress bar. Default is NA; it means TRUE for engine="sp" and FALSE for engine="sp".

Additional arguments, which are passed to internal function for writing ESRI Shapefile.

compress

Logical. Should output ESRI Shapefile files be compressed by zip? Default is FALSE.

Value

If missing fname and tools from sp then object of class "SpatialPolygonsDataFrame" (package sp). If missing fname and tools from sf then object of class "sf" with geometry of class "sfc_POLYGON" (package sf).

If fname is specified, then NULL.

Details

Some GIS software (e.g., QGIS) has broad tools for display vector data. Excepting choroplets, it is assumed that visualization of each cell separately is more attractive than displaying of polygons with different forms, which are produced, for example, by GDAL convertion utillity gdal_polygonize.py.

Examples

Run this code
# NOT RUN {
session_grid(NULL)
a <- ursa_dummy(mul=1/16)
a <- a[a>100]
print(a)
print(band_mean(a))
b2 <- polygonize(a,engine="sp") ## try 'engine="sf"'
print(colMeans(spatial_data(b2),na.rm=TRUE))
print(ursa_bbox(a))
print(spatial_bbox(b2))
# }

Run the code above in your browser using DataLab