Title: | Flexible Polyline Encoding |
---|---|
Description: | Binding to the C++ implementation of the flexible polyline encoding by HERE <https://github.com/heremaps/flexible-polyline>. 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. |
Authors: | Merlin Unterfinger [aut, cre] , HERE Europe B.V. [aut, cph] (Flexible polyline encoding C++ implementation) |
Maintainer: | Merlin Unterfinger <[email protected]> |
License: | GPL-3 |
Version: | 1.0.0 |
Built: | 2024-11-09 05:09:11 UTC |
Source: | https://github.com/munterfi/flexpolyline |
This function calls hf::polyline_decode
and
hf::get_third_dimension
of the C++ implementation of the flexible
polyline encoding by HERE. Depending on the dimensions of the encoded line,
a two or three-dimensional line is decoded.
decode(encoded)
decode(encoded)
encoded |
character, encoded flexible polyline string. |
A matrix containing the coordinates of the decoded line.
# 2d line decode("BFoz5xJ67i1B1B7PzIhaxL7Y") # 3d line decode("BlBoz5xJ67i1BU1B7PUzIhaUxL7YU")
# 2d line decode("BFoz5xJ67i1B1B7PzIhaxL7Y") # 3d line decode("BlBoz5xJ67i1BU1B7PUzIhaUxL7YU")
A wrapper function for decode
that converts the input polylines,
encoded in the flexible polyline enoding, to simple feature geometries of the sf package.
decode_sf(encoded, crs = sf::NA_crs_)
decode_sf(encoded, crs = sf::NA_crs_)
encoded |
character, encoded flexible polyline string. |
crs |
integer or character, coordinate reference system to assign to the sf object ( |
An sf
object, containing the geometries of the decoded lines (Geometry type: "LINESTRING"
).
The function returns an sf object, therefore the input set of encoded polylines
must be of consistent dimension (e.g "XY"
, "XYM"
or "XYZ"
)
to meet the requirements of the constructor of sf objects. For mixed dimensions
use the decode
function directly.
decode_sf("B1Voz5xJ67i1Bgkh9B") decode_sf("BFoz5xJ67i1B1B7PlU9yB") decode_sf("BlXoz5xJ67i1Bgkh9B1B7Pgkh9BzIhagkh9BqK-pB_ni6D")
decode_sf("B1Voz5xJ67i1Bgkh9B") decode_sf("BFoz5xJ67i1B1B7PlU9yB") decode_sf("BlXoz5xJ67i1Bgkh9B1B7Pgkh9BzIhagkh9BqK-pB_ni6D")
This function calls hf::polyline_encode
of the C++ implementation of
the flexible polyline encoding by HERE. Depending on the dimensions of the
input coordinates, a two or three-dimensional line is encoded.
encode(line, precision = 5L, third_dim = 3L, third_dim_precision = 5L)
encode(line, precision = 5L, third_dim = 3L, third_dim_precision = 5L)
line |
matrix, coordinates of the line in 2d or 3d (column order: LNG, LAT, DIM3). |
precision |
integer, precision to use in encoding (between 0 and 15,
|
third_dim |
integer, type of the third dimension (0: ABSENT, 1: LEVEL,
2: ALTITUDE, 3: ELEVATION, 4, 6: CUSTOM1, 7: CUSTOM2, |
third_dim_precision |
integer, precision to use in encoding for the
third dimension (between 1 and 15, |
The line as string in the flexible polyline encoding format.
# 2D line2d <- matrix( c(8.69821, 50.10228, 8.69567, 50.10201, 8.69150, 50.10063, 8.68752, 50.09878), ncol = 2, byrow = TRUE ) encode(line2d) # 3D line3d <- matrix( c(8.69821, 50.10228, 10, 8.69567, 50.10201, 20, 8.69150, 50.10063, 30, 8.68752, 50.09878, 40), ncol = 3, byrow = TRUE ) encode(line3d)
# 2D line2d <- matrix( c(8.69821, 50.10228, 8.69567, 50.10201, 8.69150, 50.10063, 8.68752, 50.09878), ncol = 2, byrow = TRUE ) encode(line2d) # 3D line3d <- matrix( c(8.69821, 50.10228, 10, 8.69567, 50.10201, 20, 8.69150, 50.10063, 30, 8.68752, 50.09878, 40), ncol = 3, byrow = TRUE ) encode(line3d)
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 )
encode_sf( geom, precision = 5, third_dim = NULL, third_dim_precision = precision )
geom |
simple feature, |
precision |
integer, precision to use in encoding (between 0 and 15, |
third_dim |
integer, type of the third dimension (0: ABSENT, 1: LEVEL, 2: ALTITUDE, 3: ELEVATION, 4, 6: CUSTOM1, 7: CUSTOM2, |
third_dim_precision |
integer, precision to use in encoding for the third dimension (between 1 and 15, |
The line as string in the flexible polyline encoding format.
# 3D point point3d <- sf::st_point( matrix(c(8.69821, 50.10228, 10), ncol = 3, byrow = TRUE), dim = "XYZ" ) encode_sf(point3d) # 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) # 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)
# 3D point point3d <- sf::st_point( matrix(c(8.69821, 50.10228, 10), ncol = 3, byrow = TRUE), dim = "XYZ" ) encode_sf(point3d) # 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) # 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)
This function calls hf::get_third_dimension
of the C++ implementation
of the flexible polyline encoding by HERE and return the type of the third
dimension.
get_third_dimension(encoded)
get_third_dimension(encoded)
encoded |
character, encoded flexible polyline string. |
A string describing the third dimension.
# 2d line get_third_dimension("BFoz5xJ67i1B1B7PzIhaxL7Y") # 3d line get_third_dimension("BlBoz5xJ67i1BU1B7PUzIhaUxL7YU")
# 2d line get_third_dimension("BFoz5xJ67i1B1B7PzIhaxL7Y") # 3d line get_third_dimension("BlBoz5xJ67i1BU1B7PUzIhaUxL7YU")