<?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 Arcade expression to perform a union, intersect, and push in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-expression-to-perform-a-union-intersect-and/m-p/1269694#M7502</link>
    <description>&lt;P&gt;Any help is MUCH appreciated.&amp;nbsp; I'm trying to get a widget to perform a Union on two layers, then run an Intersection on another, then report back attribute from both layers.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="EddyClark_0-1679353093095.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/65762i41A4685AE299E230/image-size/medium?v=v2&amp;amp;px=400" role="button" title="EddyClark_0-1679353093095.png" alt="EddyClark_0-1679353093095.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The screenshot above shows the three layers, all polygons.&amp;nbsp; Union is to be performed on the polygons labeled 2, 3, 5 (poly_fs, poly_fs3).&amp;nbsp; (I think) I need to union because I need to report back the square footage.&amp;nbsp; The Permanent | Actual yellow polygon intersects the 2, 5, and 3 in two places.&lt;/P&gt;&lt;P&gt;Intersection to be performed on the Temporary/Permanent | Actual/Estimated polygon layer (poly_fs2).&amp;nbsp; Actually, this layer needs to do a union on itself.&amp;nbsp; We don't want to double count the area.&lt;/P&gt;&lt;P&gt;I've successfully executed the Intersection part, but I cannot get either the Union(s), nor the Attributes, to come back.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the foundation which I started. &lt;A href="https://github.com/Esri/arcade-expressions/blob/master/dashboard_data/SpatialAggregation.md" target="_self"&gt;Aggregate by Spatial Relationship&lt;/A&gt;&lt;/P&gt;&lt;P&gt;And here is what is working for me right now.&amp;nbsp;&amp;nbsp;&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;// Write an expression that returns a FeatureSet.
// Documentation: https://arcg.is/3c419TD
// Samples: https://arcg.is/38SEWWz
// Portal
var portal = Portal('https://www.arcgis.com/');

// Create FeatureSet for polygons
var poly_fs = FeatureSetByPortalItem(
    portal,
    '535e3b40ca954053b1348a11f7ebfb59',
    15,
    [
        '*'
    ],
    true
);

// Create Featureset for points
var poly_fs2 = FeatureSetByPortalItem(
    portal,
    '535e3b40ca954053b1348a11f7ebfb59',
    20,
    [
        '*'
    ],
    true
);

var poly_fs3 = FeatureSetByPortalItem(
    portal,
    '535e3b40ca954053b1348a11f7ebfb59',
    5,
    [
        '*'
    ],
    true
);



// Create empty feature array and feat object for output
var features = [];
var feat;

var geom1 = poly_fs;
var geom2 = poly_fs3;
//If I uncomment this, I get an error
//var union = Union([poly_fs,geom2]);

// Iterate over time zones
for (var poly in poly_fs) {
    
    // Filter points by polygon
    var pts = Intersects(poly, poly_fs2);
    var cnt = Count(pts);
    var intersectsArea = 0;
    if(cnt&amp;gt;0) {
      for (var pt in pts) {
        intersectsArea += AreaGeodetic(Intersection(poly, pt),'square-feet');
        

      }
    }
    // Create feature with aggregated values
    feat = { 
        'attributes': { 
            'Multiplier': poly['multiplier'], 
            'M Code': poly['OBJECTID'], 
            'AreaSqFt': Round(intersectsArea,2)
        }
    };
    
    // Push feature into array
    Push(features, feat);
};

// Create dict for output FeatureSet
var out_dict = { 
    'fields': [
        {'name': 'Multiplier', 'type': 'esriFieldTypeInteger'},
        {'name': 'AreaSqFt', 'type': 'esriFieldTypeDouble'},
        {'name': 'M_Code', 'type': 'esriFieldTypeInteger'}
    ],
  'geometryType': '', 
  'features': features 
}; 

// Convert dictionary to feature set. 
return FeatureSet(Text(out_dict)); &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 20 Mar 2023 23:14:11 GMT</pubDate>
    <dc:creator>EddyClark</dc:creator>
    <dc:date>2023-03-20T23:14:11Z</dc:date>
    <item>
      <title>Arcade expression to perform a union, intersect, and push</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-expression-to-perform-a-union-intersect-and/m-p/1269694#M7502</link>
      <description>&lt;P&gt;Any help is MUCH appreciated.&amp;nbsp; I'm trying to get a widget to perform a Union on two layers, then run an Intersection on another, then report back attribute from both layers.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="EddyClark_0-1679353093095.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/65762i41A4685AE299E230/image-size/medium?v=v2&amp;amp;px=400" role="button" title="EddyClark_0-1679353093095.png" alt="EddyClark_0-1679353093095.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The screenshot above shows the three layers, all polygons.&amp;nbsp; Union is to be performed on the polygons labeled 2, 3, 5 (poly_fs, poly_fs3).&amp;nbsp; (I think) I need to union because I need to report back the square footage.&amp;nbsp; The Permanent | Actual yellow polygon intersects the 2, 5, and 3 in two places.&lt;/P&gt;&lt;P&gt;Intersection to be performed on the Temporary/Permanent | Actual/Estimated polygon layer (poly_fs2).&amp;nbsp; Actually, this layer needs to do a union on itself.&amp;nbsp; We don't want to double count the area.&lt;/P&gt;&lt;P&gt;I've successfully executed the Intersection part, but I cannot get either the Union(s), nor the Attributes, to come back.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the foundation which I started. &lt;A href="https://github.com/Esri/arcade-expressions/blob/master/dashboard_data/SpatialAggregation.md" target="_self"&gt;Aggregate by Spatial Relationship&lt;/A&gt;&lt;/P&gt;&lt;P&gt;And here is what is working for me right now.&amp;nbsp;&amp;nbsp;&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;// Write an expression that returns a FeatureSet.
// Documentation: https://arcg.is/3c419TD
// Samples: https://arcg.is/38SEWWz
// Portal
var portal = Portal('https://www.arcgis.com/');

// Create FeatureSet for polygons
var poly_fs = FeatureSetByPortalItem(
    portal,
    '535e3b40ca954053b1348a11f7ebfb59',
    15,
    [
        '*'
    ],
    true
);

// Create Featureset for points
var poly_fs2 = FeatureSetByPortalItem(
    portal,
    '535e3b40ca954053b1348a11f7ebfb59',
    20,
    [
        '*'
    ],
    true
);

var poly_fs3 = FeatureSetByPortalItem(
    portal,
    '535e3b40ca954053b1348a11f7ebfb59',
    5,
    [
        '*'
    ],
    true
);



// Create empty feature array and feat object for output
var features = [];
var feat;

var geom1 = poly_fs;
var geom2 = poly_fs3;
//If I uncomment this, I get an error
//var union = Union([poly_fs,geom2]);

// Iterate over time zones
for (var poly in poly_fs) {
    
    // Filter points by polygon
    var pts = Intersects(poly, poly_fs2);
    var cnt = Count(pts);
    var intersectsArea = 0;
    if(cnt&amp;gt;0) {
      for (var pt in pts) {
        intersectsArea += AreaGeodetic(Intersection(poly, pt),'square-feet');
        

      }
    }
    // Create feature with aggregated values
    feat = { 
        'attributes': { 
            'Multiplier': poly['multiplier'], 
            'M Code': poly['OBJECTID'], 
            'AreaSqFt': Round(intersectsArea,2)
        }
    };
    
    // Push feature into array
    Push(features, feat);
};

// Create dict for output FeatureSet
var out_dict = { 
    'fields': [
        {'name': 'Multiplier', 'type': 'esriFieldTypeInteger'},
        {'name': 'AreaSqFt', 'type': 'esriFieldTypeDouble'},
        {'name': 'M_Code', 'type': 'esriFieldTypeInteger'}
    ],
  'geometryType': '', 
  'features': features 
}; 

// Convert dictionary to feature set. 
return FeatureSet(Text(out_dict)); &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2023 23:14:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-expression-to-perform-a-union-intersect-and/m-p/1269694#M7502</guid>
      <dc:creator>EddyClark</dc:creator>
      <dc:date>2023-03-20T23:14:11Z</dc:date>
    </item>
  </channel>
</rss>

