Select to view content in your preferred language

Arcade expression to label polygons with count of overlapping features in that layer

1355
4
07-11-2023 03:24 AM
Labels (2)
HeatherBell
Frequent Contributor

Hello,

I'm looking for a way of showing in a clear way to anyone viewing this map that there are multiple polygons (campaigns) in one location which isn't immediately obvious unless you click through the pop ups. 

There seems to be a limitation in AGOL that polygons cannot be clustered in maps at present. I have seen a seperate enhancement idea for this on the forum.

However, I need to get around this and the simplest way seems to be to create a label expression using Arcade which indicates the number of overlapping polygons in that layer. Many polygons will have identical centroids which is why they do not show unless you click through the pop ups. To make the view less cluttered I have created an integer field called 'points' with a default value of 1 which is mapped to show psuedo points without having to create another layer. 

I have tried a few different methods using an intersect and have got none of them to work with a label. I'd really appreciate if someone could help me write this expression.

I think the method would be something like this:

// Write script to get the number of overlapping polygons and label the top polygon with the number of total features 
//1. count intersecting polygons
//2. return a label with number of total polygons that overlap in that location + "campaigns"
 
Thank you

 

HeatherBell_0-1689070281525.png

 

GIS Analyst @ The Rivers Trust
0 Kudos
4 Replies
RussRoberts
Esri Notable Contributor

Hey Heather,

- featuresets can only be used for popups and wont work with labeling or styling.

- The clustering for non-point features is something we are looking at and if you can share this sample map I can post it as an example within the development issue we have active for this. 

- Something I did a quick run through on which probably could be improved and would want to double check the counts was this Pro tool on the hosted feature layer and generate the table.  I took the generated feature class and joined it to the table and published it as a new feature layer. Then I did a view join to the original feature layer. When I created the label I setup a filter on the label class to not show labels when there was no intersect present.

https://pro.arcgis.com/en/pro-app/latest/tool-reference/analysis/count-overlapping-features.htm

 

RussRoberts_0-1689090257123.png

 

0 Kudos
HeatherBell
Frequent Contributor

Hi Russ, 

Thank you very much for looking into this. This would be a good solution. However, I'm afraid that the dataset will be constantly updated by community users through a hub. So I'm really hoping that there will be an Arcade solution that will allow this type of labelling or a proper clustering feature as with point data - which would be even better. Otherwise, I would have to run this through a script to keep updating or overwriting the data which seems quite convuluted. 

I've made a public view of the layer and a map here:

https://theriverstrust.maps.arcgis.com/apps/mapviewer/index.html?webmap=b0be32800d0f432ab4bd8b036bb5...

Would be great to have an update on this if it progresses because we are looking at alternative ways of doing this outside of the Esri environment. I'm currently logging a number of limitations like this through using Esri for creating citizen science databases but our preference would be Esri because we are already using it. 

Thank you. 

GIS Analyst @ The Rivers Trust
RussRoberts
Esri Notable Contributor

Thanks, I've added this to our dev issue on the polygon clustering side. 

Could you use a point feature for each campaign.  Then have a  1:M relationship to the monitoring hub (guessing that could be the polygon boundary) to the multiple campaigns taking place within it? Then you could cluster the campaign layer and label like you need above.

HeatherBell
Frequent Contributor

Hi Russ, 

Yeah that would be one way to do it, which is what I have done in another hub of ours, but not with an actual related table. We have a projects layer (point), with an interventions layer (polygon) with corresponding codes between, and with a related table of maintainence visits attached to those interventions. 

https://nfm-theriverstrust.hub.arcgis.com/

In this case, we would like to use polygons to be able to show the coverage of each campaign in some views. 

Thank you.  

GIS Analyst @ The Rivers Trust
0 Kudos