Select By Location in Script Errors

623
4
Jump to solution
05-30-2014 07:29 AM
NoahHuntington
Occasional Contributor
I have no idea why I can run this tool from tool dialogue but not from the following script?

Error Message: Failed to execute. Parameters are not valid. ERROR 000368: Invalid input data.
Failed to execute (SelectLayerByLocation).


import arcpy import os from arcpy import env env.overwriteOutput = 1 ''' lines = arcpy.GetParameterAsText(0) results = arcpy.GetParameterAsText(1) '''  lines = 'G:/Xcel/Route Tool/Southwest/Scratch.gdb/lines_clip' results = 'G:/Xcel/Route Tool/Southwest/Results.gdb'  line_string = '"' + "'" + lines + "'" + " #" + '"'  env.workspace = results  def main():      points = results + '\\pts'     # Process: Find all stream crossings (points)     #arcpy.Intersect_analysis(lines,'G:\Xcel\Route Tool\Southwest\Results.gdb\pts',"ONLY_FID","#","POINT")      in_features = "'" + lines + "'" + " #"      arcpy.Intersect_analysis(in_features,\     out_feature_class="G:/Xcel/Route Tool/Southwest/Scratch.gdb/lines_clip_Intersect",\     join_attributes="ONLY_FID",cluster_tolerance="#",output_type="POINT")      # Adds x and y field to points     pts_geometry = arcpy.AddXY_management("G:/Xcel/Route Tool/Southwest/Scratch.gdb/lines_clip_Intersect")      # Dissolves duplicate points     arcpy.Dissolve_management(pts_geometry,"pts_dissolve","POINT_X;POINT_Y","#","SINGLE_PART","DISSOLVE_LINES")      # Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script     # The following inputs are layers or table views: "pts_dissolve", "LCP_A"     arcpy.SelectLayerByLocation_management("pts_dissolve","INTERSECT","LCP_A","400 Feet","ADD_TO_SELECTION")
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
IanMurray
Frequent Contributor
I know right?

I was having the same issue with gdb feature classes in doing something similar on this thread

I had to end up running my script in the interactive python window in ArcGIS on the shapefiles I brought into my map that I made converted from gdb feature classes.

Perhaps making a feature layer first from your feature classes then running the select by location tool would work better?

View solution in original post

0 Kudos
4 Replies
IanMurray
Frequent Contributor
I know right?

I was having the same issue with gdb feature classes in doing something similar on this thread

I had to end up running my script in the interactive python window in ArcGIS on the shapefiles I brought into my map that I made converted from gdb feature classes.

Perhaps making a feature layer first from your feature classes then running the select by location tool would work better?
0 Kudos
BenSciance
New Contributor II
pts_dissolve has to be a feature layer
NoahHuntington
Occasional Contributor
Making a feature layer before selection corrected my issue. Thank you both! I would probably save a lot of time by reading the resources first.  Glad to know I wasn't the only one out there making this mistake. Lol.
0 Kudos
T__WayneWhitley
Frequent Contributor
@ Ian, I think I solved your gdb quandary...please see your other thread....hope I explained to your satisfaction.

To clarify here, the issue is not the same, although you may argue it could be somewhat related.  The issue here raised is 'invalid input' (000368)....and your issues raised are 'invalid parameters' and 'in_features, parameter cannot be set' (000622 and 000628) - I think one tripped the other.

Oh, by the way, I made an error in the earlier script anyway - and I think your suspicions were well-founded about the lock...I'm still not fully satisfied I understand it, but the workaround is sound.

http://forums.arcgis.com/threads/111220-Error-on-Make-Feature-Layer-for-looping-over-selected-attrib...


Wayne
0 Kudos