The flexpolyline R package provides a binding to the C++ implementation of the flexible polyline encoding by HERE. The flexible polyline encoding is a lossy compressed representation of a list of coordinate pairs or coordinate triples. The encoding is achieved by:
(1) Reducing the decimal digits of each value;
(2) encoding only the offset from the previous point;
(3) using variable length for each coordinate delta; and
(4) using 64 URL-safe characters to display the result. The flexible polyline encoding is a variant of the Encoded Polyline Algorithm Format by Google.
Note:
sf objects, without reordering the columns.You can install the released version of flexpolyline from CRAN with:
install.packages("flexpolyline")
Install the development version from GitHub with:
remotes::install_github("munterfinger/flexpolyline")
Encoding and decoding in R is straight forward by using encode() and decode(). These functions are binding to the flexpolyline C++ implementation and reflect the arguments and return values of their counterparts (hf::encode_polyline and hf::decode_polyline):
A common way to deal with spatial data in R is the sf package, which is built on the concept of simple features. The functions encode_sf() and decode_sf() provide an interface that support the encoding of sf objects:
sfg <- sf::st_linestring(line, dim = "XYZ") encode_sf(sfg) decode_sf("BlBoz5xJ67i1BU1B7PUzIhaUxL7YU")