I currently have an Arcade expression (see code snippet below) that involves a karst layer and an area of interest (aoi). The expression loops through each feature of the karst layer and sums the resulting area (as an acreage) of the karst intersection with the aoi and converts that value to a percentage based on the acreage of the aoi.
The issue I'm running into is that the karst layer has overlapping features, which can result in area percentages over 100%.
I've attempted to create one geometry based on the karst features that intersect the area of interest, but haven't been successful. In essence, I'm trying to "dissolve" the karst features (within the same featureset) so I can intersect the dissolved geometry with my area of interest.
Any help here would be appreciated, thanks!
//Define Karst FeatureSet
var karst = FeatureSetByPortalItem(Portal('https://www.arcgis.com'),'689167928f6e49f689d0f08b31ad8c47',0)
//Create FeatureSet of Karst features that intersect the aoi ($feature)
var karst_aoi = Intersects(karst, $feature)
//Calculate acreage of aoi
var aoi_acre = AreaGeodetic($feature, 'acres')
//Create empty FeatureSet with percentage and karst type fields
var new_f_karst = {fields:[
{'name':'karst_percent','type': 'esriFieldTypeDouble'},
{'name':'karst_type','type': 'esriFieldTypeString'}],
'geometryType': '',
'features':[]
}
//Loop through each feature in karst_aoi FeatureSet, calculate acreage, push to created FeatureSet (new_f_karst)
for (var c in karst_aoi){
var karst_percent = ((AreaGeodetic(Intersection(c, $feature), 'acres'))/aoi_acre)*100
var new_c = {'attributes': [{'karst_percent': karst_percent},{'karst_type': 'Karst'}]
}
Push(new_f_karst.features, new_c)}
//Group records by the karst type, and give resulting karst acreage sum
var karstStats = GroupBy(FeatureSet(Text(new_f_karst)), { name: 'karst_type', expression: 'karst_type'}, { name: 'karst_percent', expression: 'karst_percent', statistic: 'SUM' });
//Create final_percent varible with summed acreages
var final_percent = 0;
for (var k in karstStats){
final_percent += k.karst_percent;
}
//Give final percentage value
var final_text = "Approximately " + final_percent + "% of the site contains karst.";
return { type: "text", text: final_text }