AnsweredAssumed Answered

name is not defined for query

Question asked by helenak on May 15, 2012
Latest reply on May 18, 2012 by mdenil
System: ArcGIS 9.3


I tried to calculate the latitude of north and south limit of polygons specified as S in a shapefiles.
The specification of S is using query.
However, an error jumped,
saying "query = "\"%s\" = 'S'" % field.Name
NameError: name 'field' is not defined".

Please kindly advise modification and thank you.
##Script Name: latitude of north or south limit ##Description: Extract latitude of north and south boundary of B or NB range size ##Created By: Elaine Kuo ##Date: 12/05/2012   #Import standard library modules import arcgisscripting import os  #Create the Geoprocessor object gp = arcgisscripting.create(9.3)  #Set the input workspace #GP.workspace = sys.argv[1] #Set the workspace. gp.Workspace= "H:/temp/test1"  #Set the output workspace #outWorkspace = sys.argv[2] #Set the workspace. List all of the feature classes in the dataset outWorkspace= "H:/temp"   #Get a list of the featureclasses in the input folder fcs = gp.ListFeatureClasses()   # Loop through every item in the list that was just generated for fc in fcs:      # Break out the name, no path or extension, using the describe object.     desc = gp.describe(fc)     featureName =      # Add a field to this shapefile, of type LONG     gp.AddField (fc, "NorthLat", "double", 6,6)     gp.AddField (fc, "SouthLat", "double", 6,6)          # Make temporary featureclasses     query = "\"%s\" = 'S'" % field.Name     gp.Select_analysis(fc,"output.shp",query)      # get latitude of north and south limits     ext = gp.describe("output.shp").extent     NorthLat = ext.YMax     SouthLat = ext.YMin             gp.CalculateField_management("output.shp", "NorthLat",str(NorthLat))     gp.CalculateField_management("output.shp", "SouthLat",str(SouthLat))      # copy temporary shapefile to fc     gp.Select_analysis("output.shp",fc)          # clear memory of temporary shapefile     gp.Delete("output.shp")      gp.AddMessage(gp.GetMessages()) print gp.GetMessages()