Select to view content in your preferred language

Arcade expressions to update the number in another layer

233
2
07-09-2024 04:10 AM
Labels (1)
witcherrie
New Contributor

Hello,

I am pretty new at Arcade expressions and I struggle deeply with making specific expression.

I have the point layer, let's call it ,,Points".

I have the polygon layer, let's call it ,,Polygons". 

Some points are in the polygons from "Polygons" and if they are falling into the specific polygon they get from this specific polygon id called No. The attribute No. exist in ,,Polygons" and in ,,Points". 

In the polygon layer I have the attribute ,,Number of points" and I already made the attribute rule that counts the number of points in this layer. ,,Number of points" is also updating while I move the points, but it's not working when I delete the point. 

What is wrong with this code?

var fs = FeatureSetByName($datastore, "Polygons")
var updates=[]
var i =0
for(var pol in fs){
if(pol.id ==$feature.id){
updates[i++] = {'globalid': pol.globalid,
                'attributes': {'No': -1}
               }
}

}
return {
   'result': $feature.field_in_point_layer, 
   'edit': [{
        'className': 'Polygons',
        'updates': updates           
    }]
}

 

Tags (2)
0 Kudos
2 Replies
witcherrie
New Contributor

I am sorry, the attribute that is the same for both point and polygon layer is ,,id", the attribute with the number of points is called ,,No".

0 Kudos
VinceE
by
Frequent Contributor

Can you clarify this a bit, perhaps with a diagram or picture? Do you want to dynamically count the number of points that fall within a given polygon? Or simply count the number of points that have the same "id" as a polygon? I think both Polygons and Points have an "id" field, but where is the "No" field? In the Polygon feature class?

0 Kudos