Hoping the community here can lend a hand.
The goal: create a calculation attribute rule for a polygon feature class that extracts a value from the feature with which it has the largest overlap in another dataset. If a user creates a polygon I want the value of an underlying polygon to be used for an attribute in the edited datasets. However I want to have error controls in case the user creates a polygon that overlaps two of the underlying polygons. I want to extract the attribute from the polygon with which it has the largest overlap.
Current code:
var fsJurisdiction = FeatureSetByName($datastore, "jurisdictions", ["Jurisdiction"])
var fsJurisdictionIntersect = Intersects(fsJurisdiction, $feature)
var jurisdiction = First(fsJurisdictionIntersect)
if (jurisdiction == null) return {"errorMessage": "Not in a jurisdiction"}
return jurisdiction.Jurisdiction
Solved! Go to Solution.
var fsJurisdiction = FeatureSetByName($datastore, "jurisdictions", ["Jurisdiction"])
var fsJurisdictionIntersect = Intersects(fsJurisdiction, $feature)
var intersected_jurisdictions = []
for(var j in fsJurisdictionIntersect) {
var jurisdiction = {
Jurisdiction: j.Jurisdiction,
Overlap: Area(Intersection(j, $feature))
}
Push(intersected_jurisdictions, jurisdiction)
}
function sort_by_overlap(j1, j2) { return j1.Overlap < j2.Overlap }
var jurisdiction = First(Sort(intersected_jurisdictions, sort_by_overlap))
if (jurisdiction == null) return {"errorMessage": "Not in a jurisdiction"}
return jurisdiction.Jurisdiction
var fsJurisdiction = FeatureSetByName($datastore, "jurisdictions", ["Jurisdiction"])
var fsJurisdictionIntersect = Intersects(fsJurisdiction, $feature)
var intersected_jurisdictions = []
for(var j in fsJurisdictionIntersect) {
var jurisdiction = {
Jurisdiction: j.Jurisdiction,
Overlap: Area(Intersection(j, $feature))
}
Push(intersected_jurisdictions, jurisdiction)
}
function sort_by_overlap(j1, j2) { return j1.Overlap < j2.Overlap }
var jurisdiction = First(Sort(intersected_jurisdictions, sort_by_overlap))
if (jurisdiction == null) return {"errorMessage": "Not in a jurisdiction"}
return jurisdiction.Jurisdiction
@JohannesLindner I actually wanted to follow up here in case you have additional knowledge - the syntax you gave me works flawlessly in 3.x. However I opened the gdb in 2.9 and it reverts to the same behavior when using First....it stops using largest overlap as you've described.
Is this a known limitation?
Do you actually use this expression in 2.9?
The expression should work for ArcGIS Pro 2.7+
I did test it in 2.9
I opened the database I created in 3.1, where the rules executed successfully, in 2.9. The overlap rule no longer works and it takes the first jurisdiction only.
Sorry to say that I have no clue.
Try deleting the rule and creating it in 2.9.
Well that worked perfectly. Gold star for @JohannesLindner . Thank you!