<?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 Popup calculations with Arcade in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/popup-calculations-with-arcade/m-p/1031224#M38699</link>
    <description>&lt;P&gt;I am trying to add calculations for areas that intersect a project boundary, but have run into an issue with single part polygons returning an area for each intersecting polygon.&amp;nbsp; I ran a test with a new layer with the polygons dissolved to multi part polygons and I get the results I want, but I need to be able to group the data from single part polygons as its not possible to edit some of the layers I need to run this on.&amp;nbsp; I've included the Arcade code below that I've used, along with screen captures of the results on the single and multi part polygons.&lt;/P&gt;&lt;P&gt;I did some searching and found the GroupBy function, but cant figure out how to set that up it will even do what I want.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var MA_intersect = Intersects(FeatureSetByName($map,"ManagementAreas"), $feature);
var cnt = Count(MA_intersect);

if (cnt &amp;gt; 0) {
    var MAs = "";
    for (var MA in MA_intersect) {
        var intersectArea = 0
        intersectArea += Round(AreaGeodetic(Intersection($feature, MA), "acres"), 1);
        MAs += TextFormatting.NewLine + MA.NAME + ": " + Text(intersectArea, '#,###.#') + " Acres" + TextFormatting.NewLine;
    }
    //result += TextFormatting.NewLine + MAs;
    return MAs;
} else {
    return "No Overlaping Management Areas"
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Results with multi part polygons:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DavidHood2_0-1614383176494.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/7125i520D4A4ABF670B3C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DavidHood2_0-1614383176494.png" alt="DavidHood2_0-1614383176494.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Results with single part polygons (I want this to look like the popup above):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DavidHood2_1-1614383256606.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/7126iCDFE5A2EA5157DF7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DavidHood2_1-1614383256606.png" alt="DavidHood2_1-1614383256606.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 27 Feb 2021 00:08:11 GMT</pubDate>
    <dc:creator>DavidHood_USFS</dc:creator>
    <dc:date>2021-02-27T00:08:11Z</dc:date>
    <item>
      <title>Popup calculations with Arcade</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/popup-calculations-with-arcade/m-p/1031224#M38699</link>
      <description>&lt;P&gt;I am trying to add calculations for areas that intersect a project boundary, but have run into an issue with single part polygons returning an area for each intersecting polygon.&amp;nbsp; I ran a test with a new layer with the polygons dissolved to multi part polygons and I get the results I want, but I need to be able to group the data from single part polygons as its not possible to edit some of the layers I need to run this on.&amp;nbsp; I've included the Arcade code below that I've used, along with screen captures of the results on the single and multi part polygons.&lt;/P&gt;&lt;P&gt;I did some searching and found the GroupBy function, but cant figure out how to set that up it will even do what I want.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var MA_intersect = Intersects(FeatureSetByName($map,"ManagementAreas"), $feature);
var cnt = Count(MA_intersect);

if (cnt &amp;gt; 0) {
    var MAs = "";
    for (var MA in MA_intersect) {
        var intersectArea = 0
        intersectArea += Round(AreaGeodetic(Intersection($feature, MA), "acres"), 1);
        MAs += TextFormatting.NewLine + MA.NAME + ": " + Text(intersectArea, '#,###.#') + " Acres" + TextFormatting.NewLine;
    }
    //result += TextFormatting.NewLine + MAs;
    return MAs;
} else {
    return "No Overlaping Management Areas"
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Results with multi part polygons:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DavidHood2_0-1614383176494.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/7125i520D4A4ABF670B3C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DavidHood2_0-1614383176494.png" alt="DavidHood2_0-1614383176494.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Results with single part polygons (I want this to look like the popup above):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DavidHood2_1-1614383256606.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/7126iCDFE5A2EA5157DF7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DavidHood2_1-1614383256606.png" alt="DavidHood2_1-1614383256606.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Feb 2021 00:08:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/popup-calculations-with-arcade/m-p/1031224#M38699</guid>
      <dc:creator>DavidHood_USFS</dc:creator>
      <dc:date>2021-02-27T00:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: Popup calculations with Arcade</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/popup-calculations-with-arcade/m-p/1031250#M38700</link>
      <description>&lt;P&gt;Once you have your FeatureSet, &lt;STRONG&gt;GroupBy&lt;/STRONG&gt; is definitely what you want. It can get more complicated for returning multiple fields and statistics, but you essentially just want a &lt;EM&gt;sum&lt;/EM&gt; of the acreage by the type of management area, so it's more straightforward.&lt;/P&gt;&lt;P&gt;Here's part of an example using my county's landuse and parcel layers. For a given parcel of land, there are a number of different landuse types present.&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;var lu = FeatureSetByName($map,"Assessor Landuse", ['landuse', 'SHAPE__Area'])

var int_lu = Intersects($feature, lu)

var grp_dict = {
    name: 'total_area',
    expression: 'round(SHAPE__Area / 43560, 2)',
    statistic: 'SUM'
}

GroupBy(int_lu, 'landuse', grp_dict)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;This will return a FeatureSet, which by itself, is not useful for the popup text.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1614396399069.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/7135iDBC97C30A5FAAD76/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1614396399069.png" alt="jcarlson_0-1614396399069.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;You already have the next part, though! Simply take the output FeatureSet from &lt;STRONG&gt;GroupBy&lt;/STRONG&gt; and feed that into the for loop that constructs the output string.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Feb 2021 03:28:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/popup-calculations-with-arcade/m-p/1031250#M38700</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-02-27T03:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: Popup calculations with Arcade</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/popup-calculations-with-arcade/m-p/1032706#M38770</link>
      <description>&lt;P&gt;Thanks Josh,&lt;/P&gt;&lt;P&gt;I've been trying to get the GroupBy to work and I think I'm close but there is still an issue with the calculated area.&amp;nbsp; With the code below I'm getting for the popup.&amp;nbsp; But the acres calculation is not accurate as its not adding up to the total acres in the project area.&amp;nbsp; I pulled up the Shape_Area field and did an Arcade AreaGeodetic calculation on the project boundary to confirm, but can't figure out what the issue is.&amp;nbsp; Our data is in a UTM projection which does explain the Shape_Area to Acres seen below, but if I use the square meters to acres conversion of 4,046.856 the calculation is still off.&amp;nbsp; PVT should be about 30.7 acres&lt;/P&gt;&lt;P&gt;Shape_Area / 43560 =&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DavidHood2_0-1614815331408.png" style="width: 368px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/7456i175EC400D9390256/image-dimensions/368x216?v=v2" width="368" height="216" role="button" title="DavidHood2_0-1614815331408.png" alt="DavidHood2_0-1614815331408.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Shape_Area / 4046.856 =&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DavidHood2_1-1614816099828.png" style="width: 364px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/7459i92C575C2D02C53B9/image-dimensions/364x209?v=v2" width="364" height="209" role="button" title="DavidHood2_1-1614816099828.png" alt="DavidHood2_1-1614816099828.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var MA_intersect = Intersects(FeatureSetByName($map,"ManagmentAreas"), $feature);

var grp = {
    name: 'total_area',
    expression: 'round(Shape__Area / 43560, 1)',
    statistic: 'SUM'
}

var group = GroupBy (MA_intersect, ['NAME'], grp)
var cnt = Count(group);
if (cnt &amp;gt; 0) {
    var MAs = "";
    for (var MA in group) {
        MAs += MA.NAME + ": " + Text(MA.total_area, '#,###.#') + " Acres" + TextFormatting.NewLine;
    }
    return MAs;
} else {
    return "No Overlaping Management Areas"
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 00:09:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/popup-calculations-with-arcade/m-p/1032706#M38770</guid>
      <dc:creator>DavidHood_USFS</dc:creator>
      <dc:date>2021-03-04T00:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: Popup calculations with Arcade</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/popup-calculations-with-arcade/m-p/1032841#M38781</link>
      <description>&lt;P&gt;Ah, that's right. &lt;STRONG&gt;Intersection&lt;/STRONG&gt; will give the total area of the full shape of each intersected feature, not just the intersection area. I've no doubt those values are calculating accurately, but they're just more than you want.&lt;/P&gt;&lt;P&gt;To constrain the area calculation to just the overlapping area, we have to take another approach. We'll actually abandon the grouping, as this does not return geometry we can work with. Further complicating matters is the fact that the FeatureSet, being derived from a feature class, is &lt;EM&gt;immutable&lt;/EM&gt;, otherwise we could just use &lt;STRONG&gt;SetGeometry&lt;/STRONG&gt; on it.&lt;/P&gt;&lt;P&gt;Instead, we will iterate over our intersected features, calculate the area for the &lt;STRONG&gt;Intersection&lt;/STRONG&gt;, then push those values to a separate &lt;EM&gt;dictionary&lt;/EM&gt;. We can use&amp;nbsp;&lt;STRONG&gt;HasKey&lt;/STRONG&gt; to determine whether the calculated area is a new entry or simply added to an existing value. We'll then use that dictionary to cobble together the output string.&lt;/P&gt;&lt;P&gt;Be sure to use &lt;STRONG&gt;AreaGeodetic&lt;/STRONG&gt; instead of just &lt;STRONG&gt;Area&lt;/STRONG&gt;! And yes, this calculation will depend on the view scale rather than the internal area attribute, which is regrettable. But as we're rounding off to a single decimal place, that's probably okay. One benefit of this approach is that the units are specified in the calculation, so there's no conversion to manage.&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;var lu = FeatureSetByName($map,"Assessor Landuse", ['landuse', 'SHAPE__Area'])

var int_lu = Intersects($feature, lu)

var int_dict = {}

for(var i in int_lu){
    var xs = AreaGeodetic(Intersection($feature, i), 'acres')
    if(HasKey(int_dict, i)){
        int_dict[i.landuse] += xs
    } else {
        int_dict[i.landuse] = xs
    }
}

var out_str = 'Acreage by Landuse:'

for(var d in int_dict){
    out_str += '\n' + d + '\t|\t' + Text(int_dict[d], '#,###.#')
}

return out_str&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1614866871894.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/7484i943F2F8F9D57E3BB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1614866871894.png" alt="jcarlson_0-1614866871894.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;There are probably other ways to get that to format a bit more nicely in the output, but this &lt;EM&gt;should&lt;/EM&gt; get you values that make a bit more sense.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 14:10:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/popup-calculations-with-arcade/m-p/1032841#M38781</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-03-04T14:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: Popup calculations with Arcade</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/popup-calculations-with-arcade/m-p/1033003#M38793</link>
      <description>&lt;P&gt;Thanks Josh, that got me to what I needed, with just 1 change. I needed i.NAME in the HasKey part not just i.&amp;nbsp; Without the i.NAME only seemed to work were I didn't have multiple polygons with the same management area within the project. My final code is below incase it helps anyone else.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var managementareas = FeatureSetByName($map,"ManagmentAreas");

var int_ma = Intersects($feature, managementareas)

var int_dict = {}

var xs = 0

for (var i in int_ma){
    var xs = AreaGeodetic(Intersection($feature, i), 'acres')
    if(HasKey(int_dict,i.Name)){
        int_dict[i.NAME] += xs
    } else {
        int_dict[i.NAME] = xs
    }

var out_str = 'Management Area Acreage: ';

for (var d in int_dict){
    out_str += '\n' + d + '\t|\t' + Text(int_dict[d], '#,###.#')
}}

return out_str&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 18:57:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/popup-calculations-with-arcade/m-p/1033003#M38793</guid>
      <dc:creator>DavidHood_USFS</dc:creator>
      <dc:date>2021-03-04T18:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: Popup calculations with Arcade</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/popup-calculations-with-arcade/m-p/1033007#M38794</link>
      <description>&lt;P&gt;Glad to hear it! Good catch on that typo, too! That was quite a process getting to the solution!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 19:01:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/popup-calculations-with-arcade/m-p/1033007#M38794</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-03-04T19:01:19Z</dc:date>
    </item>
  </channel>
</rss>

