import arcpy arcpy.env.overwriteOutput=True arcpy.env.workspace = "D:\FacID_Python\SO_CSS_Master_9x_GDB.gdb" sinkFeatures = "D:\\FacID_Python\\SO_CSS_Master_9x_GDB.gdb\\SO_CSS_Master\\SManhole_Master" dCatchBasin = "D:\\FacID_Python\\SO_CSS_Master_9x_GDB.gdb\\SO_CSS_Master\\DCatchBasin_Master" geometricNetwork = "D:\\FacID_Python\\SO_CSS_Master_9x_GDB.gdb\\SO_CSS_Master\\SO_CSS_Master_Net" mxd = arcpy.mapping.MapDocument("D:\FacID_Python\Working.mxd") sinkList = [] rows = arcpy.SearchCursor(sinkFeatures) row = rows.next() while row: featureID = row.OBJECTID if featureID not in sinkList: sinkList.append(featureID) row = rows.next() del rows print sinkList sinkCount = len(sinkList) for each in range(sinkCount): print "%s of %s" % (each +1, sinkCount) sinkWhere = '"OBJECTID" = %s' % sinkList[each] if arcpy.Exists("TempSinkLayer"): arcpy.Delete_management("TempSinkLayer") arcpy.MakeFeatureLayer_management(sinkFeatures, "TempSinkLayer", sinkWhere) cursor = arcpy.SearchCursor("TempSinkLayer") sink = cursor.next() while sink: facID = sink.getValue("FACILITYID") print facID sink = cursor.next() del sink del cursor try: outGroupLayer = str("Trace" + facID) arcpy.SetFlowDirection_management(geometricNetwork, "WITH_DIGITIZED_DIRECTION") arcpy.TraceGeometricNetwork_management(geometricNetwork, outGroupLayer, "TempSinkLayer", "TRACE_UPSTREAM", "", "", "", "", "", "", "" ,"", "", "", "", "", "", "") except: print "Can't trace" try: dCatchLayer = str(facID + "dCatch") arcpy.SelectData_management(outGroupLayer, "DCatchBasin_Master") arcpy.MakeFeatureLayer_management("DCatchBasin_Master", dCatchLayer) result = int(arcpy.GetCount_management(dCatchLayer).getOutput(0)) print result dCatchs = arcpy.UpdateCursor(dCatchLayer) dCatch = dCatchs.next() fieldID = "DnComboFacID" while dCatch: dCatch.setValue(fieldID, facID) dCatchs.updateRow(dCatch) dCatch = dCatchs.next() del dCatch del dCatchs arcpy.Delete_management(dCatchLayer) arcpy.Delete_management("DCatchBasin_Master") arcpy.SelectLayerByAttribute_management("DCatchBasin_Master", "CLEAR_SELECTION") ##for df in arcpy.mapping.ListDataFrames(mxd): ##for lyr in arcpy.mapping.ListLayers(mxd, "", df): ##if lyr.name == "Trace" + facID: ##arcpy.mapping.RemoveLayer(df, lyr) ##else: ##pass except: print "not working"
import arcpy arcpy.env.overwriteOutput=True arcpy.env.workspace = "D:\FacID_Python\SO_CSS_Master_9x_GDB.gdb" sinkFeatures = "D:\\FacID_Python\\SO_CSS_Master_9x_GDB.gdb\\SO_CSS_Master\\Export_Output" dCatchBasin = "D:\\FacID_Python\\SO_CSS_Master_9x_GDB.gdb\\SO_CSS_Master\\DCatchBasin_Master" geometricNetwork = "D:\\FacID_Python\\SO_CSS_Master_9x_GDB.gdb\\SO_CSS_Master\\SO_CSS_Master_Net" mxd = arcpy.mapping.MapDocument("D:\FacID_Python\Working.mxd") sinkList = [] rows = arcpy.SearchCursor(sinkFeatures) row = rows.next() while row: featureID = row.OBJECTID if featureID not in sinkList: sinkList.append(featureID) row = rows.next() del rows print sinkList sinkCount = len(sinkList) for each in range(sinkCount): print "%s of %s" % (each +1, sinkCount) sinkWhere = '"OBJECTID" = %s' % sinkList[each] if arcpy.Exists("TempSinkLayer"): arcpy.Delete_management("TempSinkLayer") arcpy.MakeFeatureLayer_management(sinkFeatures, "TempSinkLayer", sinkWhere) cursor = arcpy.SearchCursor("TempSinkLayer") sink = cursor.next() while sink: facID = sink.getValue("FACILITYID") print facID sink = cursor.next() del sink del cursor try: outGroupLayer = "Trace" + facID arcpy.SetFlowDirection_management(geometricNetwork, "WITH_DIGITIZED_DIRECTION") arcpy.TraceGeometricNetwork_management(geometricNetwork, outGroupLayer, "TempSinkLayer", "TRACE_UPSTREAM", "", "", "", "", "", "", "" ,"", "", "", "", "", "", "") except: print "Can't trace" try: dCatchLayer = facID + "dCatch" arcpy.SelectData_management(outGroupLayer, "DCatchBasin_Master") arcpy.MakeFeatureLayer_management("DCatchBasin_Master", dCatchLayer) result = int(arcpy.GetCount_management(dCatchLayer).getOutput(0)) print result except: print "can't make feature layer or access selection" try: dCatchs = arcpy.UpdateCursor(dCatchLayer) dCatch = dCatchs.next() fieldID = "DnComboFacID" while dCatch: dCatch.setValue(fieldID, facID) dCatchs.updateRow(dCatch) dCatch = dCatchs.next() del dCatch del dCatchs except: print "can't update rows" try: arcpy.Delete_management(dCatchLayer) except: print "can't delete the feature layer" try: arcpy.SelectLayerByAttribute_management("DCatchBasin_Master", "CLEAR_SELECTION") for df in arcpy.mapping.ListDataFrames(mxd): for lyr in arcpy.mapping.ListLayers(mxd, "", df): if lyr.name == "Trace" + facID: arcpy.mapping.RemoveLayer(df, lyr) else: pass except: print "can't delete the group layer"
# make a list of the feature IDs theSource = r"C:\some.gdb\FeatureClass" cur = arcpy.SearchCursor(theSource) theIdList = [] for row in cur: theID = row.OBJECTID if theID not in theIdList: theIdList.append(theID) del cur # count the entries in the list idCount = len(idList) for each in range(idCount): print "%s of %s" % (each + 1, idCount) # build a feature where clause segWhere = '"OBJECTID" = %s' % idList[each] # make a layer of each feature in fc if arcpy.Exists("MyTempLayer"): arcpy.Delete_management(("MyTempLayer") arcpy.MakeFeatureLayer_management(theSource, "MyTempLayer", segWhere) ### Do stuff to that feature here....
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.