-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adds `st_astext` and `st_asewkb` * enables `lwgeom_to_wkt` through `CPL_sfc_to_wkt`
- Loading branch information
Showing
9 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,4 +40,5 @@ Collate: | |
perimeter.R | ||
clockwise.R | ||
geod.R | ||
wkt.R | ||
RoxygenNote: 6.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#' Return Well-known Text representation of simple feature geometry | ||
#' | ||
#' Return Well-known Text representation of simple feature geometry or coordinate reference system | ||
#' @param x object of class `sfg`, `sfc` or `crs`` | ||
#' @param precision number of digits to print | ||
#' @param EWKT Use Postgis Enhanced WKT (includes srid) | ||
#' @name st_astext | ||
#' @details The returned WKT representation of simple feature geometry conforms to the | ||
#' [simple features access](http://www.opengeospatial.org/standards/sfa) specification and extensions (if `EWKT = TRUE`), | ||
#' [known as EWKT](http://postgis.net/docs/using_postgis_dbmanagement.html#EWKB_EWKT), supported by | ||
#' PostGIS and other simple features implementations for addition of SRID to a WKT string. | ||
#' @md | ||
#' @examples | ||
#' library(sf) | ||
#' pt <- st_sfc(st_point(c(1.0002,2.3030303)), crs = 4326) | ||
#' st_astext(pt, 3, TRUE) | ||
#' @export | ||
st_astext <- function(x, precision = 12, EWKT = FALSE) { | ||
if (!EWKT) st_crs(x) <- NA_crs_ | ||
CPL_sfc_to_wkt(x, precision = precision) | ||
} | ||
|
||
#' @name st_astext | ||
#' @inheritParams st_astext | ||
#' @details `st_asewkt()` returns the Well-Known Text (WKT) representation of | ||
#' the geometry with SRID meta data. | ||
#' @md | ||
#' @export | ||
st_asewkt <- function(x, precision) { | ||
st_astext(x, precision, EWKT = TRUE) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
context("test-as_text.R") | ||
library(sf) | ||
|
||
test_that("Prints Points", { | ||
pt <- st_sfc(st_point(c(1.0002,2.3030303)), crs = 4326) | ||
expect_equal(st_astext(pt, 3), "SRID=4326;POINT(1 2.3)") | ||
expect_equal(st_astext(pt, 3, FALSE), "POINT(1 2.3)") | ||
expect_equal(st_astext(pt, 4, FALSE), "POINT(1 2.303)") | ||
expect_equal(st_astext(pt, 10, FALSE), "POINT(1.0002 2.3030303)") | ||
}) | ||
|
||
test_that("Prints Polygons and Lines", { | ||
pol <- st_sfc(st_polygon(list( | ||
rbind(c(0,0),c(0.5,0),c(0.5,0.5),c(0.5,0),c(1,0),c(1,1),c(0,1),c(0,0)) | ||
))) | ||
txt <- "POLYGON((0 0,0.5 0,0.5 0.5,0.5 0,1 0,1 1,0 1,0 0))" | ||
expect_equal(st_astext(pol), txt) | ||
ln <- st_cast(pol, "LINESTRING") | ||
txt <- "LINESTRING(0 0,0.5 0,0.5 0.5,0.5 0,1 0,1 1,0 1,0 0)" | ||
expect_equal(st_astext(ln), txt) | ||
}) |