2

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")

enter image description here

1
  • 1
    Please always provide errors as text rather than a picture. What version of ArcGIS are you using?
    – PolyGeo
    Commented May 5, 2017 at 21:20

1 Answer 1

3

If you take a look at the tool help:

NOT_INVERT —The result of the query will not be inverted. This is the default.

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.

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.

arcpy.SelectLayerByLocation_management(in_layer="AlternativeRoutes", 
                                       overlap_type="ARE_IDENTICAL_TO", 
                                       select_features="AlternativeRoutes_1", 
                                       search_distance="", 
                                       selection_type="NEW_SELECTION", 
                                       invert_spatial_relationship="INVERT")

This is the complete code that is executed outside of ArcMap and the selection does work.

import arcpy

routes = r"C:\GIS\Temp\ArcGISHomeFolder\scratch.gdb\AlternativeRoutes"
routes1 = r"C:\GIS\Temp\ArcGISHomeFolder\scratch.gdb\AlternativeRoutes_1"
arcpy.MakeFeatureLayer_management(in_features=routes, out_layer="AlternativeRoutes")
arcpy.MakeFeatureLayer_management(in_features=routes1, out_layer="AlternativeRoutes_1")

arcpy.SelectLayerByLocation_management(in_layer="AlternativeRoutes",
                                       overlap_type="ARE_IDENTICAL_TO",
                                       select_features="AlternativeRoutes_1",
                                       search_distance="",
                                       selection_type="NEW_SELECTION",
                                       invert_spatial_relationship="INVERT")

out_diff = r"C:\GIS\Temp\ArcGISHomeFolder\scratch.gdb\diff"
arcpy.CopyFeatures_management("AlternativeRoutes", out_diff)
print arcpy.GetCount_management(out_diff)
4
  • So I have made the changes above, but am receiving the Type Error saying that the INVERT is an unexpected keyword argument. I have added the error above. Commented May 5, 2017 at 18:55
  • I've updated my answer, please follow the guidelines outlined. Commented May 6, 2017 at 6:34
  • If you have solved the issue, I am curious what was the reason? Commented May 7, 2017 at 8:29
  • arcpy.SelectLayerbyLocation_management("Parks", "ARE_IDENTICAL_TO", outputParks, selection_type="NEW_SELECTION", invert_spatial_relationship="INVERT") Deleting the selction_type="NEW_SELCTION in this line seemed to remove the Selection issue. Commented May 8, 2017 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.