I am running a select layer by attribute and location query on a feature layer of points made from a shapefile.
I have been stuck for hours on the wording of it and would be grateful if some one would tell me how to do it because I have looked and tried many variations to no avail and there are so many suggestions but none seem to fit.
I want the code to be
"CRIME_INDE" <= 0.02 AND "UNVERSITY" = 1
but I can't get the right syntax in this case beacuse all the components are variables. Please could anyone offer any suggestions, it's really urgent and preventing me from progressing and I'll be happy to post up the resuts that work.
Thanks scottaidh
# import system modules import arcpy, os, arcpy from arcpy import env arcpy.env.overwriteOutput = True
# get user supplied path, layers and fields path = arcpy.GetParameterAsText(0) # path is H:\working\Findsites.gdb cities = arcpy.GetParameterAsText(1) # cities Layer is cities Feature Layer cities.shp citiesL = "citiesL" crimeField = arcpy.GetParameterAsText(4) # crimeField is fieldname 'CRIME_INDE' SQL expression crimefieldindex = arcpy.GetParameterAsText(5) # crime index is CRIME_INDE and is a string 0.02 whereClause = "{0} = '{1}'".format(arcpy.AddFieldDelimiters(citiesL, crimeField), crimefieldindex) universityField = arcpy.GetParameterAsText(6) # universityField is fieldname 'UNIVERSITY' SQL expression universityfieldindex = arcpy.GetParameterAsText(7) # universityfieldindex is the UNIVERSITY field and is string integer 1 whereClause2 = "{0} = '{1}'".format(arcpy.AddFieldDelimiters(citiesL, universityField), universityfieldindex) outfile = arcpy.GetParameterAsText(15) # ootput
Thank you all very much for taking the time to reply.
The line that worked in the end was a Field Delimiter where clause
crimeField = arcpy.GetParameterAsText(4) # crimeField is fieldname 'CRIME_INDE' SQL expression crimeval = arcpy.GetParameterAsText(5) # crime index is CRIME_INDE and is a Double 0.02 whereClause = "{0} <= {1}".format(arcpy.AddFieldDelimiters(citiesL, crimeField), crimeval) [\CODE]
Previously, I had two extra ' single abbreviations around the where clause 0 and 1 which made the expression something like ""CRIME_INDE"" = "0.02" so watch out for them!