areas: Areas of the Polygons of a SpatialPolygon* Object

Description Usage Arguments Value Examples

View source: R/areas.R

Description

Returns a list of the areas of all the Polygon objects of the polygons slot of a SpatialPolygon* object.

Usage

1
areas(sppoly)

Arguments

sppoly

SpatialPolygon* object as defined in package sp.

Value

A list of same length as the input SpatialPolygon* object. Each slot of the list is a numeric vector, the lenght of which is equal to the number of Polygon objects constituing the polygon entity. Each of these values are the areas of the of the Polygon objects, expressed in the unit of the CRS.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
library(sf)
# working on the provinces polygons of Vietnam:
vn_prov <- gadmVN::gadm()
vn_prov <- sf::as_Spatial(vn_prov)
poly_areas <- areas(vn_prov)
# we can see that some of the polygons are made of several polygons:
sapply(poly_areas, length)
# we can verify that it sums well for the whole country
rgeos::gArea(vn_prov)
sum(sapply(poly_areas, sum))
# as well as for each province:
cbind(rgeos::gArea(vn_prov, TRUE), sapply(poly_areas, sum))

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