Select to view content in your preferred language

Attribute rules in Arc GIS Pro

1501
15
04-13-2023 08:02 AM
AndrewReynoldsDevon
Occasional Contributor

I need to do a 4 spatial queries against different polygon features. The 4 polygon features all have the same field name of 'Name' but the field in the point feature is as such, Ward, Parish, County & District. 

For attribute rules to work like this do the tables need to be joined?

I'd like to do start with an immediate calculation rule so that when a point is created 4 spatial queries are done at the same time but then once is working I need to use the batch feature & apply these rules to 2 million items of data. 

The spatial rule will need to be something like which polygon feature does this point exist in?

0 Kudos
15 Replies
JohannesLindner
MVP Frequent Contributor

The rule could be something like this:

// Calculation Attribute Rule on the point fc
// field: leave empty!
// triggers: insert, update

// load the different polygons into a dictionary where the point fc field names are the keys
var featuresets = {
    "Ward": FeaturesetByName($datastore, "Wards", ["Name"], false),
    "Parish": FeaturesetByName($datastore, "Parishes", ["Name"], false),
    "County": FeaturesetByName($datastore, "Counties", ["Name"], false),
    "District": FeaturesetByName($datastore, "Districts", ["Name"], false),
}

// create the result dictionary
var result = {attributes: {}}

for(var field in featuresets) {
    // get the first intersecting polygon
    var fs = featuresets[field]
    var i_fs = First(Intersects(fs, $feature))
    // get its name (or null if there is no intersecting polygon)
    var name = IIf(i_fs == null, null, i_fs.Name)
    // append to the result
    result.attributes[field] = name
}

// return the result
return {result: result}

 

It might be better to check the "Exclude from application evaluation" checkbox. This way, only the database executes the rule, not your application (eg ArcGIS Pro). This should make huge bulk updates faster.

 

To trigger this rule for each feature, use the field calculator to calculate any field to be the value that is already in there.


Have a great day!
Johannes
0 Kudos
AndrewReynoldsDevon
Occasional Contributor

Hi,

Thanks for the speedy reply 🙂

As per the snips I'm getting an error saying I need to add global ID's. Is this a pre req to using attribute rules?

Also am I adding this code 4 times but tweaking it for each field or do I leave the field drop down blank? 

The idea of fast automation sounds exciting however I need to get this working on an immediate calculation rule then go from there.

Thanks

Andy

0 Kudos
JohannesLindner
MVP Frequent Contributor

As per the snips I'm getting an error saying I need to add global ID's. Is this a pre req to using attribute rules?

Yes.

 

Also am I adding this code 4 times but tweaking it for each field or do I leave the field drop down blank? 

Leave it blank.


Have a great day!
Johannes
0 Kudos
AndrewReynoldsDevon
Occasional Contributor

Ideal - have got it working for new items created 🙂

So this is the next challenge - adding Global ID's to 2 million items, adding 4 fields to the table then running the code. I'm thinking of using model builder. If I check 'exclude from app...' would the above workflow work or would it only run as a script? I'd ideally like to let it run overnight then come back & it's all done 🙂

0 Kudos
JohannesLindner
MVP Frequent Contributor

You could just run a little Python script in the ArcGIS Pro Python window:

# path to your point fc
fc = "C:/data/my_database.gdb/Points"

# add GlobalIDs
arcpy.management.AddGlobalIDs(fc)

# add fields
arcpy.management.AddField(fc, "Ward", "TEXT")
arcpy.management.AddField(fc, "Parish", "TEXT")
arcpy.management.AddField(fc, "County", "TEXT")
arcpy.management.AddField(fc, "District", "TEXT")

# trigger updates
arcpy.management.CalculateField(fc, "Ward", "null", "ARCADE")

Have a great day!
Johannes
0 Kudos
AndrewReynoldsDevon
Occasional Contributor

Regarding the filepath of the point fc -this is stored in an geodatabase so in the python does it need to refer to the manager connection to the geodb? then after that the location of the item?

0 Kudos
JohannesLindner
MVP Frequent Contributor

Yes.

fc = "C:/bla/database_connection.sde/Points"

Have a great day!
Johannes
0 Kudos
AndrewReynoldsDevon
Occasional Contributor

I'm testing the functionality of the applying the attribute rule to existing features. I launched the Calculate Field from the geoprocessing tools in Pro however it wants a specific field name see snip. The code in the Attribute rule editor allows the field name to be blank.

3.JPG

0 Kudos
JohannesLindner
MVP Frequent Contributor

Yeah, you can't just take that expression and use it in the field calculator. The Attribute Rule calculates multiple fields at once, you can't do that in the calculator.

To apply the rule on an existing feature:

  • create the rule, be sure that it triggers on update
  • make any edit to the feature

For bulk updates, just use the field calculator to update a field (let's call it Field1) to the value that is alread in that field:

// Field1 = 
return $feature.Field1

Have a great day!
Johannes
0 Kudos