knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
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 felxible polyline encoding is a variant of the Encoded Polyline Algorithm Format by Google.
sfobjects, without reordering the columns.
You can install the released version of flexpolyline from CRAN with:
Install the development version from GitHub with:
Encoding and decoding in R is straight forward by using
These functions are binding to the flexpolyline C++ implementation and have similar arguments
and return values as their counterparts (
library(flexpolyline) (line <- 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 )) (encoded <- encode(line)) (decoded <- decode(encoded))
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
decode_sf() provide an interface that support the encoding of sf objects:
(sfg <- sf::st_linestring(line, dim = "XYZ")) (encoded <- encode_sf(sfg)) (decoded <- decode_sf(encoded))
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.