Select to view content in your preferred language

Automatically populating an attribute when a new polygon is created

383
4
11-04-2024 06:07 PM
GregEscott
Emerging Contributor

In ArcPro, is it possible to automatically add or edit an attribute in an existing field when a new polygon is created?

Example: A polygon is split in 2.  One of the two polygons will have the field "Number" updated.  

Original polygon was "Number" '1'
New polygon from the split will then become "Number" '2'

This would only work if it added a number which is +1 of the highest number in that field of all polygons.

Example: "Number" '1234' is the highest number in the "Number" field.

Original polygon being split is "Number" '1'
New polygon from the split will have "Number" '1235'

I can't find any information about whether or not this is even possible.

Thanks for your time!

 

0 Kudos
4 Replies
Luke_Pinner
MVP Regular Contributor

Look into attribute rules.

GregEscott
Emerging Contributor

That's a great resource, thanks!

I got as far as trying to create a calculation attribute rule, using Arcade to build an expression.

I must be way off.  It shows an error in the attribute rules table (red icon next to the rule).  The expression is valid, but it's not working.

*****

// Define the field name
var field_name = "POLY_NUM";

// Get the maximum value in the field
var max_value = Max(FeatureSetByName($datastore, "R11_GE", [field_name]), field_name);

// Add 1 to the maximum value
if (IsEmpty(max_value)) {
return null; // or return 1 if you want to set 1 as the minimum
} else {
return max_value + 1;
}

 

******

I had the trigger set to insert.  I guess update might work too, but maybe that updates the number if you're just changing a boundary, which wouldn't work out well.

Seems like this is much more complex than I had imagined.  I really appreciate you pointing me in the right direction.  It was useful to read about, even if it didn't work out.

0 Kudos
GregEscott
Emerging Contributor

If anyone stumbles on this and is looking for something that might work, here is what worked for me.

  1. Assign global IDs to your shape file: (data management tools) to get a unique ID for every polygon and each new polygon.
  2. Data design - Attribute rules (right click shape file in table of contents)

Here you can create a calculation rule using the Arcade language

  1. Code: 

// Define the field name

var field_name = "POLY_NUM";

 

// Get the maximum value in the field

var max_value = Max(FeatureSetByName($datastore, "R11_GE", [field_name]), field_name);

 

// Add 1 to the maximum value

return max_value + 1;

 

*****end*****

 

POLY_NUM is my polygon number field.  

R11_GE is my polygon shape file

 

An improvement to this code would be to find any "unused" numbers before the MAX number.  Ie: numbers 7-9 out of 1-99 are not populated.  Finding a way to select for number 7, because it is not yet used, may be better than using number 100, which would be the MAX+1

That is out of my grasp and I'll have to settle for the MAX number.  Perhaps this helps someone with a similar problem.  

0 Kudos
ToddW_stl
Esri Contributor

Hi @GregEscott - if it helps, here is some additional info about using a database sequence with attribute rules.  https://community.esri.com/t5/attribute-rules-videos/generating-unique-ids-with-attribute-rules/td-p... 

0 Kudos