You combine whereClause3 and whereClause4 with the AND operator.
As gm70560 wrote, the variables workforceField, workforceindex are not defined. That's why, first you have to define them. I guess workforceindex is a double or at least a number datatype like farmfieldindex. So you have to Change:
whereClause3 = "\"%s\" = '%s'" % (workforceField, workforceindex)
to:
whereClause3 = "\"%s\" = %s" % (workforceField, workforceindex)
The whereClause4 is not defined (commented out). You have to change
whereClause = "\"%s\" = '%s'" % (farmField, farmfieldindex)
to:
whereClause4 = "\"%s\" = %s" % (farmField, farmfieldindex)
Is that right? (I removed the single quotes for the farmfieldindex)
Another reason for getting an error should be the following:
whereClause3 + "AND" + whereClause4
Is the same like: "\"%s\" = %s" + "AND" + "\"%s\" = %s"
Is the same like: "\"%s\" = %sAND\"%s\" = %s"
Thus, you have no blank between the value (workforceindex) of the first part of the where clause and the AND Operator. Change the Select Layer by Attribute Function to the following and it should work:
arcpy.SelectLayerByAttribute_management(countiesL, "NEW_SELECTION", whereClause3 + " AND " + whereClause4)
If it still not working check the delimiters in the where clause (have a look at the AddFieldDelimiters function)
You set a workspace, so any outputs from the script will default to that location unless you explicitly put them somewhere else. Create a folder for the outputs, then write your output rasters to that folder.
import arcpy
import os
workspace = "D:\Jiawei default download"
feature_classes = []
outputFolder = r'c:\outputfolder'
walk = arcpy.da.Walk(workspace, datatype="FeatureClass", type="Polygon")
for dirpath, dirnames, filenames in walk:
if "Subbasin" in filenames:
filenames.remove('Subbasin')
for filename in filenames:
feature_classes.append(os.path.join(dirpath, filename))
print feature_classes
for item in feature_classes[98:]:
inFeatures = item
valField = "wtdepaprjunmin"
outRaster = outputFolder+item+"_r"
print "processing "+item
# Execute PolygonToRaster
arcpy.PolygonToRaster_conversion(inFeatures, valField, outRaster)
Best Answer
I think this is what you're asking.
You have a tool written in python and want to supply the output workspace on the command line or as a parameter as a tool. First you tell the tool to expect something:
and to pick it up in python use sys.argv[], the first augment is
sys.argv[1]
, the second issys.argv[2]
and so on.sys.argv[0]
is the full path to execute the script file, sometimes useful.so your output workspace:
or you can set a variable
output = sys.argv[1]
and use it likeOutShp = output + "\\OutFile.shp"
orOutShp = "%s\\OutFile.shp" % output