POST
|
Hi, I am trying to use arcpy to run a select by location and export the resulting selection (intersect) as a new feature class. I have set my workspace to the gdb containing the featureclasses I want to select by, and the features I want to select are a tile index feature class called 'tile_index'. The code will run but doesn't have any output. Any help would be great. Thanks! # Import arcpy and set path to data import arcpy arcpy . env . workspace = r "C:\folder\Data.gdb\" # Get the list of the featureclasses to process fc_tables = arcpy . ListFeatureClasses ( ) for fc in fc_tables : arcpy . SelectLayerByLocation_management ( 'fc' , 'intersect' , 'tile_index' ) arcpy . CopyFeatures_management ( fc_tables , r "C:\Data.gdb\%Name%_selection" )
... View more
04-05-2020
08:06 PM
|
0
|
1
|
96
|
POST
|
That did it! Yes, Criteria_1 etc are existing fields. The format string did the trick, thank you so much for your help. I forgot about just using .format instead of the code block, I need to use python more consistently. Thanks again for your help. final code is below #import system modules import arcpy import os #set paramaters - parameters are weights inFC = arcpy . GetParameter ( 0 ) #fieldName_FinalScore = arcpy.ListFields(inFC) Parameter_1 = arcpy . GetParameter ( 1 ) Parameter_2 = arcpy . GetParameter ( 2 ) #deleted set to float, no need as parameter comes in as double/float, via script properties #field name fieldName_FinalScore = "FinalScore" #lower box expression_FinalScore = """!Criteria_1! * {} + !Criteria_2! * {}""" . format ( str ( Parameter_1 ) , str ( Parameter_2 ) ) #deleted code block #Execute CalculateField arcpy . CalculateField_management ( inFC , fieldName_FinalScore , expression_FinalScore , "PYTHON_9.3" )
... View more
10-02-2019
06:52 AM
|
1
|
2
|
77
|
POST
|
Update below original thread, thank you so much for your reply!
... View more
10-01-2019
10:59 AM
|
0
|
0
|
77
|
POST
|
Thank you for all the replies, I tried a few things that helped some, but not there. A new code is below that includes... -Added return FinalScore (originally I had a syntax error, this seemed to solve that). Notes: -I'm not sure if the Parameter to float is needed, I read get parameter comes in as an object, does that mean a blob? That's why converted it (still investigating) . -The error says 'not defined', so I assume its a scope issue. I'm trying to get the structure right for arcpy field calc. I think that's where my error is (still investigating) #Geonet V2 #import system modules import arcpy import os #set paramaters - parameters are weights inFC = arcpy . GetParameter ( 0 ) #fieldName_FinalScore = arcpy.ListFields(inFC) Parameter_1_p = arcpy . GetParameter ( 1 ) Parameter_2_p = arcpy . GetParameter ( 2 ) #set to float, not sure if GetParameter comes in as float, double or what. I read it comes in as an object (blob?) Parameter_1 = float ( Parameter_1_p ) Parameter_2 = float ( Parameter_2_p ) #field name fieldName_FinalScore = "FinalScore" #lower box expression_FinalScore = "Value(!Criteria_1!,!Criteria_2!,Parameter_1,Parameter_2)" #code block upper codeblock_FinalScore = """def Value( Criteria_1, Criteria_2, Parameter_1, Parameter_2): FinalScore = Criteria_1 * Parameter_1 + Criteria_2 * Parameter_2 return FinalScore""" #Execute CalculateField arcpy . CalculateField_management ( inFC , fieldName_FinalScore , expression_FinalScore , "PYTHON_9.3" , codeblock_FinalScore ) Error: Traceback ( most recent call last ) : File "W:\Citrix\35000s\35217\GIS\ExamplePropData\Rank\GeoNet.py" , line 29 , in < module > arcpy . CalculateField_management ( inFC , fieldName_FinalScore , expression_FinalScore , "PYTHON_9.3" , codeblock_FinalScore ) File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\management.py" , line 3661 , in CalculateField raise e ExecuteError : ERROR 000539 : Error running expression : Value ( 5.0 , 2.0 , Parameter_1 , Parameter_2 ) Traceback ( most recent call last ) : File "<expression>" , line 1 , in < module > NameError : name 'Parameter_1' is not defined Failed to execute ( CalculateField ) . Failed to execute ( RankWeight2 ) . Failed at Tue Oct 01 12 : 51 : 12 2019 ( Elapsed Time : 0.33 seconds )
... View more
10-01-2019
10:58 AM
|
0
|
4
|
77
|
POST
|
Thank you for the reply and information, updated to make code more readable
... View more
10-01-2019
09:31 AM
|
1
|
0
|
77
|
POST
|
I am having issues getting a field calc script in arcpy to run. It's probably my parameters, but I can't seem to find the error. Please see below. I am 'ranking', one shapefile based on multiple columns (with weights applied). My goal is to import it as a script into a toolbox so a user doesn't have to use arcpy. Thanks in advance! Edit: format, spelling #import system modules import arcpy import os #set paramaters - parameters are weights inFC = arcpy.GetParameter(0) #fieldName_FinalScore = arcpy.ListFields(inFC) Parameter_1_p = arcpy.GetParameter(1) Parameter_2_p = arcpy.GetParameter(2) #convert GetParamter to floats, I thought Parameter_1 = float(Parameter_1_p) Parameter_2 = float(Parameter_2_p) #field name fieldName_FinalScore = "FinalScore" #lower box expression_FinalScore = "Value(!Criteria1!,!Criteria2!)" #code block upper codeblock_FinalScore = """def Value( Criteria_1, Criteria_2): FinalScore = !Criteria_1! * Parameter_1 + !Criteria_2! * Parameter_2""" #Execute CalculateField arcpy.CalculateField_management(inFC, fieldName_FinalScore, expression_FinalScore, "PYTHON_9.3", codeblock_FinalScore)
... View more
10-01-2019
07:36 AM
|
0
|
10
|
444
|
Online Status |
Offline
|
Date Last Visited |
4 weeks ago
|