| 12
 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
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 
 |  
#!/usr/bin/python
# -*- coding: iso-8859-1 -*-
# -*- coding: utf_8 -*-
 
#**********************************************    Import des MODULES    ******************************************************************************
import Tkinter
from Tkinter import *
from PIL import Image, ImageTk
import  Tkinter as Tk
 
import tkMessageBox
from tkMessageBox import *
 
import tkFileDialog
from tkFileDialog import *
 
import os
import os.path
 
import arcpy
from arcpy import env
 
import time
import datetime
from time import *
 
import sys
 
import shutil
 
import random
 
import xlrd
 
import sys   #module permettant d arreter un programme en fonction de la reponse
import glob  #lister le contenu d'un répertoire
 
#**********************************************    Déclaration des variables globales    **************************************************************
 
#Parametre couleur :Master
couleurBG = '#E4E4E4' #Utiliser pour les fonds (background)
couleurTXT ='#273746' #Utiliser pour les texts (foreground)
policeTXT = 'Tilillium' #Utiliser pour la police de text (font)
 
#Variable :
    #Adresse Enregistrement des shape de recolement/GDB RECOLEMENT/
SHAPE_RECOLEMENT = "T:/Technique/SERVICE SIG-TOPOGRAPHIE/OUTILS CARTO/SHAPE_RECOLEMENT"
GDB_RECOLEMENT = "C:/Users/nh/Documents/EMPRISE/GDB_RECOLEMENT.gdb"    #"T:/Technique/SERVICE SIG-TOPOGRAPHIE/OUTILS CARTO/GDB_RECOLEMENT"
GDB_RECOLEMENT_MODEL= "T:/Technique/SERVICE SIG-TOPOGRAPHIE/OUTILS CARTO/GDB_RECOLEMENT_MODEL"
 
 
#Les icones et image
ICON_APPLI = 'G:\TE.ico'
 
class SIG(Tkinter.Tk):    #nous declarons la fenetre principale
        def __init__(self,master):
            Tkinter.Tk.__init__(self,master)
            self.master = master
            self.initialize()
            self.background = couleurBG # mettre la fenetre en couleur
            self.geometry("600x400+600+300") #Les deux premiers pour les dimensions les autres pour emplacement de l'affichage
            self.resizable(width=False,height=False) #Empeche de redimentionner de la fenetre
            self.title('SIG_') # titre de la fenetre
 
            #Ajouter de label
            self.label1 = Tkinter.Label(self,text= "SIG ", foreground=couleurTXT,  font=(policeTXT, 18,'bold')).place(x='75', y='25')
            self.label2 = Tkinter.Label(self,text= "CopyRight: SIG ", foreground=couleurTXT, font=(policeTXT, 10)).place(x='10', y='350')
            self.label3 = Tkinter.Label(self,text= "Création : nh", foreground=couleurTXT,  font=(policeTXT, 10)).place(x='10', y='375')
            self.label4 = Tkinter.Label(self,text= "Version 1.0", foreground=couleurTXT,  font=(policeTXT, 10)).place(x='500', y='375')
 
#******************************************La fenetre principale******************************************************************************************
 
        def initialize(self):    #Ici que nous declarons les boutons
            self.grid()
 
            #Creation d un bandeau de menu
            menu = Tkinter.Menu (self)
 
            #Ajout des différentes rubrique
            Fichier = Tkinter.Menu(self, tearoff=0)
            Recolement = Tkinter.Menu(self, tearoff=0)
 
            # Ajouter les différentes options dans la barre de menu
            menu.add_cascade(label='Fichier', menu=Fichier)
            menu.add_cascade(label='Récolement', menu=Recolement)
 
            # Ajouter les différentes actions pour chaque option
            #Menu Fichier
            Fichier.add_command(label='Quitter', command=self.quit) # quitte le programme
 
            #Menu Récolement
            Recolement.add_command(label='Integration Complete', command=self.INTEGRATION)
 
            # Lancement de la boucle événementielle
            self.config(menu=self)
            self.config(menu = menu)
 
#*********************************************************************************************************************************************************
#******************************************LES FONCTIONS**************************************************************************************************
 
        def quitter(self):
            master.quit()
 
        def INTEGRATION(self):
            ###################################################################################################################################
            #Procédure de sauvagarde de la GDB avant intégration d'une nouvelle affaire
            #SAVE_GDB_RECOLEMENT()
 
            #********************Creation PROCEDURE de sauvegarde de la GDB*****************
            dossier =  'SDEEG_GDB_EP'+('_')+str(datetime.date.today())+('_')+(strftime('%Hh_%Mm_%Ss'))      #definition du nom du dossier
 
            path = r'C:\\Users\\nh\\Documents\\EMPRISE\\SAVE_RECOLEMENT'                                    #Emplacement de sauvegarde
 
            GDB_Save = os.path.join(path,dossier)                                                           #Permet de concatener le nom du dossier avec l emplacement tout en respectant la codification windows pour le chemin.
 
            #Copier coller la gdb
            GDB_Active =  GDB_RECOLEMENT                                                                    #Emplacement de la GDB a SAUVEGARDER
 
            shutil.copytree(GDB_Active,GDB_Save)                                                            #Creation de la copie de sauvegarde (GDB_Active= la GDB actuelle ; GDB_SAVE= la GDB actuelle savegarder à la date du dossier)
 
            #Message de fin de procedure de sauvegarde
            tkMessageBox.showinfo("SAUVEGARDE", "Votre dernière sauvegarde se nomme"+'\n'+'\n'+dossier+'\n'+'\n'+"Vous la trouverez ici"+'\n'+'\n'+path)         #Message d'information a utilisateur
 
 
 
            ####################     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")
            Dossier = env.workspace
 
            #Nom de l'affaire
            NomDossier = os.path.basename(Dossier)
            #print "Nom du dossier :" , NomDossier
 
            #Nom du fichier excel rechercher
            FichierExcel = (NomDossier+'.xlsx')
            #print "Nom du fichier Excel recherché : " , FichierExcel
 
            AdresseFichier = os.path.join(Dossier,FichierExcel)
            #print "Adresse probable du fichier excel :" ,AdresseFichier
 
            Excel = os.path.isfile (AdresseFichier)
            #print "Présence du fichier excel :", Excel
 
            RESEAUX=os.path.join(Dossier,'RESEAUX')
            FDP = os.path.join(Dossier,'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.exit()
 
            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.exit()
 
            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.exit()
 
            # ouverture du fichier Excel
            classeur = xlrd.open_workbook(AdresseFichier)
 
            # 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"""""""""""""""""""""""'
 
            env.workspace = os.path.join(Dossier,'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"
 
            #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()
 
            #*************************************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","Voulez-vous ajouter une information a ce dossier?")
            if Question == True :
                Info=raw_input("Quel information voulez vous 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**********************************'
 
            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")
            #print "Script completed"
 
            #Suppression de EMPRISE2 afin d'avoir une dossier le plus propre possible
            arcpy.Delete_management(EMPRISE2)
 
            #def INTEGRATION_SOUTERRAIN():
            #****Procédure d'intégration du shape SD_EP_SOUTERRAIN dans le GDB********************
 
            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_SOUTERRAIN"
                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"
 
        #def INTEGRATION_FOYER():
            #****Procédure d'intégration du shape SD_EP_FOYER dans le GDB********************
            dossier_foyer_SD =  "SD_EP_FOYER.shp"                                 #definition du nom du dossier
            path = env.workspace                                                   #Environnement de travail en fonction de TKFildialoge
            Foyer = os.path.join(path,dossier_foyer_SD)                             #Permet de concatener le nom du dossier avec l emplacement tout en respectant la codification windows pour le chemin.
 
            if os.path.isfile(Foyer)==True:
               print "il y a un dossier SD_EP_FOYER"
               FoyerGDB = os.path.join(GDB_RECOLEMENT,"SDEEG_EP_FOYER.shp")      #r'C:\Users\nh\Documents\TEST PYHON\GDB RECOLEMENT\GDB_RECOLEMENT.gdb\SDEEG_EP_FOYER'
 
               #Integration des données SD_EP_FOYER dans la GDB SDEEG_EP_FOYER
               arcpy.Append_management (dossier_foyer_SD, FoyerGDB, "NO_TEST", "","")
               print "DONNEES FOYER AJOUTE"
 
            else:
               print "il n'y a pas de couche SD_EP_FOYER"
 
            #def INTEGRATION_ORGANE():
            #****Procédure d'intégration du shape SD_EP_ORGANE dans le GDB********************
            dossier_organe_SD =  "SD_EP_ORGANE.shp"                                  #definition du nom du dossier
            path = env.workspace                                                     #Environnement de travail en fonction de TKFildialoge
            Organe = os.path.join(path,dossier_organe_SD)                             #Permet de concatener le nom du dossier avec l emplacement tout en respectant la codification windows pour le chemin.
 
            if os.path.isfile(Organe)==True:
               #print "il y a un dossier SD_EP_ORGANE"
               OrganeGDB = os.path.join(GDB_RECOLEMENT,"SDEEG_EP_ORGANE.shp")  #r'C:\Users\nh\Documents\TEST PYHON\GDB RECOLEMENT\GDB_RECOLEMENT.gdb\SDEEG_EP_ORGANE'
 
               #Integration des données SD_EP_ORGANE dans la GDB SDEEG_EP_ORGANE
               arcpy.Append_management (dossier_organe_SD, OrganeGDB, "NO_TEST", "","")
               print "DONNEES ORGANE AJOUTE"
            else:
               print "il n'y a pas de couche SD_EP_ORGANE"
 
            #def INTEGRATION_CMDE():
            #****Procédure d'intégration du shape SD_EP_CMDE dans le GDB********************
            dossier_cmde_SD =  "SD_EP_CMDE.shp"                                  #definition du nom du dossier
            path = env.workspace                                                 #Environnement de travail en fonction de TKFildialoge
            CMDE = os.path.join(path,dossier_cmde_SD)                             #Permet de concatener le nom du dossier avec l emplacement tout en respectant la codification windows pour le chemin.
 
            if os.path.isfile(CMDE)==True:
               #print "il y a un dossier SD_EP_CMDE"
               CMDE_GDB = os.path.join(GDB_RECOLEMENT,"SDEEG_EP_CMDE.shp")   #r'C:\Users\nh\Documents\TEST PYHON\GDB RECOLEMENT\GDB_RECOLEMENT.gdb\SDEEG_EP_CMDE'
 
               #Integration des données SD_EP_ORGANE dans la GDB SDEEG_EP_ORGANE
               arcpy.Append_management (dossier_cmde_SD, CMDE_GDB, "NO_TEST", "","")
               print "DONNEES CMDE AJOUTE"
 
            else:
               print "il n'y a pas de couche SD_EP_CMDE"
 
            #def INTEGRATION_LEVE():
            #****Procédure d'intégration du shape SD_PT_LEVE_EP dans le GDB********************
            dossier_leve_SD =  "SD_PT_LEVE_EP.shp"                               #definition du nom du dossier
            path = env.workspace                                                 #Environnement de travail en fonction de TKFildialoge
            LEVE = os.path.join(path,dossier_leve_SD)                             #Permet de concatener le nom du dossier avec l emplacement tout en respectant la codification windows pour le chemin.
 
            if os.path.isfile(LEVE)==True:
               #print "il y a un dossier SD_EP_LEVE"
               LEVE_GDB = os.path.join(GDB_RECOLEMENT,"SDEEG_PT_LEVE_EP.shp")        #r'C:\Users\nh\Documents\TEST PYHON\GDB RECOLEMENT\GDB_RECOLEMENT.gdb\SDEEG_PT_LEVE_EP'
 
               #Integration des données SD_PT_LEVE_EP dans la GDB SDEEG_EP_ORGANE
               arcpy.Append_management (dossier_leve_SD, LEVE_GDB, "NO_TEST", "","")
               print "DONNEES LEVE AJOUTE"
 
            else:
               print "il n'y a pas de couche SD_EP_LEVE"
 
            tkMessageBox.showinfo("INTEGRATION","Integration du dossier REUSSI : " +NomDossier  )
 
#******************************************Fermer la boucle**************************************************************************************************
if __name__ == "__main__":       #nous parametrons notre fenetre principale
    app = SIG(None)
    app.mainloop() | 
Partager