Learn R Programming

duckspatial (version 0.9.0)

ddbs_as_hexwkb: Convert geometries to hexadecimal Well-Known Binary (HEXWKB) format

Description

Converts spatial geometries to their hexadecimal Well-Known Binary (HEXWKB) representation. This function wraps DuckDB's ST_AsHEXWKB spatial function.

Usage

ddbs_as_hexwkb(x, conn = NULL, quiet = FALSE)

Value

A character vector containing hexadecimal-encoded WKB representations of the geometries

Arguments

x

An sf spatial object. Alternatively, it can be a string with the name of a table with geometry column within the DuckDB database conn. Data is returned from this object.

conn

A connection object to a DuckDB database. If NULL, the function runs on a temporary DuckDB database.

quiet

A logical value. If TRUE, suppresses any informational messages. Defaults to FALSE.

Details

HEXWKB is a hexadecimal string representation of Well-Known Binary (WKB) format. This encoding is human-readable (unlike raw WKB) while maintaining the compact binary structure. HEXWKB is commonly used in databases and web services for transmitting spatial data as text strings.

Examples

Run this code
if (FALSE) {
## load packages
library(duckspatial)
library(sf)

# create a duckdb database in memory (with spatial extension)
conn <- ddbs_create_conn(dbdir = "memory")

## read data
argentina_sf <- st_read(system.file("spatial/argentina.geojson", package = "duckspatial"))

## store in duckdb
ddbs_write_vector(conn, argentina_sf, "argentina")

## convert geometries to HEXWKB
hexwkb_text <- ddbs_as_hexwkb(conn = conn, "argentina")

## convert without using a connection
hexwkb_text <- ddbs_as_hexwkb(argentina_sf)
}

Run the code above in your browser using DataLab