Select to view content in your preferred language

Attribute Rule - Generate ID

883
3
08-25-2023 01:22 AM
RMR
by
New Contributor

In the old Desktop Attribute Assistant, you could create multiple rules:

  1. Create a rule to generate incremental sequential IDs (Max + 1) based on the last generated ID (the generated ID starts at 1000).

  2. Copies a series of values from the nearest feature in a specified layer.

In the screenshot, you can see how the rules are defined in ArcMap/Attribute Assistant. I've tried several codes in Attribute Rule without success. How can I achieve these actions in ArcGIS Pro?"

 

 

 

 

RMR_0-1692950213423.png

 

Tags (1)
3 Replies
JohannesLindner
MVP Frequent Contributor

For the IDs, see my answer in this question: https://community.esri.com/t5/arcgis-pro-questions/using-attribute-rules-to-create-sequential-id/m-p...

 

For returning the nearest feature's attributes, you could do something like this:

// Calculation Attribute Rule
// field: empty!
// triggers: Insert, update

var other_fc = FeaturesetByName($datastore, "Etages")
var search_dist = 1000

// get all features in other_fc within search distance
var other_near = Intersects(other_fc, Buffer($feature, search_dist))

// find the nearest
var min_dist = search_distance
var other_nearest = null
for(var f in other_near) {
  var dist = Distance($feature, f)
  if(dist < min_dist) {
    other_nearest = f
    min_dist = dist
  }
}
// abort if no feature was found in the search distance
if(other_nearest == null) { return }

// copy the attributes
return {
  attributes: {
    EtaID: EtaID,
    EtaCode: EtaCode,
    NivCode: NivCode,
    }
  }

Have a great day!
Johannes
0 Kudos
RMR
by
New Contributor

Hello, I would like to thank you for responding to my request so quickly and for the solution provided. I have encountered an issue with this code on my map, as it doesn't seem to recognize the "Etages" layer. Could you please let me know the possible reason for this?

RMR_0-1692962290183.png

RMR_1-1692962333682.png

 

 

0 Kudos
JohannesLindner
MVP Frequent Contributor

Attribute Rules don't work with layers in maps, they work with featureclasses/tables in the same database.

  • Etages has to be in the same database as the fc where you are implementing the rule
  • If the name is different, change it in the expression
  • If you are working in an Enterprise database (.sde), change the name to the full name: DatabaseName.DataOwner.TableName

Have a great day!
Johannes
0 Kudos