docs-v2/content/flux/v0.x/stdlib/experimental/polyline/rdp.md

8.3 KiB

title description menu weight flux/v0.x/tags
polyline.rdp() function `polyline.rdp()` applies the Ramer Douglas Peucker (RDP) algorithm to input data to downsample curves composed of line segments into visually indistinguishable curves with fewer points.
flux_0_x_ref
name parent identifier
polyline.rdp experimental/polyline experimental/polyline/rdp
201
transformations

polyline.rdp() applies the Ramer Douglas Peucker (RDP) algorithm to input data to downsample curves composed of line segments into visually indistinguishable curves with fewer points.

Function type signature
(
    <-tables: stream[A],
    ?epsilon: float,
    ?retention: float,
    ?timeColumn: string,
    ?valColumn: string,
) => stream[B] where A: Record, B: Record

{{% caption %}}For more information, see Function type signatures.{{% /caption %}}

Parameters

valColumn

Column with Y axis values of the given curve. Default is _value.

timeColumn

Column with X axis values of the given curve. Default is _time.

epsilon

Maximum tolerance value that determines the amount of compression.

Epsilon should be greater than 0.0.

retention

Percentage of points to retain after downsampling.

Retention rate should be between 0.0 and 100.0.

tables

Input data. Default is piped-forward data (<-).

Examples

Downsample data using the RDP algorithm

When using polyline.rdp(), leave both epsilon and retention unspecified to automatically calculate the maximum tolerance for producing a visually indistinguishable curve.

import "experimental/polyline"

data
    |> polyline.rdp()

{{< expand-wrapper >}} {{% expand "View example input and output data" %}}

Input data

_time _value
2022-10-17T17:09:00Z 10.56555566168836
2022-10-17T17:09:10Z -29.76098586714259
2022-10-17T17:09:20Z -67.50435038579738
2022-10-17T17:09:30Z -16.758669047964453
2022-10-17T17:09:40Z -47.25865245658065
2022-10-17T17:09:50Z 66.16082461651365
2022-10-17T17:10:00Z -0.9179216017921821
2022-10-17T17:10:10Z -56.89169240573004
2022-10-17T17:10:20Z 11.358605472976624
2022-10-17T17:10:30Z 28.71147881415803
2022-10-17T17:10:40Z -30.928830759588756
2022-10-17T17:10:50Z -22.411848631056067
2022-10-17T17:11:00Z 17.05503606764129
2022-10-17T17:11:10Z 9.834382683760559
2022-10-17T17:11:20Z -12.62058579127679
2022-10-17T17:11:30Z -44.44668391211515

Output data

_time _value
2022-10-17T17:09:00Z 10.56555566168836
2022-10-17T17:09:10Z -29.76098586714259
2022-10-17T17:09:20Z -67.50435038579738
2022-10-17T17:09:30Z -16.758669047964453
2022-10-17T17:09:40Z -47.25865245658065
2022-10-17T17:09:50Z 66.16082461651365
2022-10-17T17:10:00Z -0.9179216017921821
2022-10-17T17:10:10Z -56.89169240573004
2022-10-17T17:10:20Z 11.358605472976624
2022-10-17T17:10:30Z 28.71147881415803
2022-10-17T17:10:40Z -30.928830759588756
2022-10-17T17:10:50Z -22.411848631056067
2022-10-17T17:11:00Z 17.05503606764129
2022-10-17T17:11:10Z 9.834382683760559
2022-10-17T17:11:20Z -12.62058579127679
2022-10-17T17:11:30Z -44.44668391211515

{{% /expand %}} {{< /expand-wrapper >}}

Downsample data using the RDP algorithm with an epsilon of 1.5

import "experimental/polyline"

data
    |> polyline.rdp(epsilon: 1.5)

{{< expand-wrapper >}} {{% expand "View example input and output data" %}}

Input data

_time _value
2022-10-17T17:09:00Z 10.56555566168836
2022-10-17T17:09:10Z -29.76098586714259
2022-10-17T17:09:20Z -67.50435038579738
2022-10-17T17:09:30Z -16.758669047964453
2022-10-17T17:09:40Z -47.25865245658065
2022-10-17T17:09:50Z 66.16082461651365
2022-10-17T17:10:00Z -0.9179216017921821
2022-10-17T17:10:10Z -56.89169240573004
2022-10-17T17:10:20Z 11.358605472976624
2022-10-17T17:10:30Z 28.71147881415803
2022-10-17T17:10:40Z -30.928830759588756
2022-10-17T17:10:50Z -22.411848631056067
2022-10-17T17:11:00Z 17.05503606764129
2022-10-17T17:11:10Z 9.834382683760559
2022-10-17T17:11:20Z -12.62058579127679
2022-10-17T17:11:30Z -44.44668391211515

Output data

_time _value
2022-10-17T17:09:00Z 10.56555566168836
2022-10-17T17:09:20Z -67.50435038579738
2022-10-17T17:09:30Z -16.758669047964453
2022-10-17T17:09:40Z -47.25865245658065
2022-10-17T17:09:50Z 66.16082461651365
2022-10-17T17:10:00Z -0.9179216017921821
2022-10-17T17:10:10Z -56.89169240573004
2022-10-17T17:10:20Z 11.358605472976624
2022-10-17T17:10:30Z 28.71147881415803
2022-10-17T17:10:40Z -30.928830759588756
2022-10-17T17:10:50Z -22.411848631056067
2022-10-17T17:11:00Z 17.05503606764129
2022-10-17T17:11:10Z 9.834382683760559
2022-10-17T17:11:20Z -12.62058579127679
2022-10-17T17:11:30Z -44.44668391211515

{{% /expand %}} {{< /expand-wrapper >}}

Downsample data using the RDP algorithm with a retention rate of 90%

import "experimental/polyline"

data
    |> polyline.rdp(retention: 90.0)

{{< expand-wrapper >}} {{% expand "View example input and output data" %}}

Input data

_time _value
2022-10-17T17:09:00Z 10.56555566168836
2022-10-17T17:09:10Z -29.76098586714259
2022-10-17T17:09:20Z -67.50435038579738
2022-10-17T17:09:30Z -16.758669047964453
2022-10-17T17:09:40Z -47.25865245658065
2022-10-17T17:09:50Z 66.16082461651365
2022-10-17T17:10:00Z -0.9179216017921821
2022-10-17T17:10:10Z -56.89169240573004
2022-10-17T17:10:20Z 11.358605472976624
2022-10-17T17:10:30Z 28.71147881415803
2022-10-17T17:10:40Z -30.928830759588756
2022-10-17T17:10:50Z -22.411848631056067
2022-10-17T17:11:00Z 17.05503606764129
2022-10-17T17:11:10Z 9.834382683760559
2022-10-17T17:11:20Z -12.62058579127679
2022-10-17T17:11:30Z -44.44668391211515

Output data

_time _value
2022-10-17T17:09:00Z 10.56555566168836
2022-10-17T17:09:20Z -67.50435038579738
2022-10-17T17:09:30Z -16.758669047964453
2022-10-17T17:09:40Z -47.25865245658065
2022-10-17T17:09:50Z 66.16082461651365
2022-10-17T17:10:00Z -0.9179216017921821
2022-10-17T17:10:10Z -56.89169240573004
2022-10-17T17:10:20Z 11.358605472976624
2022-10-17T17:10:30Z 28.71147881415803
2022-10-17T17:10:40Z -30.928830759588756
2022-10-17T17:10:50Z -22.411848631056067
2022-10-17T17:11:00Z 17.05503606764129
2022-10-17T17:11:10Z 9.834382683760559
2022-10-17T17:11:30Z -44.44668391211515

{{% /expand %}} {{< /expand-wrapper >}}