教程:创建地理空间可视化效果

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

使用 Kusto 查询语言 (KQL) 创建地理空间可视化效果。 地理空间聚类分析按位置组织数据。 KQL 提供了多个地理空间聚类分析和地理空间可视化工具。

本教程中,您将学习如何:

先决条件

若要运行查询,需要有权访问示例数据的查询环境。 使用以下项之一:

  • Microsoft帐户或Microsoft Entra 用户标识登录到 帮助群集
  • Microsoft帐户或Microsoft Entra 用户标识登录到 帮助群集

使用 项目 选择经度列,然后选择纬度列。 使用 呈现 来在地图上显示点(已 kind 设置为 map的散点图)。

在地图上绘制点

使用 项目 选择经度列,然后选择纬度列。 使用 渲染 来在地图上显示点(散点图,其中 kind 设置为 map)。

StormEvents
| take 100
| project BeginLon, BeginLat
| render scatterchart with (kind = map)

地图上示例风暴事件的截图。

绘制多个点系列

若要可视化多个点系列,请使用 项目 选择定义序列的经度、纬度和第三列。

在以下查询中,系列为 EventType。 这些点使用不同颜色 EventType ,并在选中时显示 EventType 值。

StormEvents
| take 100
| project BeginLon, BeginLat, EventType
| render scatterchart with (kind = map)

地图上按类型显示的示例 storm 事件的屏幕截图。

当结果的列数超过经度、纬度和序列列时,还可以在render运算符中显式指定xcolumn(经度)、ycolumn(纬度)和series

StormEvents
| take 100
| render scatterchart with (kind = map, xcolumn = BeginLon, ycolumns = BeginLat, series = EventType)

使用 GeoJSON 值在地图上绘制点

动态 GeoJSON 值经常更新,并用于实时映射。 具有动态 GeoJSON 值的映射点为你提供了纯纬度和经度无法实现的灵活性和控制力。

以下查询使用 geo_point_to_s2cellgeo_s2cell_to_central_point 函数来映射散点图上的风暴事件。

StormEvents
| project BeginLon, BeginLat
| summarize by hash=geo_point_to_s2cell(BeginLon, BeginLat, 5)
| project point = geo_s2cell_to_central_point(hash)
| project lng = toreal(point.coordinates[0]), lat = toreal(point.coordinates[1])
| render scatterchart with (kind = map)

使用 GeoJSON 显示的示例风暴事件的屏幕截图。

用可变大小的气泡来表示数据点

通过聚合每个群集并绘制其中心点来可视化数据分布。

例如,以下查询会筛选出 EventType 为 Tornado 的风暴事件。 它将事件分组为经度和纬度群集,对每个群集中的事件进行计数,投影每个群集的中心点,并呈现地图。 具有最龙卷风的地区以其更大的气泡大小脱颖而出。

StormEvents
| where EventType == "Tornado"
| project BeginLon, BeginLat
| where isnotnull(BeginLat) and isnotnull(BeginLon)
| summarize count_summary=count() by hash = geo_point_to_s2cell(BeginLon, BeginLat, 4)
| project geo_s2cell_to_central_point(hash), count_summary
| extend Events = "count"
| render piechart with (kind = map)

Azure 数据资源管理器的屏幕截图,其中显示了龙卷风事件的地理空间地图。

显示特定区域中的点

使用多边形定义区域,并使用 geo_point_in_polygon 函数筛选该区域中发生的事件。

以下查询定义一个表示南加州区域的多边形,并筛选该区域中的风暴事件。 然后它将事件分组为聚类,统计每个聚类中的事件数,投影聚类的中心点,然后呈现地图以可视化聚类。

let southern_california = dynamic({
    "type": "Polygon",
    "coordinates": [[[-119.5, 34.5], [-115.5, 34.5], [-115.5, 32.5], [-119.5, 32.5], [-119.5, 34.5]]
    ]});
StormEvents
| where geo_point_in_polygon(BeginLon, BeginLat, southern_california)
| project BeginLon, BeginLat
| summarize count_summary = count() by hash = geo_point_to_s2cell(BeginLon, BeginLat, 8)
| project geo_s2cell_to_central_point(hash), count_summary
| extend Events = "count"
| render piechart with (kind = map)

Azure 数据资源管理器 Web UI 的屏幕截图,其中显示了南加州风暴的地理空间地图。

显示 LineString 上的附近点

以下查询查找沿指定的 LineString(表示已定义路径)发生的附近暴风雨事件。 在本例中,LineString 是通往 Key West 的道路。 geo_distance_point_to_line() 函数用于根据暴风雨事件与所定义 LineString 的邻近性来筛选这些事件。 如果事件位于 LineString 的 500 米范围内,则会在地图上呈现该事件。

let roadToKeyWest = dynamic({
"type":"linestring",
"coordinates":[
          [
            -81.79595947265625,
            24.56461038017685
          ],
          [
            -81.595458984375,
            24.627044746156027
          ],
          [
            -81.52130126953125,
            24.666986385216273
          ],
          [
            -81.35650634765625,
            24.66449040712424
          ],
          [
            -81.32354736328125,
            24.647017162630366
          ],
          [
            -80.8099365234375,
            24.821639356846607
          ],
          [
            -80.62042236328125,
            24.93127614538456
          ],
          [
            -80.37872314453125,
            25.175116531621764
          ],
          [
            -80.42266845703124,
            25.19251511519153
          ],
          [
            -80.4803466796875,
            25.46063471847754
          ]
        ]});
StormEvents
| where isnotempty(BeginLat) and isnotempty(BeginLon)
| project BeginLon, BeginLat, EventType
| where geo_distance_point_to_line(BeginLon, BeginLat, roadToKeyWest) < 500
| render scatterchart with (kind=map)

以上 KQL 查询结果的屏幕截图,用于计算 LineString 沿途的事件。

显示多边形内的附近点

以下查询查找指定多边形内发生的附近暴风雨事件。 在本例中,多边形是通往 Key West 的道路。 geo_distance_point_to_polygon() 函数用于根据暴风雨事件与所定义多边形的邻近性来筛选这些事件。 如果事件位于多边形的 500 米范围内,则会在地图上呈现该事件。

let roadToKeyWest = dynamic({
"type":"polygon",
"coordinates":[
          [
            [
              -80.08209228515625,
              25.39117928167583
            ],
            [
              -80.4913330078125,
              25.517657429994035
            ],
            [
              -80.57922363281249,
              25.477992320574817
            ],
            [
              -82.188720703125,
              24.632038149596895
            ],
            [
              -82.1942138671875,
              24.53712939907993
            ],
            [
              -82.13104248046875,
              24.412140070651528
            ],
            [
              -81.81243896484375,
              24.43714786161562
            ],
            [
              -80.58746337890625,
              24.794214972389486
            ],
            [
              -80.08209228515625,
              25.39117928167583
            ]
          ]
        ]});
StormEvents
| where isnotempty(BeginLat) and isnotempty(BeginLon)
| project BeginLon, BeginLat, EventType
| where geo_distance_point_to_polygon(BeginLon, BeginLat, roadToKeyWest) < 500
| render scatterchart with (kind=map)

以上 KQL 查询结果的屏幕截图,用于计算多边形沿途的事件。

根据地理空间数据查找异常

以下查询对特定状态下发生的暴风雨事件进行分析。 查询使用 S2 单元格和时间聚合来调查破坏模式。 结果是一个可视异常图表,描绘了一段时间内暴风雨引起的破坏的任何不规则性或偏差,提供了关于暴风雨在指定州边界内影响的详细视角。

let stateOfInterest = "Texas";
let statePolygon = materialize(
    US_States
    | extend name = tostring(features.properties.NAME)
    | where name == stateOfInterest
    | project geometry=features.geometry);
let stateCoveringS2cells = statePolygon
    | project s2Cells = geo_polygon_to_s2cells(geometry, 9);
StormEvents
| extend s2Cell = geo_point_to_s2cell(BeginLon, BeginLat, 9)
| where s2Cell in (stateCoveringS2cells)
| where geo_point_in_polygon(BeginLon, BeginLat, toscalar(statePolygon))
| make-series damage = avg(DamageProperty + DamageCrops) default = double(0.0) on StartTime step 7d
| extend anomalies=series_decompose_anomalies(damage)
| render anomalychart with (anomalycolumns=anomalies)

以上 KQL 查询呈现的异常图表的屏幕截图。