Select to view content in your preferred language

Calculate acreage of intersecting features using widgets in experience builder

366
8
Jump to solution
a month ago
Labels (1)
DanaLRobinson
Regular Contributor

I think this was possible using the screening tool in Web App Builder, but I need to do the following in Experience Builder. I am trying to use widgets to do the following, but can't seem to get the results to wokr.

a) use search widget to locate a wildfire polygon perimeter in a map and zoom or pan to it, then 

b) use Near me to calculate acres of multiple features in another feature service (surface management agency) that intersect the wildfire boundary identified in the Search widget  (or that I select in the map, I am not picky, but that selected polygon will change with each use of these tools

c) provide calculated acres by management agency that intersects the selected wildfire polygon so these acres can be viewed.  

So, taking features from dataset A (surface management agency) intersecting a selected feature in dataset B (wildfire polygon), calculating acres for the multiple polygons identified in the intersect and displaying the list of acres in a text widget.  Any help would be appreciated.

1 Solution

Accepted Solutions
DanaLRobinson
Regular Contributor

@AustinAverill  was able to quickly help me out.  Here is the arcade script to calculate instersected layers in the pop-up: 

//assigning the agency layer to a variable using the name in the map
var agencies = FeatureSetByName($map, "BLM AZ SMA - BLM AZ Surface Management Agency (Polygon)")

//get all agency polygons that intersect our event polygon
var intersectingAgencies = Intersects($feature, agencies)

//get distinct agencies
var distinctAgencies = Distinct(intersectingAgencies, "ADMIN_AGENCY_CODE")


//define the variables to store our generated information in
var fldinfos = [] //will contain the field information to create a table element
var atts = {}//will contain the attribut we want to display

//loops through distinctAgencies and get intersecting area
for(var a in distinctAgencies){
	var nm = a['ADMIN_AGENCY_CODE']
	//filter intersecting features down to current agency
	var nmFeatures = Filter(intersectingAgencies, `ADMIN_AGENCY_CODE = '${nm}'`)

	//define placeholder to sum multiple intersecting features of same agency
	var acres = 0
	for(var row in nmFeatures){
		//defines the intersection of area between current feature and intersecting features, and calculates area in acres
		var calcAcres = AreaGeodetic(Intersection(Geometry($feature), Geometry(row)), 'acres')
		acres += calcAcres
	}

	//store the calculated overlaps into out placeholders from before
	Push(fldinfos, {fieldName : nm})
	atts[nm] = `${Round(acres, 1)} Acres`
	
}

//define the field list element we will return
var element = {
    type: 'fields',
    //title: '',
    //description : '',
    fieldInfos:  fldinfos,
    attributes : atts  // replace this dictionary with your own key-value pairs
  }

	return element

View solution in original post

8 Replies
JeffreyThompson2
MVP Frequent Contributor

This looks like a job for the Analysis Widget. Specifically the Overlay Layers Tool. Note: using the Analysis Widget in ArcGIS Online costs Credits.

https://developers.arcgis.com/experience-builder/guide/analysis-widget/

GIS Developer
City of Arlington, Texas
AustinAverill
Frequent Contributor

The available run time tools in ExB Online are not going to be able to very easily handle this sort of task (if you can get it to appropriately segment the area by agency at all). This would be a much more effective component of the wildfire polygons pop-up. You could populate the values by agency using a Arcade relatively easily and be much simpler for the end user to interact with (just click the wildfire).

DanaLRobinson
Regular Contributor

Thanks for your feedback.  I think this calculation into a wildfire polygon attribute would need to be run rather frequently. The wildfire polygon is a nationwide live hfs, changing sometimes multiple times daily, edited by many users, managed by a few, and not owned by me.  

Didn't the screening tool do this in Web App Builder (just want to confirm as I have only heard this, not used it when it was available and  functioned in this workflow).  I understand of course that the screening tool has not been updated yet in ExB.

Again, I appreciate your help with this.

 

0 Kudos
AustinAverill
Frequent Contributor

The screening tool did used to do something similar to this. The near me tool still allows you to get similar results, and there is an option to output the sum of intersected area. But the sum of intersected area would be by layer, not by category/attribute of a single polygon layer.

 

In terms of arcade, you can write an arcade script to display in the popup that recalculates this on the fly. This means it's only calculated whenever a user interacts with the popup, does not need to be stored anywhere, and updates as soon as your data updates. I still contend this would be the best way to solve and display this data quickly and efficently for your end users.

JeffreyThompson2
MVP Frequent Contributor

I agree with @AustinAverill. Arcade would be a good solution assuming the answer does not need to be saved. Also, the Arcade solution would not cost Credits. 

GIS Developer
City of Arlington, Texas
AustinAverill
Frequent Contributor

Not using credit's is Arcade's biggest advantage over everything! If you want to share the way your layers and fields are layed out, I'd be happy to help write the script if you don't have experience with it @DanaLRobinson 

0 Kudos
DanaLRobinson
Regular Contributor

direct msg sent to you.

 

0 Kudos
DanaLRobinson
Regular Contributor

@AustinAverill  was able to quickly help me out.  Here is the arcade script to calculate instersected layers in the pop-up: 

//assigning the agency layer to a variable using the name in the map
var agencies = FeatureSetByName($map, "BLM AZ SMA - BLM AZ Surface Management Agency (Polygon)")

//get all agency polygons that intersect our event polygon
var intersectingAgencies = Intersects($feature, agencies)

//get distinct agencies
var distinctAgencies = Distinct(intersectingAgencies, "ADMIN_AGENCY_CODE")


//define the variables to store our generated information in
var fldinfos = [] //will contain the field information to create a table element
var atts = {}//will contain the attribut we want to display

//loops through distinctAgencies and get intersecting area
for(var a in distinctAgencies){
	var nm = a['ADMIN_AGENCY_CODE']
	//filter intersecting features down to current agency
	var nmFeatures = Filter(intersectingAgencies, `ADMIN_AGENCY_CODE = '${nm}'`)

	//define placeholder to sum multiple intersecting features of same agency
	var acres = 0
	for(var row in nmFeatures){
		//defines the intersection of area between current feature and intersecting features, and calculates area in acres
		var calcAcres = AreaGeodetic(Intersection(Geometry($feature), Geometry(row)), 'acres')
		acres += calcAcres
	}

	//store the calculated overlaps into out placeholders from before
	Push(fldinfos, {fieldName : nm})
	atts[nm] = `${Round(acres, 1)} Acres`
	
}

//define the field list element we will return
var element = {
    type: 'fields',
    //title: '',
    //description : '',
    fieldInfos:  fldinfos,
    attributes : atts  // replace this dictionary with your own key-value pairs
  }

	return element