Demo entry 1075386

gauffeny

   

Submitted by anonymous on Jan 14, 2015 at 15:39
Language: Python. Code size: 4.6 kB.

import arcpy
import os
##funcion
# chergement d'un dictionnaire dans un domaine
def dicToDomain(wksp,domain,dico,descripDomain=" ",domain_type="TEXT"):
    arcpy.CreateDomain_management(wksp,domain,descripDomain,domain_type)
    for code in dico.keys():
        arcpy.AddCodedValueToDomain_management(wksp,domain,code,dico[code])

# fonction faciltant la tansformation de d un polygon en fonction de son numero de layer
def extractPolygonLayerToFc(inwksp,layer,dicolayer,outputFc):
    arcpy.env.workspace= inwksp
    fcPolygon =  [fc for fc in arcpy.ListFeatureClasses() if fc.split(".")[2] == "ERDF_polygon"][0]
    nameLayer = "layer_"+layer
    arcpy.MakeFeatureLayer_management(fcPolygon,nameLayer)
    arcpy.SelectLayerByAttribute_management(nameLayer,"NEW_SELECTION","layer = '"+layer+"'")
    arcpy.CopyFeatures_management(nameLayer,outputFc)
    arcpy.AddField_management(outputFc,"type_tension",'TEXT',"","","","","","","TYPE_TENSION")
    arcpy.CalculateField_management(outputFc,"type_tension","'"+dicolayer[layer][1]+"'","PYTHON")
    arcpy.DeleteField_management(outputFc,"layer")    

# fonction faciltant la tansformation de d un ployline en fonction de son numero de layer
def extractPolylineLayerToFc(polylineFC,layer,dicolayer,outputFc):
    nameLayer = "layer_"+layer
    arcpy.MakeFeatureLayer_management(polylineFC,nameLayer)
    arcpy.SelectLayerByAttribute_management(nameLayer,"NEW_SELECTION","layer = '"+layer+"'")
    arcpy.AddField_management(nameLayer,"type_tension","TEXT","","","","","","","TYPE_TENSION")
    arcpy.AddField_management(nameLayer,"type_fil","TEXT","","","","","","","TYPE_FIL")
    arcpy.CalculateField_management(nameLayer,"type_tension","'"+dicolayer[layer][0]+"'","PYTHON")
    arcpy.CalculateField_management(nameLayer,"type_fil","'"+dicolayer[layer][1]+"'","PYTHON")
    arcpy.Append_management(nameLayer,outputFc,"NO_TEST")
    arcpy.SelectLayerByAttribute_management(nameLayer,"CLEAR_SELECTION")

## variable d outil

gdbInput = arcpy.GetParameterAsText(0)
pathDirGdbOuput = arcpy.GetParameterAsText(1)


## varible de script

gdbOutputName = "WVS_ERDF.gdb"
pathGdbOutput = os.path.join(pathDirGdbOuput,gdbOutputName)

dico_TYPE_TENSION = {'HTA':'Haute-Tension', 'HTA-BT':'Haute-Tension Basse-Tension', 'BT':'Basse-Tension', 'HTA ABAN':'Haute tension abandonne'}
dico_TYPE_FIL = {'AERIEN':'Aerien', 'SOUTERRAIN':'Souterrain', 'TORSADE':'Torsade',}

dicoPolygon = {'46':('POSTE_SOURCE','HTA'),'21':('POSTE_DISTRIBUTION','HTA-BT'),'36':('POSTE_CLIENT','HTA'),'41':('POSTE_REPARTITION','HTA-BT')}
dicoPolyline = {'1':('BT','AERIEN'),'2':('BT','SOUTERRAIN'),'3':('BT','TORSADE'),'31':('HTA','AERIEN'),'32':('HTA','SOUTERRAIN')}

outputFcJonction = os.path.join(pathGdbOutput,'JONCTION')

sr93cc48 = arcpy.SpatialReference()
sr93cc48.factoryCode = 3948
sr93cc48.create()

arcpy.env.overwriteOutput = True
##traitement


arcpy.CreateFileGDB_management(pathDirGdbOuput,gdbOutputName)
dicToDomain(pathGdbOutput,"TYPE_TENSION",dico_TYPE_TENSION)
dicToDomain(pathGdbOutput,"TYPE_FIL",dico_TYPE_FIL)
## Traitement des polygones

for lyrpolygon in dicoPolygon.keys():
    outputFc = os.path.join(pathGdbOutput,dicoPolygon[lyrpolygon][0])
    extractPolygonLayerToFc(gdbInput,lyrpolygon,dicoPolygon,outputFc)

## traitement des polyline

arcpy.env.workspace = gdbInput
polylineGetPath =  [fc for fc in arcpy.ListFeatureClasses() if fc.split(".")[2] == "ERDF_polyline"][0]
polylineInput = os.path.join(gdbInput,polylineGetPath)

polylineFC = os.path.join("in_memory","copyPolyline")
arcpy.CopyFeatures_management(polylineInput,polylineFC)

# traitement specifique des jonctions
arcpy.MakeFeatureLayer_management(polylineInput,"layer_jonction")
arcpy.SelectLayerByAttribute_management("layer_jonction","NEW_SELECTION","layer='49'")
arcpy.CopyFeatures_management("layer_jonction",outputFcJonction)
arcpy.DeleteField_management(outputFcJonction,"layer")

# traitement specifique des reseaux
polylineOutputFc = os.path.join(pathGdbOutput,"RESEAU")
arcpy.CreateFeatureclass_management(pathGdbOutput,"RESEAU","POLYLINE","","","",sr93cc48)
arcpy.AddField_management(polylineOutputFc,"type_tension","TEXT","","","","","","","TYPE_TENSION")
arcpy.AddField_management(polylineOutputFc,"type_fil","TEXT","","","","","","","TYPE_FIL")
arcpy.AddField_management(polylineOutputFc,"insee","TEXT","","","","","","","TYPE_FIL")
# arcpy.AddField_management(polylineOutputFc,"insee","TEXT","","","","","","","TYPE_FIL")
for lyrline in dicoPolyline.keys():
    extractPolylineLayerToFc(polylineFC,lyrline,dicoPolyline,polylineOutputFc)

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).