Select to view content in your preferred language

Arcade expression to perform a union, intersect, and push

358
0
03-20-2023 04:14 PM
EddyClark
Occasional Contributor

Any help is MUCH appreciated.  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.  

EddyClark_0-1679353093095.png

The screenshot above shows the three layers, all polygons.  Union is to be performed on the polygons labeled 2, 3, 5 (poly_fs, poly_fs3).  (I think) I need to union because I need to report back the square footage.  The Permanent | Actual yellow polygon intersects the 2, 5, and 3 in two places.

Intersection to be performed on the Temporary/Permanent | Actual/Estimated polygon layer (poly_fs2).  Actually, this layer needs to do a union on itself.  We don't want to double count the area.

I've successfully executed the Intersection part, but I cannot get either the Union(s), nor the Attributes, to come back.  

This is the foundation which I started. Aggregate by Spatial Relationship

And here is what is working for me right now.  

 

 

// 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>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)); 

 

 

 

0 Kudos
0 Replies