使用 Geo 软件包处理形状数据
此页面记录了早期版本的 InfluxDB OSS。InfluxDB OSS v2 是最新的稳定版本。请参阅等效的 InfluxDB v2 文档: 使用 Geo 软件包处理形状数据。
Geo 软件包中的函数需要以下数据模式
- 包含 S2 Cell ID 作为令牌的 s2_cell_id 标签
- 包含十进制度纬度 (WGS 84) 的
lat
field 字段 - 包含十进制度经度 (WGS 84) 的
lon
field 字段
塑造地理时序数据
如果您的数据已包含纬度和经度字段,请使用 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 令牌。
此页是否对您有帮助?
感谢您的反馈!