R/to_wkt.R

Defines functions to_wkt_linestring to_wkt_poly to_wkt_pt

to_wkt_pt <- function(x, fmt) {
  sprintf(
    "POINT (%s)",
    paste0(format(x, nsmall = fmt, trim = TRUE), collapse = " ")
  )
}

to_wkt_poly <- function(x, fmt) {
  sprintf(
    "POLYGON ((%s))",
    paste0(vapply(x, function(z) paste0(format(z, nsmall = fmt, trim = TRUE),
                                        collapse = " "), ""), collapse = ", ")
  )
}

to_wkt_linestring <- function(x, fmt) {
  sprintf(
    "LINESTRING (%s)",
    paste0(vapply(x, function(z) paste0(format(z, nsmall = fmt, trim = TRUE),
                                        collapse = " "), ""), collapse = ", ")
  )
}
ropensci/randgeo documentation built on Sept. 12, 2022, 2:01 p.m.