polyline v1.2.0 Polyline

Encode and decode Polylines to and from List of {lon, lat} tuples.

The encode functions accept a precision parameter that defines the number of significant digits to retain when encoding. The same precision must be supplied to the decode or the resulting linestring will be incorrect. The default is 5, which correlates to approximately 1 meter of precision.

Examples

iex> Polyline.encode([{-120.2, 38.5}, {-120.95, 40.7}, {-126.453, 43.252}])
"_p~iF~ps|U_ulLnnqC_mqNvxq`@"

iex> Polyline.decode("_p~iF~ps|U_ulLnnqC_mqNvxq`@")
[{-120.2, 38.5}, {-120.95, 40.7}, {-126.453, 43.252}]

Link to this section Summary

Functions

Decode a polyline String into a List of {lon, lat} tuples

Encode a List of coordinate tuples into a Polyline String. Also works with Geo.LineString structs (see https://hex.pm/packages/geo)

Link to this section Functions

Link to this function decode(str, precision \\ 5)

Decode a polyline String into a List of {lon, lat} tuples.

Examples

iex> Polyline.decode("_p~iF~ps|U_ulLnnqC_mqNvxq`@")
[{-120.2, 38.5}, {-120.95, 40.7}, {-126.453, 43.252}]

iex> Polyline.decode("_izlhA~rlgdF_{geC~ywl@_kwzCn`{nI", 6)
[{-120.2, 38.5}, {-120.95, 40.7}, {-126.453, 43.252}]
Link to this function encode(coordinates, precision \\ 5)

Encode a List of coordinate tuples into a Polyline String. Also works with Geo.LineString structs (see https://hex.pm/packages/geo).

Examples

iex> Polyline.encode([{-120.2, 38.5}, {-120.95, 40.7}, {-126.453, 43.252}])
"_p~iF~ps|U_ulLnnqC_mqNvxq`@"

iex> Polyline.encode([{-120.2, 38.5}, {-120.95, 40.7}, {-126.453, 43.252}], 6)
"_izlhA~rlgdF_{geC~ywl@_kwzCn`{nI"

iex> "LINESTRING(-120.2 38.5, -120.95 40.7, -126.453 43.252)"
...> |> Geo.WKT.decode!
...> |> Map.get(:coordinates)
...> |> Polyline.encode
"_p~iF~ps|U_ulLnnqC_mqNvxq`@"