geos_stats: Summary statistical functions for 'sfg', 'sfc' and 'sf'...

geos_statsR Documentation

Summary statistical functions for sfg, sfc and sf objects

Description

Summary statistical functions for sfg, sfc and sf objects

Usage

st_geometry_summary(x)

st_area_sum(x, value, digits, ...)

st_length_sum(x, value, digits, ...)

st_perimeter_sum(x, value, digits, ...)

st_perimeter_2d_sum(x, value, digits)

Arguments

x

object of class sfg, sfc or sf

value

object of class units or symbolic_units (see examples section of units() <- value), optional: if unspecified, the default unit of the output is returned

digits

integer indicating the number of decimal places to be used (see round), optional: if unspecified, the output is not rounded

...

passed on to s2_distance or s2_distance_matrix

Value

st_geometry_summary() returns a vector with counts of the geometry types include in x, which is named by the occurring geometry type(s). If a function of the type st_measure_sum() is executed, the sum of these very measures from all geometries included in x is returned, if specified in a certain unit and rounded by given digits (see st_area, st_length, st_perimeter resp. st_perimeter_2d).

Examples

library(sf)
# some demo data
mat      <- rbind(0:3, log(4:1))*1000 + rep(c(26, 12), 4)*10^5
points   <- st_sfc(lapply(data.frame(mat), st_point)) %>% st_set_crs(2056)
polygons <- points %>% st_buffer(., seq_along(.)*150)

mix <- c(points, polygons)
st_geometry_summary(mix)

st_area_sum(polygons)
st_area_sum(polygons, "ha", 2)
st_area_sum(polygons, "km^2", 3)

# if geometries' dimension and measure don't fit:
st_length_sum(polygons)

st_perimeter_sum(polygons, "km", 1)

# specifying only units doesn't effect comparison:
st_area_sum(polygons, "km^2") == st_area_sum(polygons, "ha")
# but setting units and rounding by digits argument can mess up comparison:
st_area_sum(polygons, "km^2") == st_area_sum(polygons, "ha", 0)
# if equivalent units-digits-specifying is done, comparison is feasible:
st_area_sum(polygons, "km^2", 2) == st_area_sum(polygons, "ha", 0)
# but to avoid a mess don't specify the digits before comparing

# similarly if returns are used in further calculations then don't specify
# the digits to avoid passing on rounding errors
(ratio <- st_perimeter_sum(polygons) / st_area_sum(polygons, "ha"))
# rounding can be done later on
round(ratio)

a-benini/sfhelpers documentation built on Aug. 28, 2024, 3:30 a.m.