AnsweredAssumed Answered

Select by Location Error

Question asked by rralbritton on Jun 20, 2016
Latest reply on Jun 20, 2016 by rralbritton

I have a script that should select points by location, and then switch the selection.

 

I have made the input feature classes in-memory layers using the MakeFeatureLayer tool, and the print out says these have been made successfully, however, when the script runs the SelectLayerByLocation script I get the following error:

 

ExecuteError: Failed to execute. Parameters are not valid.

ERROR 000368: Invalid input data.

ERROR 000732: Selecting Features: Dataset S:/Rachel/Data/UTA_Data.gdb/newStopsFL does not exist or is not supported

Failed to execute (SelectLayerByLocation).

 

I've tried this using feature classes and shapefiles and converting those to in memory layers and both have failed. Any ideas?

 

import arcpy, os

#workspace & parameters
workspace = arcpy.env.workspace  = "S:/Rachel/Data/UTA_Data.gdb"
if not os.path.exists(workspace): os.makedirs(workspace)
arcpy.env.overwriteOutput = True

#Input Data
newStops = "S:/Rachel/Data/UTA_Data.gdb/newStopstest" #change to user input
clipBoundary = "S:/Rachel/Data/UTA_Data/Clip_Boundary.shp"


#Clip new stops dataset to campus boundary
clippedStops = workspace+"/clippedStops"
arcpy.Clip_analysis(newStops, clipBoundary, clippedStops)
print arcpy.GetMessages()+"\n"

#Count record #'s in both new and old sets
oldStopsCount = arcpy.GetCount_management(oldStops)
oldCntResults = int(oldStopsCount.getOutput(0))
print "There are "+str(oldCntResults)+" old stops.\n"
newStopsCount = arcpy.GetCount_management(clippedStops)
newCntResults = int(newStopsCount.getOutput(0))
print "There are "+str(newCntResults)+" new stops.\n"

if newCntResults < oldCntResults: 
#then stops from the old feature class need to be selected out and deleted

    #Convert new & old stops to a feature layer
    newStopsFL = workspace+"/newStopsFL"
    oldStopsFL = workspace+"/oldStopsFL"
    arcpy.MakeFeatureLayer_management(clippedStops, newStopsFL)
    print arcpy.GetMessages()+"\n"
    arcpy.MakeFeatureLayer_management(oldStops, oldStopsFL)
    print arcpy.GetMessages()+"\n"
                                 
    #Select by Location
    arcpy.SelectLayerByLocation_management(oldStopsFL,"INTERSECT",newStopsFL,0,"SWITCH_SELECTION")
    print arcpy.GetMessages()
    oldStopsCount2 = arcpy.GetCount_management(oldStopsFL)
    print oldStopsCount2

else:
    print "done"

Outcomes