Make a labelPoint function available in Arcade for attribute rules

852
4
11-08-2022 11:28 AM
Status: Open
Labels (1)
DaleJackan_work
New Contributor II

Centroid can be used to create a unique ID, but you run into issues with the point potentially being placed outside a polygon if it has an unusual shape, hole, or is a multi-part polygon. The labelPoint property for the Geometry() function in arcpy can be used to solve this issue, but a labelPoint function is not available for Arcade. I would like a labelPoint function for Arcade to help calculate unique IDs using attribute rules.

Cheers,

Dale Jackan

4 Comments
JohannesLindner

 

I'm all for new functionality in Arcade, but I'm not too sure about your use case.

Yes, you can calculate a unique ID from Centroid() or a theoretical LabelPoint() (using the coordinates, I assume?) but the standard ways to do this are:

 

Use a database sequence

Create a database sequence and use an Attribute Rule like this on an integer field:

// Attribute Rule on KeyField
// Triggers: Insert, Update

if(IsEmpty($feature.KeyField)) {
    return NextSequenceValue("SequenceName")
}
return $feature.KeyField

Or you can use it on a text field and combine the NextSequenceValue() with some string parts.

 

Use a Globally Unique ID

You can also create a GUID field in your table and use an expression like this:

// Attribute Rule on KeyField
// Triggers: Insert, Update

if(IsEmpty($feature.KeyField)) {
    return Guid()
}
return $feature.KeyField

 

 

Assuming you use the coordinates of the polygon's centroid to calculate the ID, be aware that that value is not unique. If you copy a feature, the copy will have the same ID as the original!

DaleJackan_work

While it is true there are other methods for creating unique IDs I should have explained that this is for parcels. We would not be changing our entire database over to global IDs given the method is already in use under arcmap and in our existing records. I know this might seem niche to my organization, but the method is a standard method for property mappers. As for the IDs not being unique, parcels follow the rule that their polygons must never overlap. That said I am sure there are use cases beyond unique IDs in which one would want points only from within a polygon as can be seen by the use cases when searching arcpy.Geometry() and labelPoint, which are only available in python and thus not for use in attribute rules.

JohannesLindner

Alright, fair points.

DuncanHornby

I'm with Dale on this, using centroid XY to create an ID. It is something I do when extracting nodes from a network as not only is it an ID it's also its location and you can remove duplicates by passing into sets for example. You can apply same logic to polygons and polylines. But always good to see other approaches.