R/to_wkt.R

Defines functions to_wkt_pt to_wkt_poly to_wkt_linestring

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 = ", ")
  )
}

Try the randgeo package in your browser

Any scripts or data that you put into this service are public.

randgeo documentation built on May 2, 2019, 5:15 a.m.