library(sf)
library(tibble)
pts1 <- rbind(c(1, 2), c(3, 2))
comp1 <- component_from_sfg(st_multipoint(pts1), 0.2)
comp2 <- component_from_sfg(st_point(c(1, 5)), 0.8)
pp <- create_pgeometry(list(comp1, comp2), "PLATEAUPOINT")
# calculating the average degree and number of components of pp
spa_avg_degree(pp)
spa_ncomp(pp)
# calculating the area and perimeter
set.seed(345)
# some random points to create plateau region objects by using the function spa_creator
tbl = tibble(x = runif(10, min= 0, max = 20),
y = runif(10, min = 0, max = 30),
z = runif(10, min = 0, max = 100))
#getting the convex hull on the points to clip the construction of plateau region objects
pts <- st_as_sf(tbl, coords = c(1, 2))
ch <- st_convex_hull(do.call(c, st_geometry(pts)))
pregions <- spa_creator(tbl, fuzz_policy = "fcp", k = 2, base_poly = ch)
spa_area(pregions$pgeometry[[1]])
spa_area(pregions$pgeometry[[2]])
spa_perimeter(pregions$pgeometry[[1]])
spa_perimeter(pregions$pgeometry[[2]])
# calculating the length of a plateau line object
lpts1 <- rbind(c(0, 0), c(1, 1))
lpts2 <- rbind(c(1, 1), c(1.2, 1.9), c(2, 1))
lpts3 <- rbind(c(2, 1), c(1.5, 0.5))
cp1 <- component_from_sfg(st_linestring(lpts1), 0.4)
cp2 <- component_from_sfg(st_linestring(lpts2), 1)
cp3 <- component_from_sfg(st_linestring(lpts3), 0.7)
pline <- create_pgeometry(list(cp1, cp2, cp3), "PLATEAULINE")
spa_length(pline)
Run the code above in your browser using DataLab