Select to view content in your preferred language

How to generate 'largest overlap' from polygon-in-polygon query

1043
6
Jump to solution
04-27-2023 12:57 PM
SFM_TravisBott
Frequent Contributor

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

 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Alum
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

Have a great day!
Johannes

View solution in original post

0 Kudos
6 Replies
JohannesLindner
MVP Alum
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

Have a great day!
Johannes
0 Kudos
SFM_TravisBott
Frequent Contributor

@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?

0 Kudos
JohannesLindner
MVP Alum

Do you actually use this expression in 2.9?

The expression should work for ArcGIS Pro 2.7+


Have a great day!
Johannes
0 Kudos
SFM_TravisBott
Frequent Contributor

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. 

0 Kudos
JohannesLindner
MVP Alum

Sorry to say that I have no clue.

Try deleting the rule and creating it in 2.9.


Have a great day!
Johannes
0 Kudos
SFM_TravisBott
Frequent Contributor

Well that worked perfectly. Gold star for @JohannesLindner . Thank you!

0 Kudos