Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
paleolimbot committed Apr 30, 2020
1 parent 6c47cbf commit 55063e0
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 4 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export(wkb_problems)
export(wkb_translate_wkb)
export(wkb_translate_wkt)
export(wkt_debug)
export(wkt_problems)
export(wkt_streamer_debug)
export(wkt_translate_wkb)
export(wkt_translate_wkt)
Expand Down
13 changes: 12 additions & 1 deletion R/debug.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,28 @@
#' custom C++ handlers and debugging read problems.
#'
#' @inheritParams wkb_translate_wkt
#'
#' @return The input, invisibly
#' @export
#'
#' @examples
#' wkt_debug("MULTIPOLYGON (((0 0, 10 0, 0 10, 0 0)))")
#' wkt_streamer_debug("MULTIPOLYGON (((0 0, 10 0, 0 10, 0 0)))")
#' wkb_debug(
#' wkt_translate_wkb(
#' "MULTIPOLYGON (((0 0, 10 0, 0 10, 0 0)))"
#' )
#' )
#'
wkb_debug <- function(wkb) {
cpp_debug_wkb(wkb)
invisible(wkb)
}

#' @rdname wkb_debug
#' @export
wkt_debug <- function(wkt) {
cpp_debug_wkt(wkt)
invisible(wkt)
}

#' @rdname wkb_debug
Expand Down
12 changes: 11 additions & 1 deletion R/problems.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@

#' Validate well-known binary
#' Validate well-known binary and well-known text
#'
#' @inheritParams wkb_translate_wkt
#'
#' @return A character vector of parsing errors. `NA` signifies
#' that there was no parsing error.
#' @export
#'
#' @examples
#' # well-known text
#' wkt_problems(c("POINT EMTPY", "POINT (20 30)"))
#'
#' # well-known binary
#' wkb <- wkt_translate_wkb("POINT (30 10)", endian = 1)[[1]]
#' wkb_bad <- wkb
#' wkb_bad[2] <- as.raw(255)
#' wkb_problems(list(wkb, wkb_bad))
#'
wkb_problems <- function(wkb) {
cpp_problems_wkb(wkb)
}
Expand Down
9 changes: 9 additions & 0 deletions R/translate.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
#' of raw vectors.
#' @export
#'
#' @examples
#' # translate between WKT and WKB
#' (wkb <- wkt_translate_wkb("POINT (30 10)"))
#' wkb_translate_wkt(wkb)
#'
#' # some basic creation options are also available
#' wkt_translate_wkt("POINT (30 10)", trim = FALSE)
#' wkb_translate_wkb(wkb, endian = 0)
#'
wkb_translate_wkt <- function(wkb, include_z = NA, include_m = NA, include_srid = NA,
precision = 16, trim = TRUE) {
cpp_translate_wkb_wkt(
Expand Down
13 changes: 13 additions & 0 deletions man/wkb_debug.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions man/wkb_problems.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions man/wkb_translate_wkt.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/testthat/test-debug.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ test_that("debugger works on wkb", {
expect_output(wkb_debug(list(point_bad_type)), "Unrecognized geometry type")
})

test_that("debugger works on wkt stream", {
expect_output(wkt_streamer_debug("LINESTRING (30 10, 0 0, 0 1)"), "LINESTRING")
expect_output(wkt_streamer_debug("POLYGON ((30 10, 0 0, 0 1, 30 10))"), "POLYGON")
expect_output(wkt_streamer_debug("MULTIPOINT (30 10, 0 0)"), "MULTIPOINT")
expect_output(wkt_streamer_debug("MULTIPOINT ((30 10), (0 0))"), "MULTIPOINT")
})

test_that("debugger works on wkt", {
expect_output(wkt_debug("LINESTRING (30 10, 0 0, 0 1)"), "LINESTRING")
expect_output(wkt_debug("POLYGON ((30 10, 0 0, 0 1, 30 10))"), "POLYGON")
Expand Down

0 comments on commit 55063e0

Please sign in to comment.