Back to Influxdb

geo.s2CellIDToken() function

content/flux/v0/stdlib/experimental/geo/s2cellidtoken.md

latest4.4 KB
Original Source
<!------------------------------------------------------------------------------ IMPORTANT: This page was generated from comments in the Flux source code. Any edits made directly to this page will be overwritten the next time the documentation is generated. To make updates to this documentation, update the function comments above the function definition in the Flux source code: https://github.com/influxdata/flux/blob/master/stdlib/experimental/geo/geo.flux#L477-L477 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md ------------------------------------------------------------------------------->

geo.s2CellIDToken() returns and S2 cell ID token for given cell or point at a specified S2 cell level.

Function type signature
js
(level: int, ?point: {lon: float, lat: float}, ?token: string) => string

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

Parameters

token

S2 cell ID token to update.

Useful for changing the S2 cell level of an existing S2 cell ID token.

point

Record with lat and lon properties that specify the latitude and longitude in decimal degrees (WGS 84) of a point.

level

({{< req >}}) S2 cell level to use when generating the S2 cell ID token.

Examples

Use latitude and longitude values to generate S2 cell ID tokens

js
import "experimental/geo"

data
    |> map(
        fn: (r) =>
            ({r with s2_cell_id: geo.s2CellIDToken(point: {lat: r.lat, lon: r.lon}, level: 10)}),
    )

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

Input data

_time*idlonlat
2021-01-01T00:00:00Za213b39.751514.01433
2021-01-02T01:00:00Za213b38.352713.9228
2021-01-03T02:00:00Za213b36.997815.08433
_time*idlonlat
2021-01-01T00:00:00Zb546c24.0069-14.5464
2021-01-02T01:00:00Zb546c25.1304-13.3338
2021-01-03T02:00:00Zb546c26.7899-12.0433

Output data

_time*idlatlons2_cell_id
2021-01-01T00:00:00Za213b14.0143339.7515166b59
2021-01-02T01:00:00Za213b13.922838.352716696d
2021-01-03T02:00:00Za213b15.0843336.9978166599
_time*idlatlons2_cell_id
2021-01-01T00:00:00Zb546c-14.546424.00691960d7
2021-01-02T01:00:00Zb546c-13.333825.13041965c7
2021-01-03T02:00:00Zb546c-12.043326.78991971dd

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

Update S2 cell ID token level

js
import "experimental/geo"

data
    |> map(fn: (r) => ({r with s2_cell_id: geo.s2CellIDToken(token: r.s2_cell_id, level: 5)}))

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

Input data

_time*ids2_cell_id
2021-01-01T00:00:00Za213b166b59
2021-01-02T01:00:00Za213b16696d
2021-01-03T02:00:00Za213b166599
_time*ids2_cell_id
2021-01-01T00:00:00Zb546c1960d7
2021-01-02T01:00:00Zb546c1965c7
2021-01-03T02:00:00Zb546c1971dd

Output data

_time*ids2_cell_id
2021-01-01T00:00:00Za213b166c
2021-01-02T01:00:00Za213b166c
2021-01-03T02:00:00Za213b1664
_time*ids2_cell_id
2021-01-01T00:00:00Zb546c1964
2021-01-02T01:00:00Zb546c1964
2021-01-03T02:00:00Zb546c1974

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