1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
def INTEGRATION_EMPRISE(workspace):
""" Integration des dossiers de recolement dans la GDB """
#################### Déclaration des variable pour l'environnement de travail ###############################################
#Adresse de basse
Adresse = r'C:\Users\nh\Documents\TEST PYHON\DONNE DE BASE' # Adresse permettant d'aller plus vite dans le TkFileDialog
#Environement de travail
#env.workspace = tkFileDialog.askdirectory(initialdir=Adresse,title="Selectionnez le repertoire RESEAUX de l affaire a integrer")
#env.workspace = workspace
#Dossier = env.workspace
#print Dossier
#Nom de l'affaire
NomDossier = os.path.basename(workspace)
#print NomDossier
#Nom du fichier excel rechercher
FichierExcel = (NomDossier+'.xlsx')
AdresseFichier = os.path.join(workspace,FichierExcel)
Excel = os.path.isfile (AdresseFichier)
RESEAUX=os.path.join(workspace,'RESEAUX')
FDP = os.path.join(workspace,'FOND DE PLAN')
#Procédure de vérification de la structure du l'affaire choisi
if Excel == True:
print "Fiche EXCEL présent"
else :
print "La fiche identification EXCEL abscente"
tkMessageBox.showerror("STRUCTURE DU DOSSIER","Il manque la Fiche Excel")
sys.quit()
if os.path.exists (RESEAUX):
print "Dossier RESEAUX présent"
else:
print "Il manque le dossier RESEAUX"
tkMessageBox.showerror("STRUCTURE DU DOSSIER","Il manque le dossier RESEAUX")
sys.quit()
if os.path.exists (FDP):
print "Dossier FOND DE PLAN présent"
else:
print "Il manque le dossier FOND DE PLAN"
tkMessageBox.showerror("STRUCTURE DU DOSSIER","Il manque le dossier FOND DE PLAN")
sys.quit()
# ouverture du fichier Excel
classeur = xlrd.open_workbook(AdresseFichier)
#print '################################################################################'
#print '#""""""""""""""""""RECUPERATION DES DONNEES EXCEL"""""""""""""""""""""""""""""""'
#print '################################################################################'
# Récupération du nom de toutes les feuilles sous forme de liste
nom_des_feuilles = classeur.sheet_names()
# Récupération de la première feuille
feuille = classeur.sheet_by_name(nom_des_feuilles[0])
#Date de creation du projet (feuille excel)
date= int(feuille.cell_value(16,2)-2)
#print "date :",date
d0 = datetime.date(1900,1,1)
deltat= datetime.timedelta(days=(date))
DateAffaire=d0+deltat
#print "DateAffaire :", DateAffaire
#Date d'integration de emprise
DateINTEG = datetime.date.today()
#print "Date de creation de EMPRISE :" , DateINTEG
Affaire= format(feuille.cell_value(4,2))
#print "Affaire :",Affaire
CodeCommune= Affaire[0:3]
#print "Code commune :", CodeCommune
Entreprise= format(feuille.cell_value(6,2))
#print "Entreprise :", Entreprise
#print '################################################################################'
#print '#"""""""""""""""""""""Creation fichier EMPRISE TEMPORAIRE"""""""""""""""""""""""'
#print '################################################################################'
env.workspace = os.path.join(workspace,'RESEAUX')
#print "env.workspace :" ,env.workspace
#***************Appel de la variable de construction pour emprise********************************************
# Create variables for the input and output feature classes
SOUT = "SD_EP_SOUTERRAIN.shp"
EMPRISE2 = "SD_EP_EMPRISE2.shp"
#Suppression du shape SD_EP_EMPRISE2 en cas de reste dans le dossier
b = os.path.join(env.workspace,'SD_EP_EMPRISE2.shp')
print b
SD_EP_EMPRISE2 = os.path.isfile(os.path.join(env.workspace,'SD_EP_EMPRISE2.shp'))
print SD_EP_EMPRISE2
if SD_EP_EMPRISE2 == True:
arcpy.Delete_management(EMPRISE2)
#Procédure de vérification de la présence du shape SD_EP_SOUTERRAIN
EP_SOUT = os.path.isfile (os.path.join(env.workspace,SOUT))
if EP_SOUT == False:
#print "SHAPE, SD_EP_SOUTERRAIN est abscente"
tkMessageBox.showerror("VERIFICATION SHAPE SOUTERRAIN","La structure des données est incorrect. \n \n Verifiez la presence des elements: \n\n - SD_EP_SOUTERRAIN")
sys.exit()
else:
#*************************************Couche SD_EP_EMPRISE TEMPORAIRE*******************************************
arcpy.MinimumBoundingGeometry_management(SOUT, EMPRISE2,"RECTANGLE_BY_AREA", "ALL") #creation de l emprise sur la couche temporaire, parametrage du type d emprise voulu
#*************************************Ajout de champ************************************************************
arcpy.AddField_management(EMPRISE2,"COMMUNE","TEXT","3") #Ajout du code de la commune
arcpy.AddField_management(EMPRISE2,"DATECREAT","TEXT","10") #Ajout de la date de creation
arcpy.AddField_management(EMPRISE2,"AFFAIRE","TEXT","20") #Ajout du champs AFFAIRE
arcpy.AddField_management(EMPRISE2,"ENTREPRISE","TEXT","20") #Ajout du champs ENTREPRISE
arcpy.AddField_management(EMPRISE2,"DATEINTEG","TEXT","10") #Ajouter le champs pour la date integration a la GDB
arcpy.AddField_management(EMPRISE2,"INFO","TEXT") #Observation sur le projet
#*************************************Ajout de information provenant du fichier excel***************************
#Ajouter la variable (code commune) au champ DATE_INT
codecommune=CodeCommune
with arcpy.da.UpdateCursor(EMPRISE2,"COMMUNE") as cursor:
for row in cursor :
row[0] = (codecommune)
cursor.updateRow(row)
#Ajouter la variable (date de creation) au champ DATECREAT
datecreat=DateAffaire
with arcpy.da.UpdateCursor(EMPRISE2,"DATECREAT") as cursor:
for row in cursor :
row[0] = (datecreat)
cursor.updateRow(row)
#Ajouter la variable (Affaire) au champ AFFAIRE
affaire=Affaire
with arcpy.da.UpdateCursor(EMPRISE2,"AFFAIRE") as cursor:
for row in cursor :
row[0] = (affaire)
cursor.updateRow(row)
#Ajouter la variable (date_integration) au champ DATEINTEG
dateinteg=DateINTEG
with arcpy.da.UpdateCursor(EMPRISE2,"DATEINTEG") as cursor:
for row in cursor :
row[0] = (dateinteg)
cursor.updateRow(row)
#Ajouter la variable (Entreprise) au champ ENTREPRISE
entreprise=Entreprise
with arcpy.da.UpdateCursor(EMPRISE2,"ENTREPRISE") as cursor:
for row in cursor :
row[0] = (entreprise)
cursor.updateRow(row)
#Ajouter la variable (Information) au champ INFO
Question = tkMessageBox.askyesno ("CREATION EMPRISE","Ajouter une information a ce dossier?")
if Question == True :
Info=raw_input("Information a apporter au dossier ?")
with arcpy.da.UpdateCursor(EMPRISE2,"INFO") as cursor: #Renseigne A LA MAIN une information supplémentaire
for row in cursor :
row[0] = (Info)
cursor.updateRow(row)
#print '################################################################################'
#print '#*************************Integration a la gdb**********************************'
#print '################################################################################'
EmpriseGDB = os.path.join(GDB_RECOLEMENT,"SDEEG_EP_EMPRISE.shp")
arcpy.Append_management (EMPRISE2, EmpriseGDB, "NO_TEST", "","")
print "DONNEES EMPRISE AJOUTE A LA GDB"
#tkMessageBox.showinfo("INTEGRATION", "Votre emprise a été ajouté à la GDB")
#Suppression de EMPRISE2 afin d'avoir une dossier le plus propre possible
arcpy.Delete_management(EMPRISE2)
def INTEGRATION_SOUTERRAIN(workspace):
#print '################################################################################'
#print '#*************************INTEGRATION_SOUTERRAIN********************************'
#print '################################################################################'
#****Procédure d'intégration du shape SD_EP_SOUTERRAIN dans le GDB**********************'
#web:
#https://www.journaldunet.fr/web-tech/developpement/1202585-comment-verifier-qu-un-fichier-existe-en-python/
#https://www.youtube.com/watch?v=1IqnpaQy8LM&list=PLrSOXFDHBtfHg8fWBd7sKPxEmahwyVBkC&index=9
dossier_sout_SD = "SD_EP_SOUTERRAIN.shp" #definition du nom du dossier
path = env.workspace #Environnement de travail en fonction de TKFildialoge
Sout = os.path.join(path,dossier_sout_SD) #Permet de concatener le nom du dossier avec l emplacement tout en respectant la codification windows pour le chemin.
if os.path.isfile(Sout)==True:
#print "il y a un dossier SD_EP_SOUT"
#dossier_sout_SDEEG =("SDEEG_EP_SOUTERRAIN.shp")
#Sout_temp= os.path.join(path,dossier_sout_SDEEG)
SoutGDB = os.path.join(GDB_RECOLEMENT,"SDEEG_EP_SOUTERRAIN.shp") # r'C:\Users\nh\Documents\TEST PYHON\GDB RECOLEMENT\GDB_RECOLEMENT.gdb\SDEEG_EP_SOUTERRAIN'
#Integration des données SD_EP_Souterrain dans la GDB SDEEG_EP_EMPRISE
arcpy.Append_management (dossier_sout_SD, SoutGDB, "NO_TEST", "","")
print "DONNEES SOUTERRAIN AJOUTE"
else:
print "il n'y a pas de couche SD_EP_SOUTERRAIN" |
Partager