Kusto 查询语言 (KQL) 提供地理空间联接工具。
以下工具和功能非常有用:
将点(经度、纬度)转换为受支持的地理哈希 S2、 H3 或 Geohash 之一。 地理哈希可用作联接键。 附近的两个点将转换为相同的哈希值,或者它们也是邻居,也可以考虑这些点。 详细了解不同的 地理哈希算法。 请参阅以下示例。
每当匹配是邻近条件时,缓冲区功能 geo_point_buffer()、 geo_polygon_buffer()和 geo_line_buffer() 可以帮助地理空间条件联接。 请参阅以下示例。
Polygon\Line lookup plugin capabilities geo_polygon_lookup() 和 geo_line_lookup() 允许根据包含和\或邻近度将位置轻松分类到各自的多边形\行。
覆盖函数 的地理多边形到 s2cells() 和 地理线到 s2cells() 的形状是高级形状,涵盖可将形状转换为可持久保存并用于联接和索引的哈希集合的实用工具。
例子
以下示例演示如何使用 S2 在位置上联接。
let locations1 = datatable(name: string, longitude: real, latitude: real)
[
"a", -0.12433080766874127, 51.51115841361647,
"b", -0.12432651341458723, 51.511160848670585,
"c", -0.12432466939637266, 51.51115959669167,
"d", 1, 1,
];
let locations2 = datatable(id: string, longitude: real, latitude: real)
[
"1", -0.12432668105284961, 51.51115938802832
];
let s2_join_level = 22; // More about join levels: https://learn.microsoft.com/en-us/kusto/query/geo-point-to-s2cell-function?view=azure-data-explorer
locations1
| extend hash = geo_point_to_s2cell(longitude, latitude, s2_join_level)
| join kind = inner (locations2 | extend hash = geo_point_to_s2cell(longitude, latitude, s2_join_level)) on hash
| project name, id
输出
姓名 | id |
---|---|
一个 | 1 |
b | 1 |
c | 1 |
以下示例演示了使用 H3 的位置联接,同时考虑到两个附近位置可能是邻居的情况。
let locations1 = datatable(name: string, longitude: real, latitude: real)
[
"a", -0.12433080766874127, 51.51115841361647,
"b", -0.12432651341458723, 51.511160848670585,
"c", -0.12432466939637266, 51.51115959669167,
"d", 1, 1,
];
let locations2 = datatable(id: string, longitude: real, latitude: real)
[
"1", -0.12432668105284961, 51.51115938802832
];
let to_hash = (lng: real, lat: real)
{
let h3_hash_level = 14; // More about join levels: https://learn.microsoft.com/en-us/kusto/query/geo-point-to-h3cell-function?view=azure-data-explorer
let h3_hash = geo_point_to_h3cell(lng, lat, h3_hash_level);
array_concat(pack_array(h3_hash), geo_h3cell_neighbors(h3_hash))
};
locations1
| extend hash = to_hash(longitude, latitude)
| mv-expand hash to typeof(string)
| join kind = inner (
locations2
| extend hash = to_hash(longitude, latitude)
| mv-expand hash to typeof(string))
on hash
| distinct name, id, longitude, latitude
输出
姓名 | id | 经度 | 纬度 |
---|---|---|---|
一个 | 1 | -0.124330807668741 | 51.5111584136165 |
b | 1 | -0.124330807668741 | 51.5111584136165 |
c | 1 | -0.124324669396373 | 51.5111595966917 |
以下示例演示了 locations1 表中的位置与 locations2 表中的位置联接(如果位置 1 中的点位于 locations2 表的 300 米以内)。
let locations1 = datatable(name: string, longitude: real, latitude: real)
[
"O2 Entrance", 0.005889454501716321, 51.50238626916584,
"O2 Entrance", 0.0009625704125020596,51.50385432770013,
"Greenwich Park", 0.0009395106042404677, 51.47700456557013,
];
let locations2 = datatable(id: string, longitude: real, latitude: real)
[
"O2 Arena", 0.003159306017352037, 51.502929224128394
]
| extend buffer = geo_point_buffer(0.003159306017352037, 51.502929224128394, 300, 0.1); // Create a radius of 300 meters from O2 center location
locations1
| evaluate geo_polygon_lookup(locations2, buffer, longitude, latitude)
| project name, id, longitude, latitude
输出
姓名 | id | 经度 | 纬度 |
---|---|---|---|
O2 入口 | O2 Arena | 0.00096257041250206 | 51.5038543277001 |
O2 入口 | O2 Arena | 0.00588945450171632 | 51.5023862691658 |