Skip to contents

Converts a dataframe with a column of characters containing the WKT encoded geometries into an sf object. The column is converted to sfc.

Usage

getgeometry(inventory, var)

Arguments

inventory

(data.frame) with a column of characters, which contains the WKT encoded geometries.

var

Name of the character column that holds WKT encoded geometries, as a data/env-variable.

Value

An sf object

Examples

data(Paracou6_2016)

felttrees <- Paracou6_2016 %>%
dplyr::filter(VernName == "wacapou") %>%
  dplyr::group_by(idTree) %>%
  dplyr::do(LocPts = # inform geometry.
       sf::st_point(c(.$Xutm,.$Yutm)) %>%
       sf::st_as_text()) %>% # as text to easy join with a non spacial table
  tidyr::unnest(LocPts) # here to pass from list to character

inventory <- dplyr::left_join(Paracou6_2016, felttrees, by = "idTree")

Rslt <- getgeometry (inventory, LocPts)

library(ggplot2)
ggplot() +
  geom_sf(data = Rslt)