地理空间联接

适用于:✅Azure 数据资源管理器Azure MonitorMicrosoft Sentinel

Kusto 查询语言 (KQL) 提供地理空间联接工具。

以下工具和功能非常有用:

小窍门

  • 如果附近位置太多,请使用受支持的地理哈希 S2H3Geohash 之一按位置聚合。

  • 详细了解 join 运算符 及其风格。

例子

以下示例演示如何使用 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