共用方式為


教學課程:建立地理空間視覺效果

本教學課程適用於想要使用 Kusto 查詢語言 (KQL) 進行地理空間視覺效果的人員。 地理空間叢集是一種根據地理位置來組織和分析數據的方式。 KQL 提供多個方法來執行 地理空間叢集 ,以及 地理空間視覺效果的工具。

在本教學課程中,您將了解如何:

在地圖上繪製點

若要在地圖上可視化點,請使用 專案 來選取包含經度的數據行,然後選取包含緯度的數據行。 然後,使用 轉譯 在散佈圖中查看結果,並將 kind 設定為 map

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

地圖上範例 Storm 事件的螢幕快照。

繪製多個數列的點

若要可視化多個點數列,請使用 專案 來選取經度和緯度,以及定義數列的第三個數據行。

在下列查詢中,數列為 EventType。 點會根據其 EventType以不同的方式著色,而且選取時會顯示數據行的內容 EventType

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

依類型在地圖上範例 Storm 事件的螢幕快照。

您也可以明確指定 xcolumn (經度) 、 ycolumn (緯度) ,以及 series 執行 render時。 當結果中有比經度、緯度和數列數據行更多的數據行時,需要此規格。

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 來對應散佈圖中的 storm 事件。

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 顯示之範例 Storm 事件的螢幕快照。

以可變大小的泡泡表示數據點

藉由在每個叢集中執行匯總,然後繪製叢集中央點,以可視化方式呈現數據點的分佈。

例如,下列查詢會篩選 「Tornado」 事件類型的所有 storm 事件。 然後,它會根據事件經度和緯度將事件分組成叢集、計算每個叢集中的事件數目,以及投影叢集的中心點,並轉譯地圖以可視化結果。 具有最多捲動的區域會根據其大型泡泡大小清楚偵測到。

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 Data Explorer Web UI 的螢幕快照,其中顯示雪風的地理空間地圖。

顯示特定區域內的點

使用多邊形來定義區域和 geo_point_in_polygon 函式,以篩選該區域內發生的事件。

下列查詢會定義多邊形,代表此區域內的南加州區域和 Storm 事件的篩選。 然後,它會將事件分組成叢集、計算每個叢集中的事件數目、投影叢集的中央點,以及呈現地圖以可視化叢集。

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 Data Explorer Web UI 的螢幕快照,其中顯示南加州雨的地理空間地圖。

在 LineString 上顯示附近的點

下列查詢會尋找沿著指定LineString發生的鄰近 Storm事件,代表定義的路徑。 在此情況下,LineString 是 Key West 的路。 geo_distance_point_to_line () 函式是用來根據其與已定義LineString的鄰近性來篩選 storm 事件。 如果事件位於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 計算事件。

在多邊形中顯示附近的點

下列查詢會尋找在指定多邊形內發生的鄰近 Storm 事件。 在此情況下,多邊形是 Key West 的路。 geo_distance_point_to_polygon () 函式是用來根據其與已定義多邊形的鄰近性來篩選 storm 事件。 如果事件在多邊形的 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 查詢結果的螢幕快照,以沿著多邊形計算事件。

根據地理空間數據尋找異常

下列查詢會執行特定狀態內發生的 Storm 事件分析。 此查詢會使用 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 查詢所呈現異常圖表的螢幕快照。