0

问题

尝试使用该outStatistics参数查询托管要素图层时,我收到失败的响应,而同一要素图层上的空间查询会返回要素。

该应用程序正在尝试使用来自加利福尼亚的井数据查询要素图层。在 CodePen 中,当搜索地址或使用 Slider 小部件修改缓冲区半径时会进行两个查询:

  1. 首先是需要多个字段进行查询的 outStatistics 查询
  2. 基于缓冲区几何的空间查询。

应用程序的 CodePen:
https ://codepen.io/dmarkbreiter/pen/abWXRZx

故障排除

我的第一个猜测是我没有正确地形成我的统计定义。但是,它们看起来格式正确。下面是统计查询及其相关统计定义对象的代码:

      // Define Statistic Definitions 

      const countActive = {
        onStatisticField: "WellStatus = 'Active'", 
        outStatisticFieldName: "active",
        statisticType: "count"
      };

      const countNew = {
        onStatisticField: "WellStatus = 'New'",
        outStatisticFieldName: "new",
        statisticType: "count"
      };

      const countPlugged = {
        onStatisticField: "WellStatus = 'Plugged'",
        outStatisticFieldName: "plugged",
        statisticType: "count"
      };

      const countIdle = {
        onStatisticField: "WellStatus = 'Idle'",
        outStatisticFieldName: "idle",
        statisticType: "count"
      };

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

      
      // Create query object and define outStatistics
      let statsQuery = oilWellsLayer.createQuery();
      statsQuery.outStatistics = [countIdle,
                                 countPlugged,
                                 countAll,
                                 countActive,
                                 countNew];

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

如您所见,除了对象之外,这些统计定义在属性countAll中使用 SQL 语句。outStatisticField它们似乎都是有效的 SQL 语句。

我的下一个想法是,可能由我不属于的机构拥有的要素图层不允许查询统计数据。但是,要素服务似乎已Supports Statistics设置为true。也许我误解了这意味着什么,但我想这将允许 outStatistics。

问题

为什么我可以在这个要素图层上成功执行空间查询,但不能返回 outStatistics?
这是编码问题还是身份验证问题?

4

1 回答 1

0

我无法访问该服务,但我认为您想念如何进行查询。它实际上要简单得多。

据我了解,您希望按 分组WellStatus,然后计算某些类型和所有记录。在那种情况下,我会像这样使用你的所有条件,

let statsQuery = oilWellsLayer.createQuery();
statsQuery.groupByFieldsForStatistics = ["WellStatus"];
statsQuery.outStatistics = [{
    onStatisticField: "WellStatus",
    outStatisticFieldName: "well_status",
    statisticType: "count"
}];

结果将是所有状态及其计数,因此要获得总和,您需要对所有状态求和。

你总是可以使用 where 参数来过滤状态,像这样,

statsQuery.where = "WellStatus IN ('Active','New','Plugged','Iddle')";

但在这种情况下,您将需要另一个查询总记录数。

于 2021-08-15T11:02:50.780 回答