Description Usage Arguments Value See Also Examples
View source: R/rm_largest_polygons.R
Filter out the Largest Polygon of each polygon slot of a SpatialPolygon* object
1 | rm_largest_polygons(sppoly, subset)
|
sppoly |
|
subset |
a subsetting condition |
An object of the same class as sppoly
where, for each slot of
the polygons
element that originally contains more than one polygon,
the largest one has been removed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | library(sf)
vn_prov <- gadmVN::gadm()
vn_prov <- sf::as_Spatial(vn_prov)
vn_prov2 <- rm_largest_polygons(vn_prov)
sp::plot(vn_prov)
sp::plot(vn_prov2)
# same with the country level:
vn <- gadmVN::gadm(level = "country")
vn <- sf::as_Spatial(vn)
vn2 <- rm_largest_polygons(vn)
rgeos::gEnvelope(vn)
# extracting the largest polygon only for Da Nang:
vn_prov3 <- rm_largest_polygons(vn_prov, province == "Da Nang")
sp::plot(vn_prov3)
# extracting the largest polygon only for Da Nang and Khanh Hoa:
vn_prov4 <- rm_largest_polygons(vn_prov, province %in% c("Da Nang", "Khanh Hoa"))
sp::plot(vn_prov4)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.