I am trying to complete a select by location, and then Invert my selection, the code runs and does not error, but my selection is not inverted. Not sure what could cause this.
Parks=r"Path"
outputParks=r"Path"
arcpy.MakeFeatureLayer_management(Parks, "Parks")
arcpy.MakeFeatureLayer_management(outputParks, "outputParks")
arcpy.SelectLayerbyLocation_management("Parks", "ARE_IDENTICAL_TO", outputParks, selection_type="NEW_SELECTION", invert_spatial_relationship="INVERT")
Best Answer
If you take a look at the tool help:
The arguments are case-sensitive, so you'd need to use the
INVERT
.Also, make sure both of your input layers are feature layers which you create using
Make Feature Layer
GP tool. From the code,outputParks
doesn't seem to be a feature layer.You don't provide the
overlap_type
parameter because you are missing the double quotes after"ARE_IDENTICAL_TO
.If the error persists, try to use the Select Layer By Location GP tool in ArcMap and use these two map layers you are working with. The tool should do the selection and you should get the results expected. If it worked, then you can go to the
Results
window > right-click the result created from running this GP tool >Copy As Python Snippet
. This is what I got after exporting to a Python snippet a successful selection of features that mismatch between two feature layers.This is the complete code that is executed outside of ArcMap and the selection does work.