塑造数据以使用 Geo 包
Geo 包中的函数需要以下数据模式
- 包含 S2 Cell ID 作为令牌 的 s2_cell_id 标签
- 包含十进制度纬度 (WGS 84) 的
lat
字段字段 - 包含十进制度经度 (WGS 84) 的
lon
字段字段
塑造地理时序数据
如果您的数据已经包含经度和纬度字段,请使用 geo.shapeData()
函数 重命名字段以匹配 Geo 包的要求,将数据透视为行式集合,并为每个点生成 S2 Cell ID 令牌。
import "experimental/geo"
from(bucket: "example-bucket")
|> range(start: -1h)
|> filter(fn: (r) => r._measurement == "example-measurement")
|> geo.shapeData(latField: "latitude", lonField: "longitude", level: 10)
生成 S2 Cell ID 令牌
Geo 包使用 S2 Geometry Library 表示三维球体上的地理坐标。球体被划分为 单元格,每个单元格都有一个唯一的 64 位标识符(S2 Cell ID)。网格和 S2 Cell ID 的精度由 级别 定义。
要更快地进行过滤,请使用更高的 S2 Cell ID 级别,但要知道更高的级别会增加 序列基数。
Geo 包需要 S2 Cell ID 作为令牌。要生成 S2 Cell ID 令牌并将其添加到您的数据中,请使用以下选项之一
使用 Telegraf 生成 S2 Cell ID 令牌
启用 Telegraf S2 Geo (s2geo
) 处理器,以使用 lat
和 lon
字段值在指定的 cell_level
生成 S2 Cell ID 令牌。
将 processors.s2geo
配置添加到您的 Telegraf 配置文件 (telegraf.conf
)
[[processors.s2geo]]
## The name of the lat and lon fields containing WGS-84 latitude and
## longitude in decimal degrees.
lat_field = "lat"
lon_field = "lon"
## New tag to create
tag_key = "s2_cell_id"
## Cell level (see https://s2geometry.io/resources/s2cell_statistics.html)
cell_level = 9
Telegraf 将 S2 Cell ID 令牌存储在 s2_cell_id
标签中。
使用特定语言的库生成 S2 Cell ID 令牌
许多编程语言都提供了 S2 库,其中包含生成 S2 Cell ID 令牌的方法。将纬度和经度与 S2 Geometry Library 的 s2.CellID.ToToken
端点一起使用,以生成 s2_cell_id
标签。例如
- Go: s2.CellID.ToToken()
- Python: s2sphere.CellId.to_token()
- Crystal: cell.to_token(level)
- JavaScript: s2.cellid.toToken()
使用 Flux 生成 S2 Cell ID 令牌
将 geo.s2CellIDToken()
函数 与现有的经度 (lon
) 和纬度 (lat
) 字段值一起使用,以生成并添加 S2 Cell ID 令牌。首先,使用 geo.toRows()
函数 将 lat 和 lon 字段透视为行式集合
import "experimental/geo"
from(bucket: "example-bucket")
|> range(start: -1h)
|> filter(fn: (r) => r._measurement == "example-measurement")
|> geo.toRows()
|> map(
fn: (r) => ({
r with
s2_cell_id: geo.s2CellIDToken(point: {lon: r.lon, lat: r.lat}, level: 10)
})
)
geo.shapeData()
函数 也生成 S2 Cell ID 令牌。
此页面是否对您有帮助?
感谢您的反馈!