ArcyPy: Select By Location with no selection_type and using invert_spatial_relationship

595
3
Jump to solution
01-02-2018 04:07 PM
PhilBeilin1
Occasional Contributor

I want my script to find geometry changes in 2 parcel datasets of differing months. To do this manually I used Select by Location on the earlier dataset using the later dataset using the "are identical to the source layer feature" option. Once the identical features are selected i invert the selection to find my geometry changes.

I am trying to get this done using python snippet below:

GeometryChanges = arcpy.SelectLayerByLocation_management(LaterParcelDataset, "ARE_IDENTICAL_TO", EarlierParcelDatset, 0, "NEW_SELECTION", "INVERT")

This gives me inaccurate results and I'm pretty sure this is because I have {selection_type} set as "NEW_SELECTION" but if I remove it I get an error. Esri's documentation says this:

INVERT —The result of the query will be inverted. If a selection_type option is used, the inversion occurs before the selection is combined with existing selections
So I'm totally confused on how to continue.

0 Kudos
1 Solution

Accepted Solutions
PhilBeilin1
Occasional Contributor

All i needed to do was omit the two parameters I was not using: Search Distance and Selection Type.

See below:

GeoChanges = arcpy.SelectLayerByLocation_management(LaterSOIselection, "ARE_IDENTICAL_TO", EarlierSOIselection, " ", " ", "INVERT")

View solution in original post

0 Kudos
3 Replies
DanPatterson_Retired
MVP Emeritus

from the help

SWITCH_SELECTION —Switches the selection. All records that were selected are removed from the selection, and all records that were not selected are added to the selection. The select_features and overlap_type parameters are ignored when this option is selected.

and then this one

INVERT —The result of the query will be inverted. If the selection_type option is used, the inversion occurs before the selection is combined with existing selections.

Which makes it sound like you do a select by location with new selection first with the two feature classes, then run it again removing the selector file (since it is optional) and just invert the selection.

Don't have time to try, but it looks confusing that .... combined with existing selection ...

Does that mean if you don't specify a selection type then the inversion is done right??? 

don't have anything to test, but try the two liner approach first, splitting the SBL into two steps if it doesn't work in one go (which it should)

RandyBurton
MVP Alum

"NEW_SELECTION" with "INVERT" is probably the setting you would want.  When you "remove it" and get an error, are you selecting another option, like "ADD_TO_SELECTION" (this defaults to new selection when omitted)?  Have you tried to set the search distance to something other than 0? Or just omitting it?

Also, can you elaborate on the inaccurate results.  Thanks.

0 Kudos
PhilBeilin1
Occasional Contributor

All i needed to do was omit the two parameters I was not using: Search Distance and Selection Type.

See below:

GeoChanges = arcpy.SelectLayerByLocation_management(LaterSOIselection, "ARE_IDENTICAL_TO", EarlierSOIselection, " ", " ", "INVERT")

0 Kudos