geos_stats | R Documentation |
sfg
, sfc
and sf
objectsSummary statistical functions for sfg
, sfc
and sf
objects
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)
x |
object of class |
value |
object of class |
digits |
integer indicating the number of decimal places to be used (see
|
... |
passed on to |
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
).
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.