polygonize: Raster to vector (polygon) conversion.

polygonizeR Documentation

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", "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", "sf"). Define package with tools for creating spatial data. If suggested packaged "sp" is loaded or can be loaded from default location, then "sp" is added to this list. If engine="sf", then functions from package sf are used. If engine="sp", then functions from package sp 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.

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.

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.

Note

Implementation is very slow even for moderate image size. Use progress bar (verbose=TRUE) to control this process.

Author(s)

Nikita Platonov platonov@sevin.ru

Examples

session_grid(NULL)
a <- ursa_dummy(mul=1/16)
a <- a[a>100]
print(a)
print(band_mean(a))
b2 <- polygonize(a,engine=ifelse(requireNamespace("sp"),"sp","sf"))
print(class(b2))
print(colMeans(spatial_data(b2),na.rm=TRUE))
str(e1 <- spatial_bbox(a))
str(e2 <- spatial_bbox(b2))
print(as.numeric(e1))
print(as.numeric(e2))

ursa documentation built on Sept. 30, 2024, 9:35 a.m.