# Import system modules import sys, string, os, arcgisscripting # Create the Geoprocessor object gp = arcgisscripting.create(9.3) # Load required toolboxes... gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx") try: gp.OverWriteOutput = True except: gp.AddMessage("Unable to set the OverWriteOutpu to 1") # Script arguments... ##inTable = gp.GetParameterAsText(0) ##inFC = gp.GetParameterAsText(1) ##String = gp.GetParameterAsText(2) ##SchoolLevel = gp.GetParameterAsText(3) ##numSchools = gp.GetParameter(4) ## ###gp.SetParameterAsText(5,"PS_lyr") ## ##SchoolLevel = "[" + SchoolLevel + "]" inTable = "D:/ORED PROJECTS/GAMS to ArcMap/ES_05_UNROUNDED.csv" inFC = "D:/ORED PROJECTS/GAMS to ArcMap/ScenarioTemplate_1011.shp" String = "ES_06" SchoolLevel = "[ES_0910]" numSchools = 11 fieldsListFC = gp.ListFields(inFC) #theFields = gp.ListFields(inFC) # Process: Add Field... gp.AddField_management(inFC, String, "TEXT", "", "", "30", "", "NON_NULLABLE", "NON_REQUIRED", "") descTable = gp.Describe(inTable) FullTName = descTable.CatalogPath theTPath = (os.path.split(FullTName)[0]) theTName = (os.path.split(FullTName)[1]) descFC = gp.Describe(inFC) FullFCName = descFC.CatalogPath FullFCNameOut = FullFCName.replace(".shp", "_copy.shp") theFCPath = (os.path.split(FullFCName)[0]) theFCName = (os.path.split(FullFCName)[1]) outFC = theFCName.replace(".shp", "_copy.shp") gp.TableToDbase_conversion(inTable,theTPath) outTable = inTable.replace("csv", "dbf") # Process: Calculate Field... gp.CalculateField_management(inFC, String, SchoolLevel, "VB", "") gp.MakeFeatureLayer_management(inFC, "PS_lyr", "#", "#", "#") gp.AddJoin_management("PS_lyr", "segment", outTable, "SEG", "KEEP_ALL") gp.FeatureClassToFeatureClass_conversion("PS_lyr", theFCPath, outFC) def zeros(*shape): if len(shape) == 0: return 0 car = shape[0] cdr = shape[1:] return [zeros(*cdr) for i in range(car)] # Determine the number of fields in the database after the GAMS # output has been joined to the Scenario Template shapefile theJoinFields = gp.ListFields(FullFCNameOut) theFields = gp.ListFields(inFC) theTableFields = gp.ListFields(outTable) lengthFC = len(theFields) ##lengthTable = len(fieldsListTable) lengthJoin = len(theJoinFields) fieldsJoin = zeros(lengthJoin,1) # Create an array to hold the planning segment values for each # of the schools Elem = zeros(numSchools,1) for i in range(0,numSchools): Elem = theTableFields[i + 2].name.encode('ASCII') schools = zeros(numSchools,1) M = zeros(numSchools,2) rows = gp.UpdateCursor(outFC) row = rows.next() try: while row: for i in range(0,numSchools): schools = row.GetValue(Elem) M[1] = schools M[0] = Elem M.sort(lambda x, y: cmp(x[1], y[1])) M.reverse() if "SEG" > 0: school = M[0][0] row.SetValue(String, M[0][0]) gp.AddMessage("You made it through the if statement") rows.UpdateRow(row) row = rows.next() except: gp.AddError("Failed to set the value of new scenario field to new school assignment") for i in range(0,numSchools): #gp.deletefield(FullFCNameOut, theFields[lengthFC + 1 + i]) gp.DeleteField_management(FullFCNameOut, "ES_05_UNRO; ES_05_UN_1") ##for i in range(0,numSchools): ## gp.AddJoin_management("PS_lyr", String, inTable2, "NAME", "KEEP_ALL") ## ## if "NAME" <> "NULL": ## gp.CalculateField_management("PS_lyr", String, "NAME", "VB", "") ## ##gp.RemoveJoin(inFC, inTABLE2) ## ##gp.FeatureToPolygon("PS_lyr", inFC, "ATTRIBUTES", "") del gp
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.