Skip to content

Commit

Permalink
Merge pull request #115 from paleolimbot/wkt-reader
Browse files Browse the repository at this point in the history
Refactor WKT Reader
  • Loading branch information
paleolimbot authored Dec 16, 2021
2 parents f5bc5a6 + 32e0c92 commit 21fbc04
Show file tree
Hide file tree
Showing 13 changed files with 3,618 additions and 475 deletions.
1 change: 1 addition & 0 deletions .covrignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
inst/include/wk
src/cpp11.cpp
src/fast_float/fast_float.h
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
be interpolated along a spherical/ellipsoidal trajectory (#112).
* Added `sf::st_geometry()` and `sf::st_sfc()` methods for wk geometry
vectors for better integration with sf (#113, #114).
* Refactored well-known text parser to be more reusable and faster
(#115, #104).

# wk 0.5.0

Expand Down
4 changes: 0 additions & 4 deletions R/cpp11.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Generated by cpp11: do not edit by hand

wk_cpp_handle_wkt <- function(wkt, xptr, reveal_size) {
.Call(`_wk_wk_cpp_handle_wkt`, wkt, xptr, reveal_size)
}

wk_cpp_wkt_writer <- function(precision, trim) {
.Call(`_wk_wk_cpp_wkt_writer`, precision, trim)
}
Expand Down
24 changes: 21 additions & 3 deletions R/handle-wkt.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,36 @@
#' @export
wk_handle.wk_wkt <- function(handleable, handler, ...) {
handler <- as_wk_handler(handler)
wk_cpp_handle_wkt(handleable, handler, reveal_size = TRUE)
.Call(
wk_c_read_wkt,
list(
handleable,
4096L,
TRUE
),
handler
)
}

#' Test handlers for handling of unknown size vectors
#'
#' @inheritParams wk_handle
#' @param wkt_parser_buffer_size Buffer size to use for the parser. Useful
#' for testing the parser.
#' @export
#'
#' @examples
#' handle_wkt_without_vector_size(wkt(), wk_vector_meta_handler())
#'
handle_wkt_without_vector_size <- function(handleable, handler) {
handle_wkt_without_vector_size <- function(handleable, handler, wkt_parser_buffer_size = 4096) {
handler <- as_wk_handler(handler)
wk_cpp_handle_wkt(handleable, handler, reveal_size = FALSE)
.Call(
wk_c_read_wkt,
list(
handleable,
as.integer(wkt_parser_buffer_size)[1],
FALSE
),
handler
)
}
13 changes: 13 additions & 0 deletions data-raw/update-fastfloat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

curl::curl_download(
"/~https://github.com/fastfloat/fast_float/archive/refs/tags/v3.4.0.zip",
"data-raw/fastfloat.zip"
)

unzip("data-raw/fastfloat.zip", exdir = "data-raw")
header_text <- withr::with_dir(
"data-raw/fast_float-3.4.0",
system("python3 script/amalgamate.py", intern = TRUE)
)

readr::write_lines(header_text, "src/fast_float.h")
9 changes: 8 additions & 1 deletion man/handle_wkt_without_vector_size.Rd

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

Loading

0 comments on commit 21fbc04

Please sign in to comment.