Selecting Features by Location

2155
13
Jump to solution
06-11-2012 11:17 AM
LarissaPizzolato
New Contributor
Hello,

I am trying to select features by location from the "tableName_vctor" layer as defined (and highlighted in red), then export them to a new shapefile and am receiving the following errors (refer to the blue section):

ERROR 000622: Failed to execute (Select Layer By Location). Parameters are not valid.
ERROR 000628: Cannot set input into parameter search_distance.

any insight as to how to fix these errors is much appreciated

thank-you in advance!

try:
    # Iterates through each of the input text files
    for v in list(table):
        # Removes the file extension
        tableName = os.path.splitext(v)[0]
        # Variables
        tableName_line = tableName + str("_line.shp")
        tableName_vctor = tableName + str("_vctor.shp")
        tableName_e = tableName + str ("_e.shp")
        gate = r"C:\gis\gate.shp"
        tableName_sim = tableName + str("_sim.shp")

        # Creating vectors from xy coordinates
        gp.Toolbox = r"C:\Program Files\ArcGIS\ArcToolbox\Toolboxes\Military Analyst Tools.tbx"
        gp.TableToLine_ma(v, tableName_line, "Decimal Degrees", "sLat", "sLon", "eLat", "eLon", "False", "False")
        gp.Project_management(tableName_line, tableName_vctor, "PROJCS['LCC']")

        #Selecting vectors that intersect a line, then points that intersect the vector, then removing the initial selection
        gp.SelectLayerByLocation(tableName_vctor, "intersect", gate, "NEW_SELECTION")
        gp.SelectLayerByLocation(tableName_e, "intersect", tableName_vctor, "ADD_TO_SELECTION")
        gp.SelectLayerByLocation(tableName_vctor, "intersect", gate, "REMOVE_FROM_SELECTION")

        # Write the selected features to a new feature class in the folder
        gp.CopyFeatures(tableName_sim, r"C:\gis\temp")
        
except:
    #If an error occurred while running the script, then print the messages
    print gp.GetMessages()
Tags (2)
0 Kudos
13 Replies
NobbirAhmed
Esri Regular Contributor
Which version of ArcGIS you are on?

Please add another print statement in the try block and see whether you get any success message.

try:
    gp.SelectLayerByLocation_management(tableName_e_lyr, "intersect", tableName_vec_lyr, "", "ADD_TO_SELECTION")
    print gp.GetMessages()
except:
    print gp.GetMessages(2)
0 Kudos
LarissaPizzolato
New Contributor
Hello NobbirAhmed,

I am using ArcGIS 9.3.

when I added the additional print message, and the try/except block this error occured:

Executing: SelectLayerByLocation 11013_e.lyr INTERSECT 11013_vec.lyr # ADD_TO_SELECTION 11013_e.lyr
Start Time: Tue Jun 12 14:18:24 2012
Failed to execute. Parameters are not valid.
ERROR 000732: Input Feature Layer: Dataset 20041115011426_20041122011013_e.lyr does not exist or is not supported
ERROR 000732: Selecting Features: Dataset 20041115011426_20041122011013_vec.lyr does not exist or is not supported
Failed to execute (SelectLayerByLocation).
0 Kudos
MathewCoyle
Frequent Contributor
You are referencing layer files that were never created it looks like. MakeFeatureLayer creates a temporary layer in memory, not a layer file.
0 Kudos
LarissaPizzolato
New Contributor
Thanks Mathew!
0 Kudos