indexing - 为使用 Qgis 中的聚合函数连接的每个值创建索引
问题描述
这是我在堆栈溢出中的第一篇文章。如果您能帮助我解决以下问题,我将非常高兴:
我正在使用 qgis 计算器,特别是聚合函数,来获取穿过我的管道层的电缆的名称(id),因为有时有不止一根电缆穿过管道。代码如下:
aggregate(
layer:='cables',
aggregate:='concatenate',
expression:= to_string(name),
concatenator:=',',
filter:=within(geometry(@parent),buffer($geometry,0.2))
)
这段代码在我的管道层中填充了一个名为“电缆”的字段,如下所示:
CLS00083,CLS00084,CLS000309
我现在想索引每个已填充的值,使其如下所示:
1:CBL00083,2:CBL00084,3:CBL000309,4:CBL000310 etc.
有没有办法使用聚合函数来实现这一点?
非常感谢你的帮助
解决方案
Use this expression:
array_to_string (
with_variable (
'array',
aggregate(
layer:='cables',
aggregate:='array_agg',
expression:= to_string(name),
concatenator:=','
),
array_foreach (
@array,
(to_int (array_find (@array, @element))+1) || ': ' || @element
)))
I suppose cables and ducts are on different layers. If not, you could use the easier array_agg
function instead of aggregate
, something like:
array_to_string(
with_variable (
'array',
array_agg(to_string(name)),
array_foreach (
@array,
(to_int (array_find (@array, @element))+1) || ': ' || @element
)))
By the way: for GIS-related questions, better use GIS SE.
推荐阅读
- php - 如何在一个 JSON 中获取两个查询以显示在 Chart.js 折线图上?
- python - Deap 运行时间给出了关键错误的错误
- c++ - 使用新运算符 c ++ 的静态绑定
- html - 如何在css中获取元素
- c - 实时嵌入式c代码中3个变量之间的依赖关系
- php - 使用 php-ews 获取 ms 交换服务器版本
- r - 如何在 r 中按月创建具有聚合值的新数据集?
- r - 根据最后一个已知值扩展数据框
- c# - Azure ServiceBusConnectionStringBuilder 中的“实体路径”是什么?
- javascript - Google Cloud Functions:尝试使用 ES6 时部署失败