I have 2 shape files. One is a polygon while other is polyline. I need to select all the polylines that are completely inside the polygon. However this doesnot seem to work in any way.

NewLinks = "NewLinks.shp"
Buffer = "Buffer.shp"
Buffer1 = "Buffer1.shp"
arcpy.MakeFeatureLayer_management(Buffer, Buffer1) 
arcpy.SelectLayerByLocation_management(NewLinks, "COMPLETELY_WITHIN", Buffer1, "", "NEW_SELECTION", "NOT_INVERT")


Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\management.py", line 7860, in SelectLayerByLocation
raise e
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000368: Invalid input data.
Failed to execute (SelectLayerByLocation).

SelectLayerByLocation_management input must be a feature layer, so make one from the shp file first, then pass that into the method.

NewLinks = "NewLinks.shp"
Buffer = "Buffer.shp"
arcpy.MakeFeatureLayer_management(NewLinks, 'newlinks_lyr') 
arcpy.SelectLayerByLocation_management('newlinks_lyr', "COMPLETELY_WITHIN", Buffer, "", "NEW_SELECTION", "NOT_INVERT")

Also, I tend to be very explicit with paths to any files; your code may now complain it can't find those .shp files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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