| selectSize | R Documentation |
Select the largest or smallest polygons or lines in a SpatVector, optionally providing a maximum number of selected features, filtering by a size threshold, dissolving adjacent features, and/or splitting multipart features into single parts.
## S4 method for signature 'SpatVector'
selectSize(x, n=Inf, largest=TRUE, threshold=NULL,
dissolve=FALSE, singleparts=TRUE)
x |
|
n |
optional integer value (default Inf) indicating the maximum number of largest or smallest features to select (if they pass the optional threshold) |
largest |
if |
threshold |
optional size threshold (area in square meters for polygons, length in meters for lines) above which (if |
dissolve |
if |
singleparts |
if |
Polygon size is calculated using expanse; line size is calculated using perim. The threshold is applied before selecting the requested number of features. If fewer than n features satisfy the threshold, only qualifying features are returned.
If dissolve=TRUE, features are aggregated before size calculation. If singleparts=TRUE, multipart features are disaggregated before size calculation.
SpatVector containing the selected features.
A. Márcia Barbosa
expanse, perim, selectHighest
f <- system.file("ex/lux.shp", package="terra")
v <- vect(f)
# Select the five largest polygons
large5 <- selectSize(v, n=5)
# Select the three smallest polygons
small3 <- selectSize(v, n=3, largest=FALSE)
# Select up to 4 largest polygons satisfying a given minimum area
large <- selectSize(v, n=4, threshold=260e+6)
## Not run:
plot(v)
polys(large5, col="red")
polys(small3, col="blue")
polys(large, col="gold", density=50)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.