AnsweredAssumed Answered

interpreting   query = "\"%s\" = 'S'" % field.Name

Question asked by helenak on May 27, 2012
Latest reply on May 27, 2012 by lpinner
Hello

System: ArcGIS 9.3

I have two questions to interpret two sections of code.
(I forget why I used them :P)

1. query = "\"%s\" = 'S'" % field.Name
Please kindly explain what \"%s\" and % field.Name stand for in the code below.

2.     vt.AddRow(fc)
Please kindly explain why the code is necessary in the code below.

##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 workspace. gp.Workspace= "H:/temp_stage_2_3_polygon_limit_1984_no_R_O/P_Turdidae_22"  #Set the workspace. List all of the feature classes in the dataset outWorkspace= "H:/temp_stage_2_3_polygon_limit_1984_no_R_O"  #Get a list of the featureclasses in the input folder fcs = gp.ListFeatureClasses()  # Create a value table that will hold all of the input features to Merge. vt = gp.createobject("ValueTable")   # 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 = desc.name      # Add a field to this shapefile, of type LONG     gp.AddField (fc, "NorthLat", "double", 6,6)     gp.AddField (fc, "SouthLat", "double", 6,6)          # Populate the input value table with feature classes.     vt.AddRow(fc)          #   Get a list of the fields in the featureclass     fields = gp.ListFields(fc, "C*", "String")          # Loop through every item in the list that was just generated      for field in fields:          gp.toolbox = "Data Management"         gp.addMessage(type(field))          # Select records to be deleted (C*, i.e. C7658)         # Make temporary featureclasses         query = "\"%s\" = 'S'" % field.Name         gp.Select_analysis(fc,("outputS.shp"),query)          # get latitude of north and south limits         ext = gp.describe("outputS.shp").extent         NorthLat = ext.YMax         SouthLat = ext.YMin                 gp.CalculateField_management("outputS.shp", "NorthLat",str(NorthLat))         gp.CalculateField_management("outputS.shp", "SouthLat",str(SouthLat))       # Loop through every item in the list that was just generated      for field in fields:          gp.toolbox = "Data Management"         gp.addMessage(type(field))          # Select records to be deleted (C*, i.e. C7658)         # Make temporary featureclasses         query = "\"%s\" = 'W'" % field.Name         gp.Select_analysis(fc,("outputW.shp"),query)          # get latitude of north and south limits         ext = gp.describe("outputW.shp").extent         NorthLat = ext.YMax         SouthLat = ext.YMin                 gp.CalculateField_management("outputW.shp", "NorthLat",str(NorthLat))         gp.CalculateField_management("outputW.shp", "SouthLat",str(SouthLat))      #Validate the new feature class name for the output workspace.     OutFeatureClass = outWorkspace + os.sep + gp.ValidateTableName(fc,outWorkspace)          # Run the merge tool     gp.Merge_management("outputS.shp;outputW.shp",OutFeatureClass)       # delete the fields     gp.Toolbox = "Data Management"     gp.deletefield (fc, "NorthLat")     gp.deletefield (fc, "SouthLat")          # clear memory of temporary shapefiles     gp.Delete("outputS.shp")     gp.Delete("outputW.shp")   gp.AddMessage(gp.GetMessages()) print gp.GetMessages()       

Outcomes