A wrapper function for encode that converts simple feature geometries of the sf package to flexible polyline encoded strings.

encode_sf(
  geom,
  precision = 5,
  third_dim = NULL,
  third_dim_precision = precision
)

Arguments

geom

simple feature, sf, sfc or sfg object with geometry type "POINT", "LINESTRING" or "POLYGON".

precision

integer, precision to use in encoding (between 0 and 15, default=5).

third_dim

integer, type of the third dimension (0: ABSENT, 1: LEVEL, 2: ALTITUDE, 3: ELEVATION, 4, 6: CUSTOM1, 7: CUSTOM2, default=NULL).

third_dim_precision

integer, precision to use in encoding for the third dimension (between 1 and 15, default=precision).

Value

The line as string in the flexible polyline encoding format.

Examples

# 3D point
point3d <- sf::st_point(
  matrix(c(8.69821, 50.10228, 10), ncol = 3, byrow = TRUE),
  dim = "XYZ"
)
encode_sf(point3d)
#> [1] "B1Voz5xJ67i1Bgkh9B"

# 2D linestring
line2d <- sf::st_linestring(
  matrix(c(
    8.69821, 50.10228,
    8.69567, 50.10201,
    8.68752, 50.09878
  ), ncol = 2, byrow = TRUE)
)
encode_sf(line2d)
#> [1] "BFoz5xJ67i1B1B7PlU9yB"

# 3D polygon
poly3d <- sf::st_polygon(list(
  matrix(c(
    8.69821, 50.10228, 10,
    8.69567, 50.10201, 20,
    8.69150, 50.10063, 30,
    8.69821, 50.10228, 10
  ), ncol = 3, byrow = TRUE)
), dim = "XYM")
encode_sf(poly3d)
#> [1] "BlXoz5xJ67i1Bgkh9B1B7Pgkh9BzIhagkh9BqK-pB_ni6D"