# first way: providing sfg objects
library(sf)
pts <- rbind(c(1, 2), c(3, 2))
comp1 <- create_component(st_multipoint(pts), 0.2)
lpts <- rbind(c(2, 2), c(3, 3))
comp2 <- create_component(st_linestring(lpts), 0.1)
matrix_obj <- matrix(c(1,1,8,1,8,8,1,8,1,1), ncol = 2, byrow = TRUE)
rpts <- list(matrix_obj)
comp3 <- create_component(st_polygon(rpts), 0.4)
# second way: providing WKT representations
comp4 <- create_component("POINT(10 35)", 0.5)
comp5 <- create_component("MULTILINESTRING((-29 -27, -36 -31, -45 -33), (-45 -33, -46 -32))", 0.9)
comp6 <- create_component("POLYGON((75 29, 77 29, 77 29, 75 29))", 1)
# third way: providing WKB representations
wkb = structure(list("0x0101000020e610000000000000000000000000000000000040"), class = "WKB")
comp7 <- create_component(wkb, 0.8, EWKB = TRUE)
# fourth way: providing coordinate pairs
coords1 = rbind(c(2,2), c(3,3))
coords2 = rbind(c(1,1), c(3,2))
comp8 <- create_component(coords1, 0.45, type = "LINE")
comp9 <- create_component(coords2, 0.32, type = "POINT")
Run the code above in your browser using DataLab