Skip to content

Commit

Permalink
(conditionally) use lwgeom::st_astext; #800
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Dec 7, 2018
1 parent 4eaaf08 commit 90821d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Suggests:
dplyr (>= 0.7-0),
ggplot2,
knitr,
lwgeom (>= 0.1-2),
lwgeom (>= 0.1-5),
maps,
maptools,
mapview,
Expand Down
19 changes: 13 additions & 6 deletions R/wkt.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ st_as_text = function(x, ...) UseMethod("st_as_text")
#' st_as_text(st_point(1:2))
#' st_as_text(st_sfc(st_point(c(-90,40)), crs = 4326), EWKT = TRUE)
st_as_text.sfg = function(x, ...) {
switch(class(x)[2],
if (Sys.getenv("LWGEOM_WKT") == "true" && requireNamespace("lwgeom", quietly = TRUE) && utils::packageVersion("lwgeom") >= "0.1-5")
lwgeom::st_astext(x, ...)
else
switch(class(x)[2],
POINT = prnt.POINT(x, ...),
MULTIPOINT = prnt.MULTIPOINT(x, ...),
LINESTRING = prnt.LINESTRING(x, ...),
Expand All @@ -108,12 +111,16 @@ st_as_text.sfg = function(x, ...) {
#' @param EWKT logical; if TRUE, print SRID=xxx; before the WKT string if \code{epsg} is available
#' @export
st_as_text.sfc = function(x, ..., EWKT = FALSE) {
if (EWKT) {
epsg = attr(x, "crs")$epsg
if (!is.na(epsg) && epsg != 0)
x = lapply(x, function(sfg) structure(sfg, epsg = epsg))
if (Sys.getenv("LWGEOM_WKT") == "true" && requireNamespace("lwgeom", quietly = TRUE) && utils::packageVersion("lwgeom") >= "0.1-5")
lwgeom::st_astext(x, ..., EWKT = EWKT)
else {
if (EWKT) {
epsg = attr(x, "crs")$epsg
if (!is.na(epsg) && epsg != 0)
x = lapply(x, function(sfg) structure(sfg, epsg = epsg))
}
vapply(x, st_as_text, "", ..., EWKT = EWKT)
}
vapply(x, st_as_text, "", ..., EWKT = EWKT)
}

#' @name st_as_sfc
Expand Down

0 comments on commit 90821d8

Please sign in to comment.