Translate between WKB and WKT

wkb_translate_wkt(
  wkb,
  include_z = NA,
  include_m = NA,
  include_srid = NA,
  precision = 16,
  trim = TRUE
)

wkb_translate_wkb(
  wkb,
  include_z = NA,
  include_m = NA,
  include_srid = NA,
  endian = wk_platform_endian(),
  buffer_size = 2048
)

wkb_translate_wksxp(wkb, include_z = NA, include_m = NA, include_srid = NA)

wkt_translate_wkt(
  wkt,
  include_z = NA,
  include_m = NA,
  include_srid = NA,
  precision = 16,
  trim = TRUE
)

wkt_translate_wkb(
  wkt,
  include_z = NA,
  include_m = NA,
  include_srid = NA,
  endian = wk_platform_endian(),
  buffer_size = 2048
)

wkt_translate_wksxp(wkt, include_z = NA, include_m = NA, include_srid = NA)

wksxp_translate_wkt(
  wksxp,
  include_z = NA,
  include_m = NA,
  include_srid = NA,
  precision = 16,
  trim = TRUE
)

wksxp_translate_wkb(
  wksxp,
  include_z = NA,
  include_m = NA,
  include_srid = NA,
  endian = wk_platform_endian(),
  buffer_size = 2048
)

wksxp_translate_wksxp(wksxp, include_z = NA, include_m = NA, include_srid = NA)

wk_platform_endian()

Arguments

wkb

A list() of raw() vectors, such as that returned by sf::st_as_binary().

include_z, include_m, include_srid

Include the values of the Z and M coordinates and/or SRID in the output? Use FALSE to omit, TRUE to include, or NA to include only if present. Note that using TRUE may result in an error if there is no value present in the original.

precision

The rounding precision to use when writing (number of decimal places).

trim

Trim unnecessary zeroes in the output?

endian

For WKB writing, 0 for big endian, 1 for little endian. Defaults to wk_platform_endian() (slightly faster).

buffer_size

For WKB writing, the initial buffer size to use for each feature, in bytes. This will be extended when needed, but if you are calling this repeatedly with huge geometries, setting this value to a larger number may result in less copying.

wkt

A character vector containing well-known text.

wksxp

A list() of classed objects

Value

*_translate_wkt() returns a character vector of well-known text; *_translate_wkb() returns a list of raw vectors, and *_translate_wksxp() returns an unclassed list of wksxp() geometries. Unlike as_wkb(), as_wkt(), and as_wksxp(), these functions do not attach a class to the output.

Examples

# translate between WKT and WKB (wkb <- wkt_translate_wkb("POINT (30 10)"))
#> [[1]] #> [1] 01 01 00 00 00 00 00 00 00 00 00 3e 40 00 00 00 00 00 00 24 40 #>
#> [1] "POINT (30 10)"
# some basic creation options are also available wkt_translate_wkt("POINT (30 10)", trim = FALSE)
#> [1] "POINT (30.0000000000000000 10.0000000000000000)"
wkb_translate_wkb(wkb, endian = 0)
#> [[1]] #> [1] 00 00 00 00 01 40 3e 00 00 00 00 00 00 40 24 00 00 00 00 00 00 #>