Relationship class by location

250
1
05-10-2022 07:11 AM
Maps-Berlin
New Contributor III

I have a feature class containing thousands of lines which gets confusing to look at/work with. So my idea was to create a grid overlaying my map in which I can select any given quadrant and get all lines intersecting only this specific quadrant.  The closest I have come to realise that idea is the select by location tool which is not quite what I was hoping to do. I was wondering if there is a way to click a quadrant and automatically select corresponding lines kind of like relationship classes work, without taking the detour to the selector each time. 

Any other tips to visually "declutter" or ways to automatically visualise only a subset of large datasets  would also be much appreciated. Thanks a bunch!    

0 Kudos
1 Reply
JohannesLindner
MVP Frequent Contributor

Nothing built-in (that I know of).

 

Off the top of my head, I see two possibilities:

 

Python window

Write a Python statement like below, copy it to a text file on your desktop/some other easy location. At the start of your session, you just have to paste it once into the Python window, then you can always use the up arrow to repeatedly call it.

Select a polygon, run that command (switch to Python window, up arrow, enter), profit.

# too lazy to test...
arcpy.management.SelectLayerByLocation("LineLayer", "INTERSECT", "GridLayer", selection_type="NEW_SELECTION")

 

Relationship class and Attribute Rule

To use the relationship class behavior (automatically select all related records), you could create a relationship and assign an Attribute Rule to the lines that triggers on Insert and Update and stores the ID of the intersecting grid polygon in the feature. This way, you could do it automatically. But a line intersecting multiple polygons would only get selected by one of those.

The rule would be something like this

// too lazy to test...
if($editcontext.editType == "UPDATE" && Equals(Geometry($feature), Geometry($originalfeature)) {
    return
}
var polygons = FeatureSetByName($datastore, "Polygons", ["PrimaryKey"], true)
polygons = Intersects($feature, polygons)

// find the polygon with the greatest intersection with $feature
var max_length = 0
var poly_pk = null
for(var p in polygons) {
    var intersect_line = Intersection(p, $feature)
    if(Length(intersect_line) > max_length) {
        max_length = Length(intersect_line)
        poly_pk = p.PrimaryKey
    }
}

return poly_pk

 

 


Have a great day!
Johannes
0 Kudos