Page Title

Der Wiki wird derzeit überarbeitet: neue URL, neues Design, neue Inhalte!

Benutzer-Werkzeuge

Webseiten-Werkzeuge


mikeurban:anleitungen:import_anschlussleitungen_arcgis_desktop_advanced_pythoncode

Der folgende Abschnitt gehört zur Seite Anschlussleitungen berücksichtigen:

ArcMap Python-Fenster (ArcGIS Desktop Advanced)

# CODE
 
 
# Umgebungsvariablen
# ******************
Pfad_Workspace = <VOLLSTÄNDIGER PFAD ZUM TEMPORÄREN VERZEICHNIS>
Bufferdist = 0.1
Searchdist = 0.2
 
 
# Vorbereitende Schritte
# **********************
import arcpy
arcpy.env.workspace = Pfad_Workspace
arcpy.env.overwriteOutput = True
arcpy.ImportToolbox(Pfad_ET-Toolbox)
 
MXD = arcpy.mapping.MapDocument("Current")
LYRhausanschluss = arcpy.mapping.ListLayers(MXD,"Hausanschluss")[0]
STRINGhausanschluss = LYRhausanschluss.datasetName + ".Zielknoten"
 
 
# Erstellung eines Buffers um die Anschlussleitungen
# **************************************************
arcpy.Buffer_analysis("Anschlussleitung","AnschlussleitungBuffer1",Bufferdist,"FULL","ROUND","ALL","","GEODESIC") 
arcpy.MultipartToSinglepart_management("AnschlussleitungBuffer1","AnschlussleitungBuffer2")
arcpy.AddField_management("AnschlussleitungBuffer2","ALID","LONG")
 
codeblock = """rec=0
def autoIncrement1():  
  global rec
  pStart = 1
  pInterval = 1
  if (rec == 0):
    rec = pStart
  else:
    rec = rec + pInterval
  return rec"""
expression = "autoIncrement1()"
 
arcpy.CalculateField_management("AnschlussleitungBuffer2","ALID",expression,"PYTHON",codeblock)
 
 
# Hausanschlüsse werden bearbeitet
# ********************************
arcpy.AddField_management("Hausanschluss","tempHAID","LONG")
arcpy.CalculateField_management("Hausanschluss","tempHAID",expression,"PYTHON",codeblock)
arcpy.SpatialJoin_analysis("Hausanschluss","AnschlussleitungBuffer2","Hausanschluss1","JOIN_ONE_TO_ONE","KEEP_ALL","","COMPLETELY_WITHIN")
 
 
# Anschlussleitungen werden bearbeitet
# ************************************
arcpy.FeatureVerticesToPoints_management("Anschlussleitung","Anschlussleitung2Punkte","BOTH_ENDS")
arcpy.SpatialJoin_analysis("Anschlussleitung2Punkte","AnschlussleitungBuffer2","Anschlussleitung2Punkte2","JOIN_ONE_TO_ONE","KEEP_ALL","","COMPLETELY_WITHIN")
 
arcpy.CalculateField_management("mw_Pipe","Coeff3",0)
arcpy.CalculateField_management("mw_Pipe","Coeff4",1)
arcpy.CreateRoutes_lr("mw_Pipe","MUID","mw_Pipe_Routen","TWO_FIELDS","Coeff3","Coeff4","UPPER_LEFT",1,0,"IGNORE","INDEX")
arcpy.LocateFeaturesAlongRoutes_lr("Anschlussleitung2Punkte2","mw_Pipe_Routen","MUID",Searchdist,"ALPosition.dbf","RID POINT MEAS","FIRST","DISTANCE","ZERO","FIELDS")
arcpy.AddField_management("ALPosition","Zielknoten","TEXT","","",40)
arcpy.AddJoin_management("ALPosition","RID","mw_Pipe","MUID","KEEP_ALL") # RID kommt von den Routen, ist die MUID
arcpy.SelectLayerByAttribute_management("ALPosition","NEW_SELECTION",'MEAS <=0.5')
arcpy.CalculateField_management("ALPosition","ALPosition.Zielknoten","!mw_Pipe.FROMNODE!","PYTHON")
arcpy.SelectLayerByAttribute_management("ALPosition","NEW_SELECTION",'MEAS >0.5')
arcpy.CalculateField_management("ALPosition","ALPosition.Zielknoten","!mw_Pipe.TONODE!","PYTHON")
arcpy.SelectLayerByAttribute_management("ALPosition","CLEAR_SELECTION")
arcpy.RemoveJoin_management("ALPosition","mw_Pipe")
 
arcpy.AddField_management("Hausanschluss1","Zielknoten","TEXT","","",40)
arcpy.AddJoin_management("Hausanschluss1","ALID","ALPosition","ALID","KEEP_ALL")
arcpy.SelectLayerByAttribute_management("Hausanschluss1","NEW_SELECTION","ALPosition.Zielknoten IS NOT NULL")
arcpy.CalculateField_management("Hausanschluss1","Hausanschluss1.Zielknoten","!ALPosition.Zielknoten!","PYTHON")
arcpy.SelectLayerByAttribute_management("Hausanschluss1","CLEAR_SELECTION")
arcpy.RemoveJoin_management("Hausanschluss1","ALPosition")
 
arcpy.AddField_management("Hausanschluss","Zielknoten","TEXT","","",40)
arcpy.AddJoin_management("Hausanschluss","tempHAID","Hausanschluss1","tempHAID","KEEP_ALL")
arcpy.CalculateField_management("Hausanschluss",STRINGhausanschluss,"!Hausanschluss1.Zielknoten!","PYTHON")
arcpy.RemoveJoin_management("Hausanschluss","Hausanschluss1")
arcpy.DeleteField_management("Hausanschluss","tempHAID")
mikeurban/anleitungen/import_anschlussleitungen_arcgis_desktop_advanced_pythoncode.txt · Zuletzt geändert: 2018/10/03 09:40 von katharina