Select to view content in your preferred language

Arcade expression to assign unique id to each polygon in an edit session

115
0
3 weeks ago
Labels (1)
AGP
by
Regular Contributor

I have a polygon layer with a numeric attribute (id_astwhich I want to populate with the next consecutive value for every new polygon created in the Map Viewer. When updating polygons this attribute should not be recalculated.

To get this I configured a form and added the following calculated expression to populate id_ast attribute:

  if($editcontext.editType == "UPDATE") {
    return $feature.id_assentament
  } else {
    var vals = FeatureSetById($datastore,"0",['id_ast'],false)
    var numarray = []
    for (var n in vals){
      var nn = Number(n.id_ast)
      Push(numarray, nn)
    }
    var maxnum = Max(numarray)
    var newnum = maxnum + 1
    if(newnum == null) { return 1 }
 
    return newnum
  }

If works except when multiple polygons are created in the same edit session. I mean, I select the polygon layer in the Create features section of the Editor pane, then I draw a polygon and before clicking Create I draw more polygons. All this polygons get the same value for id_ast.

How can I access the attribute values of the polygons in the edit session to assign a different id_ast to each? 

Tags (2)
0 Kudos
0 Replies