rm_largest_polygons: Filter out the Largest Polygon of each polygon slot of a...

Description Usage Arguments Value See Also Examples

View source: R/rm_largest_polygons.R

Description

Filter out the Largest Polygon of each polygon slot of a SpatialPolygon* object

Usage

1

Arguments

sppoly

SpatialPolygon* object as defined in package sp.

subset

a subsetting condition

Value

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.

See Also

largest_polygons

Examples

 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)

choisy/sptools documentation built on Aug. 22, 2019, 12:57 p.m.