Step1 to any ESRI geoprocessing analysis: Copy all the data to a local hard drive (perferably in .shp or FGDB format), then proceed with the analysis (i.e. Don't use data directly from a network connection!).
#blah blah else: #Process: Try to select the arcs message = "Selecting features. Please wait..."; showPyMessage() selectionOidList = list(currentSearchOidList) selectionOidList.sort() gp.SelectLayerByAttribute_management(inLayer, "NEW_SELECTION", oidFieldName + " in (" + str(selectionOidList)[1:-1] + ")") #blah blah #blah blah #Process: Proceed with getting the selected feature count... if data source is in SDE this can take a while! selectedFeatureCount = int(gp.GetCount_management(inLayer).getoutput(0)) if selectedFeatureCount > 0: message = "Selected " + str(selectedFeatureCount) + " features..."; showPyMessage() elif sdeDataSourceFlag == True and selectedFeatureCount == 0 and len(selectionOidList) > 0: #Process: Build an SDE look up table to handle the large selection! message = "Building ArcSDE selection table. Please wait..."; showPyMessage() lookupTblName = "SEL_OID_" + string.lower(os.environ.get("USERNAME")) + "_" + time.strftime('%Y%m%d%H%M%S') gp.CreateTable_management("in_memory", lookupTblName, "", "") gp.AddField_management("in_memory\\" + lookupTblName, "SEL_OID", "LONG") insertRows = gp.insertcursor("in_memory\\" + lookupTblName) for currentSearchOid in currentSearchOidList: insertRow = insertRows.newrow() insertRow.SEL_OID = currentSearchOid insertRows.insertrow(insertRow) del insertRow del insertRows parentWorkspace = parentFC[0:-len(parentFC.split("\\")[-1]) - 1] #if stream dataset (aka "the parent" ) is in SDE put the lut there too lookupTblPath = parentWorkspace + "\\" + lookupTblName gp.CopyRows_management("in_memory\\" + lookupTblName, lookupTblPath, "") gp.Delete_management("in_memory\\" + lookupTblName, "") gp.ChangePrivileges_management(lookupTblPath, "public", "GRANT", "GRANT") gp.SelectLayerByAttribute_management(inLayer, "NEW_SELECTION", oidFieldName + " in (SELECT SEL_OID FROM " + lookupTblName + ")") gp.Delete_management(lookupTblPath, "") message = "Selected " + str(count2) + " features..."; showPyWarning() else: message = "ERROR: No features were selected! Exiting script..."; showPyError(); sys.exit() del currentSearchOidList message = "REFRESH THE ARCMAP VIEW TO DISPLAY NEWLY SELECTED FEATURES!"; showPyWarning() #*****************GEOPROCESSING STUFF ENDS HERE****************************** #Indicates that the script is complete message = sys.argv[0] + " is all done!"; showPyMessage() except: message = "Error in script! Consult log file " + logFile + " for details..."; showPyError() message = "\n*** LAST GEOPROCESSOR MESSAGE (may not be source of the error)***"; print >> open(logFile, 'a'), str(time.ctime()) + " - " + message print >> open(logFile, 'a'), gp.GetMessages() message = "PYTHON TRACEBACK INFO: " + traceback.format_tb(sys.exc_info()[2])[0]; print >> open(logFile, 'a'), str(time.ctime()) + " - " + message message = "PYTHON ERROR INFO: " + str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"; print >> open(logFile, 'a'), str(time.ctime()) + " - " + message message = "\n*** PYTHON LOCAL VARIABLE LIST ***"; print >> open(logFile, 'a'), str(time.ctime()) + " - " + message #don't print this mess to ArcToolbox (just the logFile)! variableCounter = 0 while variableCounter < len(locals()): message = str(list(locals())[variableCounter]) + " = " + str(locals()[list(locals())[variableCounter]]); print >> open(logFile, 'a'), str(time.ctime()) + " - " + message #don't print this mess to ArcToolbox (just the logFile)! variableCounter = variableCounter + 1]
...tuple list instead of a list list...
oidList = [6,4,2,6,8,1] oidList.sort() gp.MakeFeatureLayer_managment(fc, "fl", "OBJECTID in (" + str(oidList)[1:-1] + ")")
oidList = [6,4,2,6,8,1] oidList.sort() gp.MakeFeatureLayer_managment(fc, "fl", "OBJECTID in " + str(tuple(oidList)))
oidList = [1,2,3,4,5,6] gp.SelectLayerByAttribute(layername, "ADD_TO_SELECTION", "OBJECTID in (" + str(oidList)[1:-1] + ")")
gp.MakeFeatureLayer_managment(fc, "fl", "OBJECTID in (" + str(oidList)[1:-1] + ")") gp.Clip_analysis("fl", cookieCutterFC, blah, blah)
query = 'OID in '+OIDlist gp.SelectByAttribute(layername, "ADD_TO_SELECTION", query)
query = 'OID in '+str(OIDlist) gp.SelectByAttribute(layername, "NEW_SELECTION", query)
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.