You need to enable JavaScript to run this app. ArcGIS托管要素图层outStatistics参数查询失败问题咨询
优惠活动
大模型
产品
解决方案
定价
更多

ArcGIS托管要素图层outStatistics参数查询失败问题咨询

问题原因

该问题属于编码错误,和身份认证无关,你空间查询可正常返回说明服务访问权限无异常,报错核心原因是outStatistics参数的写法不符合ArcGIS REST API规范:
onStatisticField参数仅接收字段名或合法的标量SQL表达式,你直接将等值判断条件填入该字段,同时搭配count统计类型的写法是错误的:

  • 首先多数ArcGIS Server实例不支持直接将布尔表达式作为统计输入字段,会直接触发查询报错
  • 其次count统计逻辑是计数所有onStatisticField返回非空值的记录,就算表达式能执行,返回的也不是满足条件的记录数,而是所有有WellStatus值的记录数,和你预期的分类计数逻辑不符。

解决方法

有两种常见的实现方案可选:

方案1:条件求和实现分类计数

将分类统计项的统计类型改为sum,onStatisticField改为CASE WHEN条件表达式,示例修改如下:

// 按状态分类统计定义
const countActive = {
  onStatisticField: "CASE WHEN WellStatus = 'Active' THEN 1 ELSE 0 END", 
  outStatisticFieldName: "active",
  statisticType: "sum"
};

const countNew = {
  onStatisticField: "CASE WHEN WellStatus = 'New' THEN 1 ELSE 0 END",
  outStatisticFieldName: "new",
  statisticType: "sum"
};

const countPlugged = {
  onStatisticField: "CASE WHEN WellStatus = 'Plugged' THEN 1 ELSE 0 END",
  outStatisticFieldName: "plugged",
  statisticType: "sum"
};

const countIdle = {
  onStatisticField: "CASE WHEN WellStatus = 'Idle' THEN 1 ELSE 0 END",
  outStatisticFieldName: "idle",
  statisticType: "sum"
};

const countAll = {
  onStatisticField: "WellStatus",
  outStatisticFieldName: "all",
  statisticType: "count"
};

let statsQuery = oilWellsLayer.createQuery();
statsQuery.outStatistics = [countIdle, countPlugged, countAll, countActive, countNew];
// 统计查询无需返回几何,显式设置提升查询效率
statsQuery.returnGeometry = false;

oilWellsLayer.queryFeatures(statsQuery).then(response=>{
  console.log(response)
}).catch(e=>{
  console.log(e);
})

方案2:分组统计(更高效)

如果不需要一次性返回所有分类为独立字段,用分组统计的方式性能更高,也无需编写多个统计定义:

let statsQuery = oilWellsLayer.createQuery();
statsQuery.outStatistics = [{
  onStatisticField: "WellStatus",
  outStatisticFieldName: "status_count",
  statisticType: "count"
}];
// 按WellStatus字段分组统计
statsQuery.groupByFieldsForStatistics = ["WellStatus"];
statsQuery.returnGeometry = false;

查询返回的结果中每个条目对应一个WellStatus值的计数,你可以自行映射为需要的字段格式。

内容的提问来源于stack exchange,提问作者drm1217

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.08 18:15:02