Select to view content in your preferred language

Statistics of a polygon within a polygon in Experience Builder

1098
9
Jump to solution
02-21-2024 04:37 PM
mtuffy
by
Emerging Contributor

Hi Community,

So, I don't think this is a possibility in Experience Builder, but I thought I would ask just in case.

I have built a map with multiple layers of polygon, each representing different datasets. I have created a search function for users to search for a locality. I have a Near Me widget that shows all the different datasets that fall within that searched zone. I then created a query and text with dynamic content, as I was trying to get statistics of the dataset (polygons) that fall within the searched zone. But all I seem to be able to do is Sum, count, average etc for the entirety of the datasets. However, what I am wanting is to get statistics of the datasets for only the sections found within the searched zone. 

Hopefully this makes sense...but if not, this image might help. 

Areas within zone.png

A user searches the area highlighted in blue above, however they want to know how much of the yellow polygons (circled in red) extend into the searched area (highlighted in blue). So, the yellow polygon on the right might be 100 hectares in total, but only 20 hectares or 20% is within the search area. 

Is this a possibility using widgets or coding with experience builder?

Thanks in advance if anyone was able to get through all this, understand it, and provide some feedback 🙂

Matt.

0 Kudos
1 Solution

Accepted Solutions
JeffreyThompson2
MVP Regular Contributor

My screenshot was from an old version of ArcGIS Enterprise. ESRI has apparently changed 'Manage Expressions' to 'Attribute Expressions'. Using the Arcade option opens up a different interface that I am not familiar with. I am not super familiar with Arcade and my brain is stuck on low power mode this morning, but something like this in the Attribute Expressions should get you the correct percentage.

var impact_areas = Intersects($feature, FeatureSetByName($map, 'Short Term Rental Zoning District', ['*'], true))
var impacted_area = 0
for(var ia in impact_areas) {
	impacted_area += Area(Intersection($feature, ia), 'arces')
}
var total_area = $feature.Shape__Area
var percentage = impacted_area/total_area
return percentage

You should then be able to access this number in a Text field by calling the name of the Expression, something like this.

JeffreyThompson2_0-1709047866019.png

GIS Developer
City of Arlington, Texas

View solution in original post

0 Kudos
9 Replies
JeffreyThompson2
MVP Regular Contributor

It is possible to get the intersection area/percentage of two intersecting polygons into an Experience Builder popup. Both polygon layers must be loaded into a webmap as FeatureLayers. In the webmap, go to the layer you want the data to display in and customize the popup. Select Manage Expressions then create an Arcade expression. This one should find the total area in acres of a polygon titled 'Easement' within the area of the feature clicked on:

var impact_areas = Intersects($feature, FeatureSetByName($map, 'Easement', ['*'], true))
var impacted_area = 0
for(var ia in impact_areas) {
	impacted_area += AreaGeodetic(Intersection($feature, ia), 'acres')
}
return impacted_area

Add this expression to your popup and the calculated value should follow your webmap into Experience Builder.

GIS Developer
City of Arlington, Texas
0 Kudos
mtuffy
by
Emerging Contributor

Hi Jeffrey,

Thanks so much for your reply, I really appreciate it! And if this code works in the webmap then that would be absolutely fantastic and save me some headaches 🙂

I did try the code and I do get this error - 

Coding error.png

Have I typed something incorrect or missed something? I'm really sorry as I do suck at coding haha but thankyou in advance for your help!
Matt.

0 Kudos
JasonBOCQUET
Frequent Contributor

i'm not sure but maybe because you included your var impact_areas in a return clause ? i think you have not to use a return in line 7

0 Kudos
JeffreyThompson2
MVP Regular Contributor

That block of code is written in Arcade and is designed to work within the webmap. This is where you should enter it.

JeffreyThompson2_0-1708694411212.png

It looks like you are trying to use it in the Javascript/React of Developer Edition. We can make it work there too, but it will get a little more complicated.

Sidenote: Use AreaGeodetic() if you are in WGS84 or Web Mercator. Otherwise use Area().

GIS Developer
City of Arlington, Texas
0 Kudos
mtuffy
by
Emerging Contributor

Hi Jeffrey,

Thanks again for your reply, and sorry I haven't replied back earlier. I have been working with your details and with another fella at work who is good with coding (python etc), but we still couldnt get the code to do specifically what I am needing. 

So, I apologise if this message is long, but I do have a couple questions and maybe I'll layout my requirements and hopefully it'll help with development of this code. I really hope you don't mind all this details; but if we get the result, I'll owe you big time!! 😄

For starters, and sorry for my ignorance, but what is the Javascript/React of Developer Edition? Is this possibly a different level of access/program that I may be using which affects the coding options? If so, I can look into upgrading my subscription through work. 

Hopefully the following information and screenshots will provide some insight to what I am working with...

Layout and situation.png

Above is my webmap layout. 

1. In red is the option I have for adding an expression. I see in your screenshot you have 'Manage expressions' whereas I have 'Attribute Expressions'. This doesn't change even when an expression is added; still says Attribute expressions. Is this because of the React of Developer Edition? 

2. In Green is where I can add an Arcade expression. We did add an expression and some info was displayed where the Green star is, which is what I wanted. However the code for the intersect/impact areas didnt work. 

3. The Blue sections kind of show what I'd like to produce in Experience Builder. Basically the big brown sections are the Indigenous Protected Areas (IPA), and we want to see how much of a percentage sit in the IBRA areas (dark brown boundaries). For example in the blues; dark blue shows 48% of the IPA sits in the IBRA area in the north, and 52% of it sits in the IBRA area to the south.

Below is my next step where I bring the Webmap into Experience Builder....

Layout and situation2.png

1. In the search section (circled in red) is the IBRA area - which is highlighted in aqua and pointed by red arrow.

2. I have then connected the search function to the query list below which shows how many of the others layers are found in the IBRA area. For example, in orange, it states that there is 3 IPAs found in the search IBRA area. Then when the user clicks on the specific IPA they want to view details for, the info is displayed and I am wanting it to show how much of a percentage this polygon is found in the IBRA boundary (bright green example). If users click on a different IPA (Ngadju or Yalata etc which are the other purple boundary areas) it will show full details including the percentage found in the IBRA. 

 

So that's what I am doing, have done and hope to achieve. Does this make any sense, or help with what the Arcade coding should be? 

Again sorry it's so long 🙂
Matt.

0 Kudos
JeffreyThompson2
MVP Regular Contributor

My screenshot was from an old version of ArcGIS Enterprise. ESRI has apparently changed 'Manage Expressions' to 'Attribute Expressions'. Using the Arcade option opens up a different interface that I am not familiar with. I am not super familiar with Arcade and my brain is stuck on low power mode this morning, but something like this in the Attribute Expressions should get you the correct percentage.

var impact_areas = Intersects($feature, FeatureSetByName($map, 'Short Term Rental Zoning District', ['*'], true))
var impacted_area = 0
for(var ia in impact_areas) {
	impacted_area += Area(Intersection($feature, ia), 'arces')
}
var total_area = $feature.Shape__Area
var percentage = impacted_area/total_area
return percentage

You should then be able to access this number in a Text field by calling the name of the Expression, something like this.

JeffreyThompson2_0-1709047866019.png

GIS Developer
City of Arlington, Texas
0 Kudos
mtuffy
by
Emerging Contributor

Thanks so much Jeffrey, and I do apologise again that I am probably not helping the brain on low power with my over-the-top messages haha I generally like to write/expand a lot to make sure the info is clear. 

Anyway I really appreciate your continual help and support! It's helping me to solve this issue. I have used your coding and a result number is produced, but it does seem a little high which is a bit odd. But I'll have a play with it and see if I can figure out what the produced number is. If I still struggle I'll probably annoy you again. 

But seriously thank you for continuing to help! Means a lot as I'm really wanting to get this function working 🙂

0 Kudos
JeffreyThompson2
MVP Regular Contributor

Keep in mind Arcade has two area functions: Area and AreaGeodetic. You will need to use the right one. You will also need to be mindful of the default units of your polygon. You could call Area($feature, 'acre') so you can set the unit to match the calculated intersection area.

GIS Developer
City of Arlington, Texas
0 Kudos
mtuffy
by
Emerging Contributor

Hi Jeffrey,

I am sorry I haven't replied in ages, but I wanted to get in contact to let you know how it all went and to thankyou for putting up with my messages and providing a bunch of support for myself. 

For quite a bit of time I kept returning a '0' value result which I wasn't sure why. I had even chatgpt to see what the error might be and after running through all the possible steps to rectify the issue, nothing worked. 

However I had a fella I work with, who knows coding really well (first time with Arcade though), take a look and have a play. After a few hours of changing things he found the issue. In one of the lines of coding, I had an extra 'impact_areas' term which wasn't supposed to be there. I must of miswrote the code, but after removing that, the code worked and I received a % value. 

So I have been very thankful that my work colleague could find that error of mine. But thanks again for all your help; your code was perfect, I just couldnt see the error (hence I'm not good or like coding haha).

Thanks again, 

Matt.

0 Kudos