使用 Geo 包处理形状数据
此页面记录了早期版本的 InfluxDB OSS。InfluxDB OSS v2 是最新的稳定版本。请参阅等效的 InfluxDB v2 文档: 使用 Geo 包处理形状数据。
Geo 包中的函数需要以下数据 schema
- 一个 s2_cell_id 标签,包含 作为令牌 的 S2 Cell ID
- 一个
lat
字段 字段,包含 十进制度的纬度 (WGS 84) - 一个
lon
字段 字段,包含 十进制度的经度 (WGS 84)
塑造地理时序数据
如果您的数据已经包含纬度和经度字段,请使用 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()
- 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 令牌。
此页内容是否对您有帮助?
感谢您的反馈!
支持和反馈
感谢您成为我们社区的一份子!我们欢迎并鼓励您提供关于 InfluxDB 和本文档的反馈和错误报告。如需获得支持,请使用以下资源
拥有年度合同或支持合同的客户 可以联系 InfluxData 支持。