MyNixOS website logo
Description

Lightweight Well-Known Geometry Parsing.

Provides a minimal R and C++ API for parsing well-known binary and well-known text representation of geometries to and from R-native formats. Well-known binary is compact and fast to parse; well-known text is human-readable and is useful for writing tests. These formats are useful in R only if the information they contain can be accessed in R, for which high-performance functions are provided here.

wk

R buildstatus Codecov testcoverage

The goal of wk is to provide lightweight R, C, and C++ infrastructure for a distributed ecosystem of packages that operate on collections of coordinates. First, wk provides vector classes for points, circles, rectangles, well-known text (WKT), and well-known binary (WKB). Second, wk provides a C API and set of S3 generics for event-based iteration over vectors of geometries.

Installation

You can install the released version of wk from CRAN with:

install.packages("wk")

You can install the development version from GitHub with:

# install.packages("remotes")
remotes::install_github("paleolimbot/wk")

If you can load the package, you’re good to go!

library(wk)

Vector classes

Use wkt() to mark a character vector as containing well-known text, or wkb() to mark a vector as well-known binary. Use xy(), xyz(), xym(), and xyzm() to create vectors of points, and rct() to create vectors of rectangles. These classes have full vctrs support and plot()/format() methods to make them as frictionless as possible working in R and RStudio.

wkt("POINT (30 10)")
#> <wk_wkt[1]>
#> [1] POINT (30 10)
as_wkb(wkt("POINT (30 10)"))
#> <wk_wkb[1]>
#> [1] <POINT (30 10)>
xy(1, 2)
#> <wk_xy[1]>
#> [1] (1 2)
rct(1, 2, 3, 4)
#> <wk_rct[1]>
#> [1] [1 2 3 4]
crc(0, 0, 1)
#> <wk_crc[1]>
#> [1] [0 0, r = 1]

Generics

The wk package is made up of readers, handlers, and filters. Readers parse the various formats supported by the wk package, handlers calculate values based on information from the readers (e.g., translating a vector of geometries into another format), and filters transform information from the readers (e.g., transforming coordinates) on the fly. The wk_handle() and wk_translate() generics power operations for many geometry vector formats without having to explicitly support each one.

C API

The distributed nature of the wk framework is powered by a ~100-line header describing the types of information that parsers typically encounter when reading geometries and the order in which that information is typically organized. Detailed information is available in the C and C++ API article.

wk_debug(
  as_wkt("LINESTRING (1 1, 2 2, 3 3)"),
  wkt_format_handler(max_coords = 2)
)
#> initialize (dirty = 0  -> 1)
#> vector_start: <Unknown type / 0>[1] <0x16d75aac0> => WK_CONTINUE
#>   feature_start (1): <0x16d75aac0>  => WK_CONTINUE
#>     geometry_start (<none>): LINESTRING[UNKNOWN] <0x16d75a950> => WK_CONTINUE
#>       coord (1): <0x16d75a950> (1.000000 1.000000)  => WK_CONTINUE
#>       coord (2): <0x16d75a950> (2.000000 2.000000)  => WK_ABORT_FEATURE
#> vector_end: <0x16d75aac0>
#> deinitialize
#> [1] "LINESTRING (1 1, 2 2..."

sf support

The wk package implements a reader and writer for sfc objects so you can use them wherever you’d use an xy(), rct(), crc(), wkb(), or wkt():

wk_debug(
  sf::st_sfc(sf::st_linestring(rbind(c(1, 1), c(2, 2), c(3, 3)))),
  wkt_format_handler(max_coords = 2)
)
#> initialize (dirty = 0  -> 1)
#> vector_start: LINESTRING B[1] <0x16d75dac8> => WK_CONTINUE
#>   feature_start (1): <0x16d75dac8>  => WK_CONTINUE
#>     geometry_start (<none>): LINESTRING[3] <0x16d75da10> => WK_CONTINUE
#>       coord (1): <0x16d75da10> (1.000000 1.000000)  => WK_CONTINUE
#>       coord (2): <0x16d75da10> (2.000000 2.000000)  => WK_ABORT_FEATURE
#> vector_end: <0x16d75dac8>
#> deinitialize
#> [1] "LINESTRING (1 1, 2 2..."

Lightweight

The wk package has zero dependencies and compiles in ~10 seconds.

Metadata

Version

0.9.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD 13
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd13
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd13
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows