+ Reply to Thread
Results 1 to 14 of 14

Thread: Selecting Features by Location

  1. #1
    larissa pizzolato
    Join Date
    Jun 2012
    Posts
    17
    Points
    0
    Answers Provided
    0


    0

    Default Selecting Features by Location

    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!

    Code:
    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()
    Last edited by lavpizzo; 06-11-2012 at 11:38 AM.

  2. #2
    Mathew Coyle

    Join Date
    Feb 2011
    Posts
    1,369
    Points
    958
    Answers Provided
    150


    0

    Default Re: Selecting Features by Location

    You can only do selections on layers, not feature classes.

    Also, this is the syntax.
    SelectLayerByLocation_management (in_layer, {overlap_type}, {select_features}, {search_distance}, {selection_type})
    Mathew Coyle, EADA10
    GIS Analyst
    Alberta-Pacific Forest Industries Inc.
    ArcGIS 10.2.1 Testing
    ArcGIS 10.1 SP1
    Windows 7 SP1 64-bit

  3. #3
    larissa pizzolato
    Join Date
    Jun 2012
    Posts
    17
    Points
    0
    Answers Provided
    0


    0

    Default Re: Selecting Features by Location

    When creating the feature layer using the following code,
    Code:
    # Make a layer from the shapefiles
    gp.MakeFeatureLayer("tableName_e.shp", "tableName_e_lyr")
    gp.MakeFeatureLayer("tableName_vctor.shp", "tableName_vctor_lyr")
    I am trying to call on shapefiles that were made earlier in the code (the files in blue), yet I am getting this error:
    Failed to execute. Parameters are not valid.
    ERROR 000732: Input Features: Dataset tableName_e.shp does not exist or is not supported
    Failed to execute (MakeFeatureLayer).

  4. #4
    Marcin Gasior

    Join Date
    Oct 2010
    Posts
    450
    Points
    559
    Answers Provided
    91


    0

    Default Re: Selecting Features by Location

    The shapefile you specified is not found in geoprocessing workspace or gp.workspace was not declared.

    So you have to:
    - declare gp.workspace which contains your shapefiles
    or
    - provide full path (or variable with path) in gp.MakeFeatureLayer_management() tool
    Marcin Gąsior : GIS Analyst | Polish Academy of Sciences || GIS freelancer/consultant: e-mail

  5. #5
    larissa pizzolato
    Join Date
    Jun 2012
    Posts
    17
    Points
    0
    Answers Provided
    0


    0

    Default Re: Selecting Features by Location

    Code:
    # Make a layer from the feature class
            gp.MakeFeatureLayer_management(gate, "gate_lyr")
            gp.MakeFeatureLayer_management(tableName_e, "tableName_e_lyr")
            gp.MakeFeatureLayer_management(tableName_vec, "tableName_vec_lyr")
            print "Feature Layers created."
    
            #Selecting the vectors that intersect the gate
            gp.SelectLayerByLocation_management(tableName_vec_lyr, "intersect", gate_lyr)
            # Add to selection, points that intersect with the previously selected vectors
            gp.SelectLayerByLocation_management(tableName_e_lyr, "intersect", tableName_vec_lyr, "ADD_TO_SELECTION")
            # Remove initial vector selection
            gp.SelectLayerByLocation_management(tableName_vec_lyr, "intersect", gate_lyr, "REMOVE_FROM_SELECTION")
            # Write the selected features to a new feature class
            gp.CopyFeatures(tableName_e_lyr, tableName_sim)
    The feature layers are successfully created, and the first "select layer by location " works, but it doesn't seem to perform the 2 subsequent "select layer by location"'s.

  6. #6
    Mathew Coyle

    Join Date
    Feb 2011
    Posts
    1,369
    Points
    958
    Answers Provided
    150


    0

    Default Re: Selecting Features by Location

    Quote Originally Posted by lavpizzo View Post
    Code:
    # Make a layer from the feature class
            gp.MakeFeatureLayer_management(gate, "gate_lyr")
            gp.MakeFeatureLayer_management(tableName_e, "tableName_e_lyr")
            gp.MakeFeatureLayer_management(tableName_vec, "tableName_vec_lyr")
            print "Feature Layers created."
    
            #Selecting the vectors that intersect the gate
            gp.SelectLayerByLocation_management(tableName_vec_lyr, "intersect", gate_lyr)
            # Add to selection, points that intersect with the previously selected vectors
            gp.SelectLayerByLocation_management(tableName_e_lyr, "intersect", tableName_vec_lyr, "ADD_TO_SELECTION")
            # Remove initial vector selection
            gp.SelectLayerByLocation_management(tableName_vec_lyr, "intersect", gate_lyr, "REMOVE_FROM_SELECTION")
            # Write the selected features to a new feature class
            gp.CopyFeatures(tableName_e_lyr, tableName_sim)
    The feature layers are successfully created, and the first "select layer by location " works, but it doesn't seem to perform the 2 subsequent "select layer by location"'s.
    You need to use the proper syntax.
    SelectLayerByLocation_management (in_layer, overlap_type, select_features, search_distance, selection_type)
    http://webhelp.esri.com/arcgisdeskto...9&tocVisable=0

    You are trying to insert "ADD_TO_SELECITON" in the search distance parameter.
    Mathew Coyle, EADA10
    GIS Analyst
    Alberta-Pacific Forest Industries Inc.
    ArcGIS 10.2.1 Testing
    ArcGIS 10.1 SP1
    Windows 7 SP1 64-bit

  7. #7
    larissa pizzolato
    Join Date
    Jun 2012
    Posts
    17
    Points
    0
    Answers Provided
    0


    0

    Default Re: Selecting Features by Location

    It says that the search distance is optional so I have tried to set it as "None", "Null", "No_Value", "", " ", "0", as I do not want to create a buffer, but rather only select the points that intersect with the specified vector... I can't seem to find any other alternative placeholder to setting it as blank.

    Quote Originally Posted by mzcoyle View Post
    You need to use the proper syntax.
    SelectLayerByLocation_management (in_layer, overlap_type, select_features, search_distance, selection_type)
    http://webhelp.esri.com/arcgisdeskto...9&tocVisable=0

    You are trying to insert "ADD_TO_SELECITON" in the search distance parameter.

  8. #8
    Mathew Coyle

    Join Date
    Feb 2011
    Posts
    1,369
    Points
    958
    Answers Provided
    150


    0

    Default Re: Selecting Features by Location

    Either of these should work.
    "" or "#"

    Code:
    gp.SelectLayerByLocation_management(tableName_e_lyr, "intersect", tableName_vec_lyr, "", "ADD_TO_SELECTION")
    
    gp.SelectLayerByLocation_management(tableName_vec_lyr, "intersect", gate_lyr, "#","REMOVE_FROM_SELECTION")
    Are you getting an error or anything when these execute? Or just unexpected behaviour?
    Mathew Coyle, EADA10
    GIS Analyst
    Alberta-Pacific Forest Industries Inc.
    ArcGIS 10.2.1 Testing
    ArcGIS 10.1 SP1
    Windows 7 SP1 64-bit

  9. #9
    Nobbir Ahmed

    Join Date
    Jun 2010
    Posts
    327
    Points
    124
    Answers Provided
    17


    0

    Default Re: Selecting Features by Location

    After you set an empty string (red) for the search_distance parameter:

    Code:
    gp.SelectLayerByLocation_management(tableName_e_lyr, "intersect", tableName_vec_lyr, "", "ADD_TO_SELECTION")
    Please enclose the call with try-except block as follows:


    Code:
    try:
        gp.SelectLayerByLocation_management(tableName_e_lyr, "intersect", tableName_vec_lyr, "", "ADD_TO_SELECTION")
    
    except:
        print gp.GetMessages(2)
    What error message do you get now?

  10. #10
    larissa pizzolato
    Join Date
    Jun 2012
    Posts
    17
    Points
    0
    Answers Provided
    0


    0

    Default Re: Selecting Features by Location

    I added the try and except statement around the select layers by location by did not get any error messages generated.

    This is what printed in the python shell:
    Feature Layers created. (suggesting that the feature layers were created)
    Selecting vectors that intersect the gate for:20041115011426_20041122011013 (this is the start of the select by location commands)
    (i'm not sure why this is occuring after the feature layers should have aExecuting: MakeFeatureLayer E:\temp\5464648_vec.shp vec_lyr # # "CP CP VISIBLE NONE;startX startX VISIBLE NONE;startY startY VISIBLE NONE;dispX dispX VISIBLE NONE;dispY dispY VISIBLE NONE;sLat sLat VISIBLE NONE;sLon sLon VISIBLE NONE;theta theta VISIBLE NONE;pCorr pCorr VISIBLE NONE;pkStr pkStr VISIBLE NONE;cCorr cCorr VISIBLE NONE;conf conf VISIBLE NONE;velX velX VISIBLE NONE;velY velY VISIBLE NONE;endX endX VISIBLE NONE;endY endY VISIBLE NONE;eLat eLat VISIBLE NONE;eLon eLon VISIBLE NONE"
    Start Time: Tue Jun 12 12:57:06 2012
    Executed (MakeFeatureLayer) successfully.
    End Time: Tue Jun 12 12:57:06 2012 (Elapsed Time: 0.00 seconds)

    I know that the select by location should work because when I do it manually in ArcMap, i'm able to select several features through following the similar set of commands but the automation for this step doesn't seem to run.

    Code:
            # Variables...
            tableName_e = tableName + str("_e.shp")
            tableName_vec = tableName + str("_vec.shp")
            tableName_e = tableName + str ("_e.shp")
            tableName_sim = tableName + str("_sim.shp")
            gate = r"E:\test\gate.shp"
            end_lyr = tableName + str("_e.lyr")
            vec_lyr = tableName + str("_vec.lyr")
            
     # Make a layer from the feature class
            gp.MakeFeatureLayer_management(gate, "gate_lyr")
            gp.MakeFeatureLayer_management(tableName_e, "end_lyr")
            gp.MakeFeatureLayer_management(tableName_vec, "vec_lyr")
            print "Feature Layers created."
    
            #Selecting the vectors that intersect the gate
            print "Selecting vectors that intersect the gate for:" + str(tableName)
            
            # Process: Select Layer By Location...
            gp.SelectLayerByLocation_management(vec_lyr, "INTERSECT", gate_lyr, "", "NEW_SELECTION")
    
            # Process: Select Layer By Location (2)...
            gp.SelectLayerByLocation_management(end_lyr, "INTERSECT", vec_lyr, "", "ADD_TO_SELECTION")
    
            # Process: Select Layer By Location (3)...
            gp.SelectLayerByLocation_management(vec_lyr, "INTERSECT", gate_lyr, "", "REMOVE_FROM_SELECTION")
    
            # Write the selected features to a new feature class
            gp.CopyFeatures_management(end_lyr, tableName_sim,  "", "0", "0", "0")
    Last edited by lavpizzo; 06-12-2012 at 09:09 AM.

  11. #11
    Nobbir Ahmed

    Join Date
    Jun 2010
    Posts
    327
    Points
    124
    Answers Provided
    17


    0

    Default Re: Selecting Features by Location

    Which version of ArcGIS you are on?

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

    Code:
    try:
        gp.SelectLayerByLocation_management(tableName_e_lyr, "intersect", tableName_vec_lyr, "", "ADD_TO_SELECTION")
        print gp.GetMessages()
    except:
        print gp.GetMessages(2)

  12. #12
    larissa pizzolato
    Join Date
    Jun 2012
    Posts
    17
    Points
    0
    Answers Provided
    0


    0

    Default Re: Selecting Features by Location

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

  13. #13
    Mathew Coyle

    Join Date
    Feb 2011
    Posts
    1,369
    Points
    958
    Answers Provided
    150


    0
    This post is marked as the answer

    Default Re: Selecting Features by Location

    You are referencing layer files that were never created it looks like. MakeFeatureLayer creates a temporary layer in memory, not a layer file.
    Mathew Coyle, EADA10
    GIS Analyst
    Alberta-Pacific Forest Industries Inc.
    ArcGIS 10.2.1 Testing
    ArcGIS 10.1 SP1
    Windows 7 SP1 64-bit

  14. #14
    larissa pizzolato
    Join Date
    Jun 2012
    Posts
    17
    Points
    0
    Answers Provided
    0


    0

    Default Re: Selecting Features by Location

    Thanks Mathew!
    Last edited by lavpizzo; 06-13-2012 at 09:18 AM.

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts