<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Return feature ID for query buffer with StatisticDefinition in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/return-feature-id-for-query-buffer-with/m-p/1012520#M71213</link>
    <description>&lt;P&gt;Edits to remove what I have found will not work and try to better explain what I am looking to do.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a feature polygon layer that is queried with a buffer. I use StatisticDefinition to sum one field shown in the code below. Using the 4.17 JS API&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-tasks-support-StatisticDefinition.html" target="_blank" rel="nofollow noopener noreferrer"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-tasks-support-StatisticDefinition.html&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I would like to return the polygon ID which is a string in this case I am using block groups. The problem is I cant use StatisticDefinition on a string field as it must be a sum, max, min or so on.&lt;/P&gt;&lt;P&gt;When I call console.log(&lt;SPAN&gt;result.features[&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;].attributes) I see one attribute from the query&amp;nbsp;hh_202006. So this is the summed value for hh_202006 inside the buffer. I would like to add the ID for all block groups.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;function queryStatistics() {&lt;BR /&gt;  const statDefinitions = [
        onStatisticField:
          "CASE WHEN 202006 &amp;gt; 0 THEN 202006 ELSE 0 END",
        outStatisticFieldName: "hh_202006",
        statisticType: "sum",
      }]

    const query = featureLayerView.layer.createQuery()
    query.geometry = sketchGeometry;
    query.distance = bufferSize;
    query.units = 'miles'
    query.outStatistics = statDefinitions; //Only seeing results for this

    return featureLayerView.queryFeatures(query).then(function (result) {
      console.log(result.features[0].attributes)&lt;BR /&gt;   }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Dec 2020 14:27:34 GMT</pubDate>
    <dc:creator>JeffKropelnicki</dc:creator>
    <dc:date>2020-12-29T14:27:34Z</dc:date>
    <item>
      <title>Return feature ID for query buffer with StatisticDefinition</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/return-feature-id-for-query-buffer-with/m-p/1012520#M71213</link>
      <description>&lt;P&gt;Edits to remove what I have found will not work and try to better explain what I am looking to do.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a feature polygon layer that is queried with a buffer. I use StatisticDefinition to sum one field shown in the code below. Using the 4.17 JS API&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-tasks-support-StatisticDefinition.html" target="_blank" rel="nofollow noopener noreferrer"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-tasks-support-StatisticDefinition.html&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I would like to return the polygon ID which is a string in this case I am using block groups. The problem is I cant use StatisticDefinition on a string field as it must be a sum, max, min or so on.&lt;/P&gt;&lt;P&gt;When I call console.log(&lt;SPAN&gt;result.features[&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;].attributes) I see one attribute from the query&amp;nbsp;hh_202006. So this is the summed value for hh_202006 inside the buffer. I would like to add the ID for all block groups.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;function queryStatistics() {&lt;BR /&gt;  const statDefinitions = [
        onStatisticField:
          "CASE WHEN 202006 &amp;gt; 0 THEN 202006 ELSE 0 END",
        outStatisticFieldName: "hh_202006",
        statisticType: "sum",
      }]

    const query = featureLayerView.layer.createQuery()
    query.geometry = sketchGeometry;
    query.distance = bufferSize;
    query.units = 'miles'
    query.outStatistics = statDefinitions; //Only seeing results for this

    return featureLayerView.queryFeatures(query).then(function (result) {
      console.log(result.features[0].attributes)&lt;BR /&gt;   }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Dec 2020 14:27:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/return-feature-id-for-query-buffer-with/m-p/1012520#M71213</guid>
      <dc:creator>JeffKropelnicki</dc:creator>
      <dc:date>2020-12-29T14:27:34Z</dc:date>
    </item>
    <item>
      <title>Re: Return feature Name/ID for query buffer with StatisticDefinition or outFields</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/return-feature-id-for-query-buffer-with/m-p/1012540#M71214</link>
      <description>&lt;P&gt;Reading the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-tasks-support-Query.html#outStatistics" target="_self"&gt;documentation&lt;/A&gt;, it says "If outStatistics is specified the only other query parameters that should be used are groupByFieldsForStatistics, orderByFields, text, and where." This indicates that the outFields parameter will be ignored. If you want to sum the length field and display the name of all the features used to calculate this sum, you'll need separate queries. Or just query all the features like normal and sum the length yourself (no extra outStatistics query needed).&lt;/P&gt;</description>
      <pubDate>Mon, 28 Dec 2020 20:37:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/return-feature-id-for-query-buffer-with/m-p/1012540#M71214</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2020-12-28T20:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: Return feature Name/ID for query buffer with StatisticDefinition or outFields</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/return-feature-id-for-query-buffer-with/m-p/1012547#M71215</link>
      <description>&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;That is what I thought about the outFields&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Can you tell me more about summing the length field to return a string?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;{&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;onStatisticField: ??&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;outStatisticFieldName:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"name"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;statisticType:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"sum"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;},&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 28 Dec 2020 20:56:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/return-feature-id-for-query-buffer-with/m-p/1012547#M71215</guid>
      <dc:creator>JeffKropelnicki</dc:creator>
      <dc:date>2020-12-28T20:56:07Z</dc:date>
    </item>
    <item>
      <title>Re: Return feature Name/ID for query buffer with StatisticDefinition or outFields</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/return-feature-id-for-query-buffer-with/m-p/1012553#M71216</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var lengthSum = 0;
layer.queryFeatures(query).then(function(featureSet) {
  featureSet.features.forEach(function(feature) {
    lengthSum += feature.attributes.lengthFieldName
  });
});
console.log(lengthSum);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Dec 2020 22:09:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/return-feature-id-for-query-buffer-with/m-p/1012553#M71216</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2020-12-28T22:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: Return feature Name/ID for query buffer with StatisticDefinition or outFields</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/return-feature-id-for-query-buffer-with/m-p/1012558#M71217</link>
      <description>&lt;P&gt;Thank you for the reply I have been looking for a work around on this for a long time. Is there are working example of this out there? this code does not work for me and I dont understand how I can get all the names of the polygons inside a buffer which are strings from summing the length column.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Dec 2020 21:35:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/return-feature-id-for-query-buffer-with/m-p/1012558#M71217</guid>
      <dc:creator>JeffKropelnicki</dc:creator>
      <dc:date>2020-12-28T21:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: Return feature Name/ID for query buffer with StatisticDefinition or outFields</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/return-feature-id-for-query-buffer-with/m-p/1012565#M71218</link>
      <description>&lt;P&gt;You may need to clarify what you're trying to do with an example of what you want the output to look like. You have access to all output fields in the featureSet features so you can get the length (to sum) and the name values all in the same spot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var lengthSum = 0;
var names = [];
layer.queryFeatures(query).then(function(featureSet) {
  featureSet.features.forEach(function(feature) {
    lengthSum += feature.attributes.lengthFieldName;
    names.push(feature.attributes.nameFieldName);
  });
});

console.log(`Total length of queried features is ${lengthSum}`);
console.log(`Names of queried features ${names}`);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT:&lt;/P&gt;&lt;P&gt;Just realized I made a slight error on how to construct the forEach loop. I updated the code to be&amp;nbsp;&lt;FONT face="courier new,courier"&gt;featureSet.features.forEach&lt;/FONT&gt; and&amp;nbsp;&lt;FONT face="courier new,courier"&gt;feature.attributes&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Dec 2020 22:09:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/return-feature-id-for-query-buffer-with/m-p/1012565#M71218</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2020-12-28T22:09:29Z</dc:date>
    </item>
  </channel>
</rss>

