如何通过Kusto查询导入CSV数据以实现地理地图可视化
Kusto导入CSV数据并实现地理地图可视化
一、CSV数据导入Kusto的核心命令
Kusto主要通过.ingest命令导入CSV,根据数据源位置分两种常用场景:
1. 本地CSV文件导入(仅适用于Kusto Explorer/桌面客户端)
如果CSV在本地机器上,用以下命令导入,支持自动创建表并跳过表头:
.ingest into table MyGeoData (@"C:\local\path\geo_data.csv") with ( format = "csv", ignoreFirstRecord = true, // 若CSV首行是表头则开启 createifnotexists = true // 表不存在时自动创建 )
2. 云存储CSV导入(Azure Blob示例)
如果CSV存储在Azure Blob等云存储,通过SAS授权链接导入:
.ingest into table MyGeoData ( h@"https://your-storage.blob.core.windows.net/container/geo_data.csv?your_sas_token" ) with ( format = "csv", ignoreFirstRecord = true, createifnotexists = true )
二、为地理可视化准备数据
地理地图可视化需要Kusto识别的地理类型字段,常见处理方式如下:
1. 从经纬度列生成地理点
如果CSV里是分开的经度(Longitude)、纬度(Latitude)列,先添加并生成geo_point类型列:
// 新增地理点列 .alter-merge table MyGeoData add column GeoPoint geo_point // 将经纬度转为地理点 .update table MyGeoData set GeoPoint = geo_make_point(Longitude, Latitude)
注意:如果经纬度导入后是字符串类型,先转成数值:.update table MyGeoData set Longitude = todouble(Longitude), Latitude = todouble(Latitude)
2. 解析GeoJSON格式字段
如果CSV里有GeoJSON格式的字符串列(比如GeoJson),直接解析为地理类型:
.update table MyGeoData set GeoShape = geo_parse_geojson(GeoJson)
三、地理地图可视化查询
在Kusto Web UI或Explorer中执行以下查询,然后切换到地图可视化模式,配置GeoPoint为地理字段、MetricValue为数值字段即可:
MyGeoData | project GeoPoint, LocationName, MetricValue // 选择需要展示的字段 | where isnotempty(GeoPoint) // 过滤无效地理数据
内容的提问来源于stack exchange,提问作者Manoranjini M
相关产品推荐
相关产品推荐

