<?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 Clustering Feature  Reduction using UniqueValueRenderer based on value from another field in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clustering-feature-reduction-using/m-p/1541410#M85740</link>
    <description>&lt;P&gt;I am using Clustering Featured Reduction (ArcGIS Maps SDK 4.30) on a Feature Layer with UniqueValueRender for symbols for a category. By default, the API will symbolize the cluster based on the "predominant category". Where predominant seems to refer to the most frequent category in the cluster.&lt;/P&gt;&lt;P&gt;I want to use the symbol for the category with the highest value of a particular field in the cluster. As an example, my data contains a category called animals, and a particular cluster has 3 cats and a dog, the API assigns the cluster the symbol of a cat. In my data, I have an additional field, the price for each animal, and the dog has the highest cost of all animals, I would like to assign the cluster the symbol of a dog.&lt;/P&gt;&lt;P&gt;What I have tried:&lt;/P&gt;&lt;P&gt;Using UniqueValueRender value expression Arcade. From here I am able to access the cluster feature, summary stats (computed in the cluster configuration), but the attributes here do not contain the aggregated features. So I am not able to find out which of the cluster elements contain the highest value.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//Expects($Feature, '*')

{
  "attributes": {
    "aggregateId": "266.187",
    "cluster_count": 12,
    "max_price": 100.0001,
    "avg_price": 23.674746264166668,
    "count_animals": 12,
    "unique_id": "db4120ae-b6be-4cc2-b20e-0a10c388d829",
    "category": "Dog"
  },
  "geometry": {
    "x": 108,
    "y": 178
  },
  "centroid": {
    "x": 108,
    "y": 178
  }
}&lt;/LI-CODE&gt;&lt;P&gt;I have also tried creating a new category field from the aggregated features. The Arcade below will work fine to present this information in a pop up, so I would be able to find out the category with the highest value from $aggregatedFeatures&lt;/P&gt;&lt;LI-CODE lang="c"&gt; {
              label: 'Predominant category',
              type:'expression',
              expressionInfo: {
                expression: `
                      Expects($aggregatedFeatures, '*');

                    var statsFs = GroupBy($aggregatedFeatures,
                      [ 
                        { name: 'Type', expression: 'category'}
                      ],
                      [ 
                        { name: 'MaxPrice', expression: 'price', statistic: 'MAX' }
                      ]
                    );

                    var ordered = Top(OrderBy(statsFs, 'MaxPrice DESC'), 5);

                      // create an HTML ordered list as a string and return in a rich text element
                      var list = "&amp;lt;p&amp;gt;Top animals (Price)&amp;lt;/p&amp;gt;&amp;lt;ol&amp;gt;";
               
                      for (var cat in ordered){
                        list += \`&amp;lt;li&amp;gt;\${cat.Type} (\${Text(cat.MaxPrice)}) &amp;lt;/li&amp;gt;\`
                      }
                      list += "&amp;lt;/ol&amp;gt;";
               
                      return {
                        type: "text",
                        text: list
                      }

                `
              }
            }&lt;/LI-CODE&gt;&lt;P&gt;However trying the same approach in the fields definition does not work, as $aggregatedFeatures does not seem to exist.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;        {
          name: 'pred_cat',
          onStatisticExpression: {
            title: 'category',
            returnType: 'string',
            expression: `
                      //Works fine, but I have only access to a single feature not all cluster features
                      Expects($feature, '*')

                      //Error
                      Expects($aggregatedFeatures, '*')

                      return "Dog"

                `
          }
          ,statisticType: 'mode'
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I achieve this? Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 23 Sep 2024 14:53:35 GMT</pubDate>
    <dc:creator>LawrenceD</dc:creator>
    <dc:date>2024-09-23T14:53:35Z</dc:date>
    <item>
      <title>Clustering Feature  Reduction using UniqueValueRenderer based on value from another field</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clustering-feature-reduction-using/m-p/1541410#M85740</link>
      <description>&lt;P&gt;I am using Clustering Featured Reduction (ArcGIS Maps SDK 4.30) on a Feature Layer with UniqueValueRender for symbols for a category. By default, the API will symbolize the cluster based on the "predominant category". Where predominant seems to refer to the most frequent category in the cluster.&lt;/P&gt;&lt;P&gt;I want to use the symbol for the category with the highest value of a particular field in the cluster. As an example, my data contains a category called animals, and a particular cluster has 3 cats and a dog, the API assigns the cluster the symbol of a cat. In my data, I have an additional field, the price for each animal, and the dog has the highest cost of all animals, I would like to assign the cluster the symbol of a dog.&lt;/P&gt;&lt;P&gt;What I have tried:&lt;/P&gt;&lt;P&gt;Using UniqueValueRender value expression Arcade. From here I am able to access the cluster feature, summary stats (computed in the cluster configuration), but the attributes here do not contain the aggregated features. So I am not able to find out which of the cluster elements contain the highest value.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//Expects($Feature, '*')

{
  "attributes": {
    "aggregateId": "266.187",
    "cluster_count": 12,
    "max_price": 100.0001,
    "avg_price": 23.674746264166668,
    "count_animals": 12,
    "unique_id": "db4120ae-b6be-4cc2-b20e-0a10c388d829",
    "category": "Dog"
  },
  "geometry": {
    "x": 108,
    "y": 178
  },
  "centroid": {
    "x": 108,
    "y": 178
  }
}&lt;/LI-CODE&gt;&lt;P&gt;I have also tried creating a new category field from the aggregated features. The Arcade below will work fine to present this information in a pop up, so I would be able to find out the category with the highest value from $aggregatedFeatures&lt;/P&gt;&lt;LI-CODE lang="c"&gt; {
              label: 'Predominant category',
              type:'expression',
              expressionInfo: {
                expression: `
                      Expects($aggregatedFeatures, '*');

                    var statsFs = GroupBy($aggregatedFeatures,
                      [ 
                        { name: 'Type', expression: 'category'}
                      ],
                      [ 
                        { name: 'MaxPrice', expression: 'price', statistic: 'MAX' }
                      ]
                    );

                    var ordered = Top(OrderBy(statsFs, 'MaxPrice DESC'), 5);

                      // create an HTML ordered list as a string and return in a rich text element
                      var list = "&amp;lt;p&amp;gt;Top animals (Price)&amp;lt;/p&amp;gt;&amp;lt;ol&amp;gt;";
               
                      for (var cat in ordered){
                        list += \`&amp;lt;li&amp;gt;\${cat.Type} (\${Text(cat.MaxPrice)}) &amp;lt;/li&amp;gt;\`
                      }
                      list += "&amp;lt;/ol&amp;gt;";
               
                      return {
                        type: "text",
                        text: list
                      }

                `
              }
            }&lt;/LI-CODE&gt;&lt;P&gt;However trying the same approach in the fields definition does not work, as $aggregatedFeatures does not seem to exist.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;        {
          name: 'pred_cat',
          onStatisticExpression: {
            title: 'category',
            returnType: 'string',
            expression: `
                      //Works fine, but I have only access to a single feature not all cluster features
                      Expects($feature, '*')

                      //Error
                      Expects($aggregatedFeatures, '*')

                      return "Dog"

                `
          }
          ,statisticType: 'mode'
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I achieve this? Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2024 14:53:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clustering-feature-reduction-using/m-p/1541410#M85740</guid>
      <dc:creator>LawrenceD</dc:creator>
      <dc:date>2024-09-23T14:53:35Z</dc:date>
    </item>
  </channel>
</rss>

