/
GeoMCE.py
1469 lines (1388 loc) · 231 KB
/
GeoMCE.py
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
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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
/***************************************************************************
GeoMCE
A QGIS plugin
GeoMCE permet de mettre en forme des couches shape en vue des les impoprter
dans la plateforme nationale de géolocalisation des mesures compensatoires
environnementales prévue par la loi sur la reconquète de la biodiveristé et
des paysages du 16 aout 2016
-------------------
begin : 2020-03-26
git sha : $Format:%H$
copyright : (C) 2020 by DREAL Auvergne-Rhône-Alpes
email : cedric.claude@developpement-durable.gouv.fr
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
from __future__ import absolute_import
from builtins import str
from builtins import range
from builtins import object
from PyQt5.QtCore import *
from PyQt5 import QtWidgets
from PyQt5.QtGui import *
from qgis.core import *
from qgis.gui import *
from qgis.PyQt.QtGui import *
from qgis.utils import *
from PyQt5.QtWidgets import QAction, QDialog, QFormLayout, QFileDialog, QProgressBar, QListWidgetItem
import os, processing, fnmatch, sys, glob, datetime, unicodedata, zipfile, os.path, urllib
# Import the code for the dialog
from .GeoMCE_dialog import GeoMCEDialog
from .aboutdialog import AboutDialog
from .resources import *
from os.path import basename
from datetime import date
from pathlib import Path
class GeoMCE(object):
"""QGIS Plugin Implementation."""
def __init__(self, iface):
"""Constructor.
:param iface: An interface instance that will be passed to this class
which provides the hook by which you can manipulate the QGIS
application at run time.
:type iface: QgisInterface
"""
# Save reference to the QGIS interface
self.iface = iface
# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale = QSettings().value('locale/userLocale')[0:2]
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'GeoMCE_{}.qm'.format(locale))
if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
self.dlg = GeoMCEDialog()
self.dlga = AboutDialog()
#initialization for select features
self.turnedoffLayers = []
self.selectList = []
self.cLayer = None
self.provider = None
self.saved = False
self.countchange = 0
selectall = 0
# Declare instance attributes
self.actions = []
self.menu = self.tr(u'&GeoMCE')
# TODO: We are going to let the user set this up in a future iteration
self.toolbar = self.iface.addToolBar(u'GeoMCE')
self.toolbar.setObjectName(u'GeoMCE')
# noinspection PyMethodMayBeStatic
def tr(self, message):
"""Get the translation for a string using Qt translation API.
We implement this ourselves since we do not inherit QObject.
:param message: String for translation.
:type message: str, QString
:returns: Translated version of message.
:rtype: QString
"""
# noinspection PyTypeChecker,PyArgumentList,PyCallByClass
return QCoreApplication.translate('GeoMCE', message)
def add_action(
self,
icon_path,
text,
callback,
enabled_flag=True,
add_to_menu=True,
add_to_toolbar=True,
status_tip=None,
whats_this=None,
parent=None):
"""Add a toolbar icon to the toolbar.
:param icon_path: Path to the icon for this action. Can be a resource
path (e.g. ':/plugins/foo/bar.png') or a normal file system path.
:type icon_path: str
:param text: Text that should be shown in menu items for this action.
:type text: str
:param callback: Function to be called when the action is triggered.
:type callback: function
:param enabled_flag: A flag indicating if the action should be enabled
by default. Defaults to True.
:type enabled_flag: bool
:param add_to_menu: Flag indicating whether the action should also
be added to the menu. Defaults to True.
:type add_to_menu: bool
:param add_to_toolbar: Flag indicating whether the action should also
be added to the toolbar. Defaults to True.
:type add_to_toolbar: bool
:param status_tip: Optional text to show in a popup when mouse pointer
hovers over the action.
:type status_tip: str
:param parent: Parent widget for the new action. Defaults None.
:type parent: QWidget
:param whats_this: Optional text to show in the status bar when the
mouse pointer hovers over the action.
:returns: The action that was created. Note that the action is also
added to self.actions list.
:rtype: QAction
"""
# Create the dialog (after translation) and keep reference
self.dlg = GeoMCEDialog()
icon = QIcon(icon_path)
action = QAction(icon, text, parent)
action.triggered.connect(callback)
action.setEnabled(enabled_flag)
if status_tip is not None:
action.setStatusTip(status_tip)
if whats_this is not None:
action.setWhatsThis(whats_this)
if add_to_toolbar:
self.toolbar.addAction(action)
if add_to_menu:
self.iface.addPluginToVectorMenu(
self.menu,
action)
self.actions.append(action)
return action
def initGui(self):
"""Create the menu entries and toolbar icons inside the QGIS G"""
icon_path = ':/plugins/GeoMCE/icon.png'
self.add_action(
icon_path,
text=self.tr(u'GeoMCE'),
callback=self.run,
parent=self.iface.mainWindow())
valcom = self.get_communes()
self.dlg.communes.setText(valcom)
valtamponpoint = self.distance_tampon_point_read()
valtamponligne = self.distance_tampon_ligne_read()
self.checkBox_read()
self.tampon_read()
self.dlg.geoportail.clicked.connect(self.wfs)
self.dlg.fusion.clicked.connect(self.fusion)
self.dlg.eff_form.clicked.connect(self.eff_formulaire)
self.dlg.checkBox.stateChanged.connect(self.checkBox_write)
self.dlg.checkBox.stateChanged.connect(self.checkBox_read)
self.dlg.tampon.stateChanged.connect(self.tampon_write)
self.dlg.tampon.stateChanged.connect(self.tampon_read)
self.dlg.mMapLayerComboBox_2.currentIndexChanged.connect(self.set_select_attributes)
self.dlg.mMapLayerComboBox.currentIndexChanged.connect(self.set_select_attributes)
self.dlg.mMapLayerComboBox.currentIndexChanged.connect(self.compatibilite)
self.dlg.save.clicked.connect(self.save_edits)
self.dlg.show_t.clicked.connect(self.show_table)
self.dlg.show_t_2.clicked.connect(self.show_table_2)
self.dlg.create_new_field.clicked.connect(self.newfield_connect)
self.dlg.create_new_field_2.clicked.connect(self.newfield_connect_2)
self.dlg.change_another.clicked.connect(self.change_to_any)
self.dlg.pushButton.clicked.connect(self.select_output_file_store)
self.dlg.pushButton_3.clicked.connect(self.select_save_folder)
self.dlg.pushButton_4.clicked.connect(self.select_save_folder_2)
self.dlg.about.clicked.connect(self.doabout)
#self.dlg.nom.setPlaceholderText(u'Nom de la mesure - 100 caractères max')
#self.dlg.description.setPlaceholderText(u'Description de la mesure - 254 caractères max')
#self.dlg.decision.setPlaceholderText(u'Références de l\'acte et de l\'article prescrivant la mesure - 254 caractères max')
#self.dlg.refei.setPlaceholderText(u'Références à l\'étude d\'impact décrivant la mesure - 254 caractères max')
#self.dlg.faunes.setDefaultText(u'Espèces animales concernées par la mesure - Respecter la casse des noms latins - 254 caractères max')
#self.dlg.flores.setPlaceholderText(u'Espèces végétales concernées par la mesure - Respecter la casse des noms latins - 254 caractères max')
#self.dlg.echeances.setPlaceholderText(u'Libéllé de la mesure de suivi - 254 caractères max')
self.listWidget()
QgsProject.instance().layersAdded.connect(self.listWidget)
QgsProject.instance().layersRemoved.connect(self.listWidget)
self.dlg.Exit.clicked.connect(self.exit)
self.dlg.Exit_2.clicked.connect(self.exit)
self.dlg.Exit_3.clicked.connect(self.exit)
self.dlg.zipbutton.clicked.connect(self.archive)
self.dlg.zipbutton_2.clicked.connect(self.archive_2)
self.dlg.dossier.clicked.connect(self.dossier)
self.dlg.dossier_2.clicked.connect(self.dossier_2)
self.dlg.sauvegarder_tampon.clicked.connect(self.sauv_dist_tampon)
self.dlg.maj.clicked.connect(self.maj_label)
self.dlg.validity.clicked.connect(self.validite)
#fonctions personnalisees-------------------------------------------------------------------------------------------------------------
#fonctions de sauvegarde -------------------------------------------------------------------------------------------------------------
#fonction prise en compte du format shape
def checkBox_write(self):
s = QSettings()
s.setValue('/GeoMCE-Sortie_shp', self.dlg.checkBox.isChecked())
self.iface.messageBar().pushMessage(u'GéoMCE',u'Paramètre sauvegardé', level=Qgis.Info, duration=3)
def checkBox_read(self):
s = QSettings()
self.dlg.checkBox.setChecked(s.value('/GeoMCE-Sortie_shp', False, type=bool))
#fonction sauvegarde d'application d un tampon
def tampon_write(self):
s = QSettings()
s.setValue('/GeoMCE-tampon', self.dlg.tampon.isChecked())
self.iface.messageBar().pushMessage(u'GéoMCE',u'Paramètre sauvegardé', level=Qgis.Info, duration=3)
def tampon_read(self):
s = QSettings()
self.dlg.tampon.setChecked(s.value('/GeoMCE-tampon', False, type=bool))
# fonction lecture des distances tampon sauvegardees
def distance_tampon_point_read(self):
s = QSettings()
self.dlg.distance_tampon_point.setValue(s.value('/GeoMCE-distance_tampon_point', True, type=int))
def distance_tampon_ligne_read(self):
s = QSettings()
self.dlg.distance_tampon_ligne.setValue(s.value('/GeoMCE-distance_tampon_ligne', True, type=int))
#fonctions generale-------------------------------------------------------------------------------------------------------------------
#verification si presence de vecteurs pour lancer le plugin
def checkvector(self):
count = 0
for name, layer in QgsProject.instance().mapLayers().items():
if layer.type() == QgsMapLayer.VectorLayer:
count += 1
return count
#fonction relative a la separation des couches -----------------------------------------------------------------------------------------------
#chemin d enregistrement du traitement splitvectorlayer
def select_save_folder(self):
qfd_1 = QFileDialog()
title_1 = u'T\'enregistres ça où?'
path_1 = ""
filename = QFileDialog.getExistingDirectory(qfd_1, title_1, path_1)
self.dlg.enregistrement.setText(filename)
#on recupere le chemin du dossier d enregistrement du traitement pour plus tard
def get_enregistrement(self):
chemin_couche = self.dlg.mMapLayerComboBox_2.currentLayer()
source_chemin_couche = chemin_couche.dataProvider().dataSourceUri()
chemin_couche_separer = os.path.dirname(source_chemin_couche)
if self.dlg.enregistrement.text() =="":
new_enregistrement = chemin_couche_separer
else:
new_enregistrement = self.dlg.enregistrement.text()
return new_enregistrement
#choix de la couche a pour traitement splitlayervector
def chooselayer(self):
self.dlg.mMapLayerComboBox_2.clear()
self.dlg.mMapLayerComboBox.clear()
self.dlg.mFieldComboBox.clear()
self.dlg.mMapLayerComboBox.setFilters(QgsMapLayerProxyModel.VectorLayer)
layerlist=[]
slist=[]
layers = [layer for layer in QgsProject.instance().mapLayers().values()]
for layer in layers:
layerType = layer.type()
if layerType == QgsMapLayer.VectorLayer:
self.dlg.mMapLayerComboBox_2.addItem(layer.name())
self.set_select_attributes()
#choix du champ separateur pour fonction splitlayervector
def set_select_attributes(self):
self.dlg.mMapLayerComboBox_2.clear()
self.dlg.mMapLayerComboBox.clear()
self.dlg.mMapLayerComboBox_2.setFilters(QgsMapLayerProxyModel.VectorLayer)
self.dlg.mMapLayerComboBox.setFilters(QgsMapLayerProxyModel.VectorLayer)
self.dlg.mFieldComboBox.clear()
if self.dlg.mMapLayerComboBox.currentText() != "":
layername = self.dlg.mMapLayerComboBox.currentText()
for name, selectlayer in QgsProject.instance().mapLayers().items():
if selectlayer.name() == layername:
for field in selectlayer.dataProvider().fields():
self.dlg.mFieldComboBox.addItem(field.name())
#on connecte le champ en fonction de la couche a séparer
def select_layer_fields2(self, vlayer):
self.dlg.mFieldComboBox.setLayer(vlayer)
field = self.dlg.mFieldComboBox.setLayer(vlayer)
def newfield_connect(self):
self.create_new_field()
self.set_select_attributes()
return
def newfield_connect_2(self):
self.create_new_field_2()
self.set_select_attributes()
return
#on lance splitlayervector
def create_new_field(self) :
#creation d un dossier dans C: nomme GeoMCE et d un sous dossier horodate qui va porter le nom de la couche + le nom du champ separateur qui va etre traiter
couche = self.dlg.mMapLayerComboBox_2.currentText()
champ = self.dlg.mFieldComboBox.currentText()
path = self.get_enregistrement()
p = path + "/" + datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S') + "_" + couche + "_" + champ
os.makedirs(p)
#separation de la couche active par le champ defini au debut du script et enregistrement dans le dossier choisi par lafonction get_enregistrement. Attention, QGIS3 genere par defaut des fichiers geopackage sauf qu on veut du shape ...
split = processing.run("qgis:splitvectorlayer", {'INPUT':self.dlg.mMapLayerComboBox_2.currentText(),'FIELD': self.dlg.mFieldComboBox.currentText(), 'OUTPUT' : p})
#permet de scanner le dossier de get_enregistrement
def find_files(directory, pattern, only_root_directory):
for root, dirs, files in os.walk(directory):
for basename in files:
if fnmatch.fnmatch(basename.lower(), pattern):
filename = os.path.join(root, basename)
yield filename
if (only_root_directory):
break
if self.dlg.checkBox.isChecked():
#... puis on scanne le dossier a la recherche des shapes et on les charge dans l interface
count = 0
for src_file in find_files(p, '*.shp', True):
(head, tail) = os.path.split(src_file)
(name, ext) = os.path.splitext(tail)
vlayer = iface.addVectorLayer(src_file, name, "ogr")
output = count
else :
count = 0
for src_file in find_files(p, '*.gpkg', True):
(head, tail) = os.path.split(src_file)
(name, ext) = os.path.splitext(tail)
vlayer = QgsVectorLayer(src_file, name, "ogr")
#...et on les convertis en shape ...
QgsVectorFileWriter.writeAsVectorFormat(vlayer,p+ "/" + vlayer.name(), 'UTF-8',vlayer.crs(), 'ESRI Shapefile')
output = count
#... puis on scanne le dossier a la recherche des shapes et on les charge dans l interface
count = 0
for src_file in find_files(p, '*.shp', True):
(head, tail) = os.path.split(src_file)
(name, ext) = os.path.splitext(tail)
vlayer = iface.addVectorLayer(src_file, name, "ogr")
output = count
self.dlg.mFieldComboBox.clear()
self.dlg.mMapLayerComboBox_2.clear()
self.iface.messageBar().pushMessage(u'GéoMCE',u'Les nouvelles couches ont été créées dans le dossier ' + self.get_enregistrement() + u' et chargées dans l\'interface', level=Qgis.Info, duration=3)
#fonctions relatives au traitement de fusion des couches -----------------------------------------------------------------------------------------------
#chemin d enregistrement du traitement merge
def select_save_folder_2(self):
qfd_1 = QFileDialog()
filename = QFileDialog.getSaveFileName(qfd_1, "Nom des couches fusionnées","", '*.shp')
self.dlg.mQgsFileWidget.setText(filename[0])
#traitement merge : permet de fusionner les couches selectionnees
def fusion(self):
layers = self.dlg.mComboBox.checkedItems()
#p = self.dlg.mQgsFileWidget.filePath()
path = self.dlg.mQgsFileWidget.text()
path_fusion = os.path.dirname(path)
shape = path
gpkg = path+'.gpkg'
nom_fusion = [layers for layers in self.dlg.mComboBox.checkedItems()]
merge = processing.run("qgis:mergevectorlayers",
{'LAYERS':nom_fusion,
'CRS':None,
'OUTPUT':'TEMPORARY_OUTPUT'})
vlayer = merge['OUTPUT']
processing.run("qgis:refactorfields",{'INPUT':vlayer, 'FIELDS_MAPPING' : [{'expression': '"id"', 'length': 10, 'name': 'id', 'precision': 0, 'type': 2}, {'expression': '"nom"', 'length': 100, 'name': 'nom', 'precision': 0, 'type': 10}, {'expression': '"categorie"', 'length': 7, 'name': 'categorie', 'precision': 0, 'type': 10}, {'expression': '"cible"', 'length': 100, 'name': 'cible', 'precision': 0, 'type': 10}, {'expression': '"descriptio"', 'length': 254, 'name': 'descriptio', 'precision': 0, 'type': 10}, {'expression': '"decision"', 'length': 254, 'name': 'decision', 'precision': 0, 'type': 10}, {'expression': '"refei"', 'length': 254, 'name': 'refei', 'precision': 0, 'type': 10}, {'expression': '"duree"', 'length': 25, 'name': 'duree', 'precision': 0, 'type': 10}, {'expression': '"unite"', 'length': 25, 'name': 'unite', 'precision': 0, 'type': 10}, {'expression': '"modalite"', 'length': 50, 'name': 'modalite', 'precision': 0, 'type': 10}, {'expression': '"cout"', 'length': 10, 'name': 'cout', 'precision': 0, 'type': 10}, {'expression': '"montant_pr"', 'length': 10, 'name': 'montant_pr', 'precision': 0, 'type': 10}, {'expression': '"faunes"', 'length': 254, 'name': 'faunes', 'precision': 0, 'type': 10}, {'expression': '"flores"', 'length': 254, 'name': 'flores', 'precision': 0, 'type': 10}, {'expression': '"echeances"', 'length': 254, 'name': 'echeances', 'precision': 0, 'type': 10}, {'expression': '"communes"', 'length': 220, 'name': 'communes', 'precision': 0, 'type': 10}, {'expression': '"layer"', 'length': 100, 'name': 'layer', 'precision': 0, 'type': 10}, {'expression': '"path"', 'length': 200, 'name': 'path', 'precision': 0, 'type': 10}], 'OUTPUT' :path})
if self.dlg.checkBox.isChecked():
dede = iface.addVectorLayer(path, "", "ogr")
dede.startEditing()
dede.dataProvider().deleteAttributes([16,17])
dede.commitChanges()
else :
popo = QgsVectorLayer(gpkg, "Fusion", "ogr")
zaza = QgsVectorFileWriter.writeAsVectorFormat(popo,path,'UTF-8',vlayer.crs(), "ESRI Shapefile")
zaza = iface.addVectorLayer(path, "", "ogr")
zaza.startEditing()
zaza.dataProvider().deleteAttributes([16,17])
zaza.commitChanges()
#fonctions qui permettent de s assurer de la compatibilite et des erreurs des geometries qui vont etre modifier
#ouvre le traitement qui permet de verifier la validite des geometrie (polygone qui s autocroisent notamment)
def validite(self):
processing.execAlgorithmDialog('qgis:checkvalidity')
#permet de verifier et d afficher a l'utilisateur la compatibilite de la couche a traiter avec un import dans geomce
def compatibilite(self):
layer = self.dlg.mMapLayerComboBox.currentLayer()
if layer is None :
pass
else:
source_chemin_couche = layer.dataProvider().dataSourceUri()
(head, tail) = os.path.split(source_chemin_couche)
(name, ext) = os.path.splitext(tail)
format = ext.split('|',1)
if format[0]==('.shp'):
if layer.wkbType()==1 or layer.wkbType()==2 or layer.wkbType()==3 or layer.wkbType()==5 or layer.wkbType()==6:
self.dlg.label_28.hide()
self.dlg.label_27.show()
else:
self.dlg.label_27.hide()
self.dlg.label_28.show()
else:
self.dlg.label_27.hide()
self.dlg.label_28.show()
#fonctions assurant la mise en forme des couches pour un import dans GeoMCE---------------------------------------------------------------
#choix de la couche a traiter
def chooselayer_2(self):
self.dlg.mMapLayerComboBox.clear()
Layers = [layer for layer in QgsProject.instance().mapLayers().values()]
Layer_list = []
for layer in Layers:
Layer_list.append (layer.name())
self.dlg.mMapLayerComboBox.addItems(Layer_list)
self.set_select_attributes()
#on efface tous les champs existants et on cree ceux qui permettent un import dans GeoMCE
def create_new_field_2(self):
layer = self.dlg.mMapLayerComboBox.currentLayer()
source_chemin_couche = layer.dataProvider().dataSourceUri()
(head, tail) = os.path.split(source_chemin_couche)
(name, ext) = os.path.splitext(tail)
format = ext.split('|',1)
if format[0]==('.shp'):
if layer.wkbType()==1 or layer.wkbType()==2 or layer.wkbType()==3 or layer.wkbType()==5 or layer.wkbType()==6:
layer.startEditing()
#on efface tout les champs existants...
prov = layer.dataProvider()
field_names = [field.name() for field in prov.fields()]
for count, f in enumerate(field_names):
jean = range(count, count +1 )
paul = range(count)
jeanpaul = list(range(count, count +1 )) + list (range(count))
layer.dataProvider().deleteAttributes(jeanpaul)
#... et creation des nouveaux champs compatibles avec un import dans GeoMCE
if self.dlg.maj.isChecked():
layer.dataProvider().addAttributes(
[QgsField("id", QVariant.Int,'Integer64',10,0),
QgsField("nom", QVariant.String,'String',100,0),
QgsField("categorie", QVariant.String,'String',7,0),
QgsField("cible", QVariant.String,'String',100,0),
QgsField("descriptio", QVariant.String,'String',254,0),
QgsField("decision", QVariant.String,'String',254,0),
QgsField("refei", QVariant.String,'String',254,0)])
else:
layer.dataProvider().addAttributes(
[QgsField("id", QVariant.Int,'Integer64',10,0),
QgsField("nom", QVariant.String,'String',100,0),
QgsField("categorie", QVariant.String,'String',7,0),
QgsField("cible", QVariant.String,'String',100,0),
QgsField("descriptio", QVariant.String,'String',254,0),
QgsField("decision", QVariant.String,'String',254,0),
QgsField("refei", QVariant.String,'String',254,0),
QgsField("duree", QVariant.String,'String',25,0),
QgsField("unite", QVariant.String,'String',25,0),
QgsField("modalite", QVariant.String,'String',50,0),
QgsField("cout",QVariant.Int,'Integer64', 10,0),
QgsField("montant_pr",QVariant.Int,'Integer64', 10,0),
QgsField("faunes",QVariant.String, 'String', 254,0),
QgsField("flores",QVariant.String, 'String', 254,0),
QgsField("echeances",QVariant.String, 'String', 254,0),
QgsField("communes", QVariant.String,'String',220,0)])#,
#QgsField("surface", QVariant.String,'String', 10,2),
#QgsField("surf_unite",QVariant.String, 'String', 50,0),
#QgsField("lineaire",QVariant.String,'String', 10,2),
#QgsField("lin_unite",QVariant.String, 'String', 50,0),
#QgsField("nb_point",QVariant.Int,'Integer64', 10,0),
#QgsField("ore",QVariant.String, 'String', 5,0),
#QgsField("date_eche",QVariant.String, 'String', 254,0)])
layer.updateFields()
layer.selectAll()
self.iface.messageBar().pushMessage(u'GéoMCE',u'Tout a été effacé, j\'espère que tu ne le regretteras pas!', level=Qgis.Info, duration=3)
return
else:
self.iface.messageBar().pushMessage(u'GéoMCE',u'La couche sélectionnée n\'est pas compatible avec GéoMCE : aucune modification n\'a été effectuée', level=Qgis.Critical, duration=3)
else:
self.iface.messageBar().pushMessage(u'GéoMCE',u'La couche sélectionnée n\'est pas compatible avec GéoMCE : aucune modification n\'a été effectuée', level=Qgis.Critical, duration=3)
#les champs de saisi texte et listes deroulantes.
def get_new_nom(self):
new_nom = self.dlg.nom.text()
return new_nom
def get_description(self):
new_val_description = self.dlg.description.toPlainText()
return new_val_description
def get_decision(self):
new_val_decicision = self.dlg.decision.text()
return new_val_decicision
def get_refei(self):
new_val_refei = self.dlg.refei.text()
return new_val_refei
def get_duree(self):
new_val_duree = self.dlg.duree.text()
return new_val_duree
def get_categorie(self):
#on s assure de ne recuperer que les codes et pas le texte complet : l'import dans l outil etant limite a 7 caracteres max
numero_categorie = [u'E',u'E1',u'E1-1',u'E1-1-a',u'E1-1-b',u'E1-1-c',u'E1-1-z',u'E2',u'E2-1',u'E2-1-a',u'E2-1-b',u'E2-1-c',u'E2-1-z',u'E2-2',u'E2-2-a',u'E2-2-b',u'E2-2-c',u'E2-2-d',u'E2-2-e',u'E2-2-f',u'E2-2-g',u'E2-2-z',u'E3',u'E3-1',u'E3-1-a',u'E3-1-b',u'E3-1-z',u'E3-2',u'E3-2-a',u'E3-2-b',u'E3-2-c',u'E3-2-z',u'E4',u'E4-1',u'E4-1-a',u'E4-1-b',u'E4-1-c',u'E4-1-z',u'E4-2',u'E4-2-a',u'E4-2-b',u'E4-2-c',u'E4-2-z',u'R',u'R1',u'R1-1',u'R1-1-a',u'R1-1-b',u'R1-1-c',u'R1-1-d',u'R1-1-z',u'R1-2',u'R1-2-a',u'R1-2-b',u'R1-2-c',u'R1-2-z',u'R2',u'R2-1',u'R2-1-a',u'R2-1-b',u'R2-1-c',u'R2-1-d',u'R2-1-e',u'R2-1-f',u'R2-1-g',u'R2-1-h',u'R2-1-i',u'R2-1-j',u'R2-1-k',u'R2-1-l',u'R2-1-m',u'R2-1-n',u'R2-1-o',u'R2-1-p',u'R2-1-q',u'R2-1-r',u'R2-1-s',u'R2-1-z',u'R2-2',u'R2-2-a',u'R2-2-b',u'R2-2-c',u'R2-2-d',u'R2-2-e',u'R2-2-f',u'R2-2-g',u'R2-2-h',u'R2-2-i',u'R2-2-j',u'R2-2-k',u'R2-2-l',u'R2-2-m',u'R2-2-n',u'R2-2-o',u'R2-2-p',u'R2-2-q',u'R2-2-z',u'R3',u'R3-1',u'R3-1-a',u'R3-1-b',u'R3-1-c',u'R3-1-z',u'R3-2',u'R3-2-a',u'R3-2-b',u'R3-2-c',u'R3-2-z',u'C ',u'C1',u'C1-1',u'C1-1-a',u'C1-1-b',u'C1-1-c',u'C1-1-z',u'C2',u'C2-1',u'C2-1-a',u'C2-1-b',u'C2-1-c',u'C2-1-d',u'C2-1-e',u'C2-1-f',u'C2-1-g',u'C2-1-h',u'C2-1-z',u'C2-2',u'C2-2-a',u'C2-2-b',u'C2-2-c',u'C2-2-d',u'C2-2-e',u'C2-2-f',u'C2-2-g',u'C2-2-h',u'C2-2-i',u'C2-2-z',u'C3-1',u'C3-1-a',u'C3-1-b',u'C3-1-c',u'C3-1-d',u'C3-1-z',u'C3-2',u'C3-2-a',u'C3-2-b',u'C3-2-c',u'C3-2-d',u'C3-2-z',u'A',u'A1',u'A1-1',u'A1-1-a',u'A1-2',u'A1-2-a',u'A2',u'A2-1',u'A2-1-a',u'A2-1-b',u'A2-1-c',u'A2-1-d',u'A3',u'A3-1',u'A3-1-a',u'A3-1-b',u'A3-1-z',u'A4',u'A4-1',u'A4-1-a',u'A4-1-b',u'A4-1-c',u'A4-1-z',u'A4-2',u'A4-2-a',u'A4-2-b',u'A4-2-c',u'A4-2-z',u'A5',u'A5-1',u'A5-1-a',u'A5-1-b',u'A5-1-z',u'A6',u'A6-1',u'A6-1-a',u'A6-1-b',u'A6-1-z',u'A6-2',u'A6-2-a',u'A6-2-b',u'A6-2-c',u'A6-2-d',u'A6-2-z',u'A7',u'A7-1',u'A7-1-a',u'A8',u'A8-1',u'A8-1-z',u'A9',u'A9-1',u'A9-1-a',u'Z',u'Zz',u'Zzz',u'Zzzz']
new_val_categorie = self.dlg.comboBox.currentIndex()
index = numero_categorie[new_val_categorie]
return index
def get_cible(self):
new_val_cible = self.dlg.comboBox_2.currentText()
return new_val_cible
def get_unite(self):
numero_unite =[u'Année',u'Mois',u'Jour']
new_val_unite = self.dlg.comboBox_3.currentIndex()
index = numero_unite[new_val_unite]
return index
def get_modalite(self):
new_val_modalite = self.dlg.comboBox_4.currentText()
return new_val_modalite
def get_communes(self):
s = QSettings()
new_val_communes = s.value('/GeoMCE-chemin_communes.shp')
self.dlg.communes.setText(new_val_communes)
return new_val_communes
def get_cout(self):
new_val_cout = self.dlg.cout.text()
return new_val_cout
def get_montant(self):
new_val_montant = self.dlg.montant.text()
return new_val_montant
def get_faunes(self):
new_val_faunes = self.dlg.faunes.currentText()
return new_val_faunes
def get_flores(self):
new_val_flores = self.dlg.flores.currentText()
return new_val_flores
def get_echeances(self):
new_val_echeances = self.dlg.echeances.text()
return new_val_echeances
def surface_prescrite(self):
new_val_surface_prescrite = self.dlg.surf_prescrite.text()
return new_val_surface_prescrite
def surface_unite(self):
new_val_surf_unite = self.dlg.surf_unite.currentText()
return new_val_surf_unite
def lineaire_prescrit(self):
new_val_lineaire_prescrit = self.dlg.lin_prescrit.text()
return new_val_lineaire_prescrit
def lineaire_unite(self):
new_val_lin_unite = self.dlg.line_unite.currentText()
return new_val_lin_unite
def nb_point_prescrit(self):
new_val_nb_point_prescrit = self.dlg.nb_point_prescrit.text()
return new_val_nb_point_prescrit
#ORE : renvoie true ou false
def ORE(self):
new_val_ORE = self.dlg.ORE.isChecked()
return new_val_ORE
def distance_tampon_point(self):
s= QSettings()
new_val_distance_point = self.dlg.distance_tampon_point.text()
s.setValue('/GeoMCE-distance_tampon_point', new_val_distance_point)
return new_val_distance_point
def distance_tampon_ligne(self):
s= QSettings()
new_val_distance_ligne = self.dlg.distance_tampon_ligne.text()
s.setValue('/GeoMCE-distance_tampon_ligne', new_val_distance_ligne)
return new_val_distance_ligne
def sauv_dist_tampon(self):
self.distance_tampon_ligne()
self.distance_tampon_point()
self.iface.messageBar().pushMessage(u'GéoMCE',u'Paramètres sauvegardés', level=Qgis.Info, duration=3)
#genere les dates d echeances des suivis au format dd/mm/YYYY selon la date definies dans le cadre idoine
def date(self):
date_ech = [u'0',u'1',u'2',u'3',u'4',u'5',u'6',u'7',u'8',u'9',u'10',u'15',u'20',u'25',u'30',u'35',u'40',u'45',u'50']
new_date_ech = self.dlg.date_echeance.checkedItems()
delivrance = self.dlg.delivrance.date()
date =""
for i in new_date_ech:
date += delivrance.addYears(int(i)).toString(Qt.LocaleDate)+"|"
return date
#selection des toutes les entites de la couche
def select_all(self):
self.selectall = 0
layername = self.dlg.mMapLayerComboBox.currentLayer()
for name, selectlayer in QgsProject.instance().mapLayers().items():
if selectlayer.name() == layername:
selectlayer.setSelectedFeatures([])
selectlayer.invertSelection()
self.selectall = 1
#application des nouvelles valeurs dans la nouvelle table attributaire y compris le tampon si option cochee
def change_to_any(self):
kiki = self.dlg.mMapLayerComboBox.currentLayer()
source_chemin_couche = kiki.dataProvider().dataSourceUri()
(head, tail) = os.path.split(source_chemin_couche)
(name, ext) = os.path.splitext(tail)
format = ext.split('|',1)
#on traite ce qui peut l etre
if format[0]==('.shp'):
if kiki.wkbType()==1 or kiki.wkbType()==2 or kiki.wkbType()==3 or kiki.wkbType()==5 or kiki.wkbType()==6:
source_chemin_couche = kiki.dataProvider().dataSourceUri()
chemin_tampon = os.path.dirname(source_chemin_couche)
nom_couche= self.dlg.mMapLayerComboBox.currentText()
path = chemin_tampon+"/"+nom_couche+"_TAMPON"
shape= path+'.shp'
gpkg= path+'.gpkg'
distance_point = self.distance_tampon_point()
distance_ligne = self.distance_tampon_ligne()
#on cree les tampons si options cochees
if self.dlg.tampon.isChecked() :
if kiki.geometryType()==QgsWkbTypes.PointGeometry:
tampon = processing.run('qgis:buffer',{'INPUT': kiki,'DISTANCE': distance_point,'SEGMENTS': 5,'DISSOLVE': True,'END_CAP_STYLE': 0,'JOIN_STYLE': 0,'MITER_LIMIT': 2,'OUTPUT': path})
#layer = tampon['OUTPUT']
if self.dlg.checkBox.isChecked():
layer = iface.addVectorLayer(shape, "", "ogr")
layer.startEditing()
prov = layer.dataProvider()
field_names = [field.name() for field in prov.fields()]
for count, f in enumerate(field_names):
jean = range(count, count +1 )
paul = range(count)
jeanpaul = list(range(count, count +1 )) + list (range(count))
layer.dataProvider().deleteAttributes(jeanpaul)
#... et creation des nouveaux champs compatibles avec un import dans GeoMCE
if self.dlg.maj.isChecked():
layer.dataProvider().addAttributes(
[QgsField("id", QVariant.Int,'Integer64',10,0),
QgsField("nom", QVariant.String,'String',100,0),
QgsField("categorie", QVariant.String,'String',7,0),
QgsField("cible", QVariant.String,'String',100,0),
QgsField("descriptio", QVariant.String,'String',254,0),
QgsField("decision", QVariant.String,'String',254,0),
QgsField("refei", QVariant.String,'String',254,0)])
else:
layer.dataProvider().addAttributes(
[QgsField("id", QVariant.Int,'Integer64',10,0),
QgsField("nom", QVariant.String,'String',100,0),
QgsField("categorie", QVariant.String,'String',7,0),
QgsField("cible", QVariant.String,'String',100,0),
QgsField("descriptio", QVariant.String,'String',254,0),
QgsField("decision", QVariant.String,'String',254,0),
QgsField("refei", QVariant.String,'String',254,0),
QgsField("duree", QVariant.String,'String',25,0),
QgsField("unite", QVariant.String,'String',25,0),
QgsField("modalite", QVariant.String,'String',50,0),
QgsField("cout",QVariant.Int,'Integer64', 10,0),
QgsField("montant_pr",QVariant.Int,'Integer64', 10,0),
QgsField("faunes",QVariant.String, 'String', 254,0),
QgsField("flores",QVariant.String, 'String', 254,0),
QgsField("echeances",QVariant.String, 'String', 254,0),
QgsField("communes", QVariant.String,'String',220,0)])#,
#QgsField("surface",QVariant.String, 'String', 10,2),
#QgsField("surf_unite",QVariant.String, 'String', 50,0),
#QgsField("lineaire",QVariant.String,'String', 10,2),
#QgsField("lin_unite",QVariant.String, 'String', 50,0),
#QgsField("nb_point",QVariant.Int,'Integer64', 10,0),
#QgsField("ore",QVariant.String, 'String', 5,0),
#QgsField("date_eche",QVariant.String, 'String', 254,0)])
layer.updateFields()
#prise en compte de l option sortie gpkg
else :
dede = QgsVectorLayer(gpkg, "", "ogr")
zaza = QgsVectorFileWriter.writeAsVectorFormat(dede,path,'UTF-8',dede.crs(), "ESRI Shapefile")
layer = iface.addVectorLayer(shape, "", "ogr")
layer.startEditing()
prov = layer.dataProvider()
field_names = [field.name() for field in prov.fields()]
for count, f in enumerate(field_names):
jean = range(count, count +1 )
paul = range(count)
jeanpaul = list(range(count, count +1 )) + list (range(count))
layer.dataProvider().deleteAttributes(jeanpaul)
#... et creation des nouveaux champs compatibles avec un import dans GeoMCE
if self.dlg.maj.isChecked():
layer.dataProvider().addAttributes(
[QgsField("id", QVariant.Int,'Integer64',10,0),
QgsField("nom", QVariant.String,'String',100,0),
QgsField("categorie", QVariant.String,'String',7,0),
QgsField("cible", QVariant.String,'String',100,0),
QgsField("descriptio", QVariant.String,'String',254,0),
QgsField("decision", QVariant.String,'String',254,0),
QgsField("refei", QVariant.String,'String',254,0)])
else:
layer.dataProvider().addAttributes(
[QgsField("id", QVariant.Int,'Integer64',10,0),
QgsField("nom", QVariant.String,'String',100,0),
QgsField("categorie", QVariant.String,'String',7,0),
QgsField("cible", QVariant.String,'String',100,0),
QgsField("descriptio", QVariant.String,'String',254,0),
QgsField("decision", QVariant.String,'String',254,0),
QgsField("refei", QVariant.String,'String',254,0),
QgsField("duree", QVariant.String,'String',25,0),
QgsField("unite", QVariant.String,'String',25,0),
QgsField("modalite", QVariant.String,'String',50,0),
QgsField("cout",QVariant.Int,'Integer64', 10,0),
QgsField("montant_pr",QVariant.Int,'Integer64', 10,0),
QgsField("faunes",QVariant.String, 'String', 254,0),
QgsField("flores",QVariant.String, 'String', 254,0),
QgsField("echeances",QVariant.String, 'String', 254,0),
QgsField("communes", QVariant.String,'String',220,0)])#,
#QgsField("surface",QVariant.String, 'String', 10,2),
#QgsField("surf_unite",QVariant.String, 'String', 50,0),
#QgsField("lineaire",QVariant.String,'String', 10,2),
#QgsField("lin_unite",QVariant.String, 'String', 50,0),
#QgsField("nb_point",QVariant.Int,'Integer64', 10,0),
#QgsField("ore",QVariant.String, 'String', 5,0),
#QgsField("date_eche",QVariant.String, 'String', 254,0)])
layer.updateFields()
elif kiki.geometryType()== QgsWkbTypes.LineGeometry:
tampon = processing.run('qgis:buffer',{'INPUT': kiki,'DISTANCE': distance_ligne,'SEGMENTS': 5,'DISSOLVE': True,'END_CAP_STYLE': 0,'JOIN_STYLE': 0,'MITER_LIMIT': 2,'OUTPUT': path})
#layer = tampon['OUTPUT']
if self.dlg.checkBox.isChecked():
layer = iface.addVectorLayer(shape, "", "ogr")
layer.startEditing()
prov = layer.dataProvider()
field_names = [field.name() for field in prov.fields()]
for count, f in enumerate(field_names):
jean = range(count, count +1 )
paul = range(count)
jeanpaul = list(range(count, count +1 )) + list (range(count))
layer.dataProvider().deleteAttributes(jeanpaul)
#... et creation des nouveaux champs compatibles avec un import dans GeoMCE
if self.dlg.maj.isChecked():
layer.dataProvider().addAttributes(
[QgsField("id", QVariant.Int,'Integer64',10,0),
QgsField("nom", QVariant.String,'String',100,0),
QgsField("categorie", QVariant.String,'String',7,0),
QgsField("cible", QVariant.String,'String',100,0),
QgsField("descriptio", QVariant.String,'String',254,0),
QgsField("decision", QVariant.String,'String',254,0),
QgsField("refei", QVariant.String,'String',254,0)])
else:
layer.dataProvider().addAttributes(
[QgsField("id", QVariant.Int,'Integer64',10,0),
QgsField("nom", QVariant.String,'String',100,0),
QgsField("categorie", QVariant.String,'String',7,0),
QgsField("cible", QVariant.String,'String',100,0),
QgsField("descriptio", QVariant.String,'String',254,0),
QgsField("decision", QVariant.String,'String',254,0),
QgsField("refei", QVariant.String,'String',254,0),
QgsField("duree", QVariant.String,'String',25,0),
QgsField("unite", QVariant.String,'String',25,0),
QgsField("modalite", QVariant.String,'String',50,0),
QgsField("cout",QVariant.Int,'Integer64', 10,0),
QgsField("montant_pr",QVariant.Int,'Integer64', 10,0),
QgsField("faunes",QVariant.String, 'String', 254,0),
QgsField("flores",QVariant.String, 'String', 254,0),
QgsField("echeances",QVariant.String, 'String', 254,0),
QgsField("communes", QVariant.String,'String',220,0)])#,
#QgsField("surface",QVariant.String, 'String', 10,2),
#QgsField("surf_unite",QVariant.String, 'String', 50,0),
#QgsField("lineaire",QVariant.String,'String', 10,2),
#QgsField("lin_unite",QVariant.String, 'String', 50,0),
#QgsField("nb_point",QVariant.Int,'Integer64', 10,0),
#QgsField("ore",QVariant.String, 'String', 5,0),
#QgsField("date_eche",QVariant.String, 'String', 254,0)])
layer.updateFields()
else :
dede = QgsVectorLayer(gpkg, "", "ogr")
zaza = QgsVectorFileWriter.writeAsVectorFormat(dede,path,'UTF-8',dede.crs(), "ESRI Shapefile")
layer = iface.addVectorLayer(shape, "", "ogr")
layer.startEditing()
prov = layer.dataProvider()
field_names = [field.name() for field in prov.fields()]
for count, f in enumerate(field_names):
jean = range(count, count +1 )
paul = range(count)
jeanpaul = list(range(count, count +1 )) + list (range(count))
layer.dataProvider().deleteAttributes(jeanpaul)
#... et creation des nouveaux champs compatibles avec un import dans GeoMCE
if self.dlg.maj.isChecked():
layer.dataProvider().addAttributes(
[QgsField("id", QVariant.Int,'Integer64',10,0),
QgsField("nom", QVariant.String,'String',100,0),
QgsField("categorie", QVariant.String,'String',7,0),
QgsField("cible", QVariant.String,'String',100,0),
QgsField("descriptio", QVariant.String,'String',254,0),
QgsField("decision", QVariant.String,'String',254,0),
QgsField("refei", QVariant.String,'String',254,0)])
else:
layer.dataProvider().addAttributes(
[QgsField("id", QVariant.Int,'Integer64',10,0),
QgsField("nom", QVariant.String,'String',100,0),
QgsField("categorie", QVariant.String,'String',7,0),
QgsField("cible", QVariant.String,'String',100,0),
QgsField("descriptio", QVariant.String,'String',254,0),
QgsField("decision", QVariant.String,'String',254,0),
QgsField("refei", QVariant.String,'String',254,0),
QgsField("duree", QVariant.String,'String',25,0),
QgsField("unite", QVariant.String,'String',25,0),
QgsField("modalite", QVariant.String,'String',50,0),
QgsField("cout",QVariant.Int,'Integer64', 10,0),
QgsField("montant_pr",QVariant.Int,'Integer64', 10,0),
QgsField("faunes",QVariant.String, 'String', 254,0),
QgsField("flores",QVariant.String, 'String', 254,0),
QgsField("echeances",QVariant.String, 'String', 254,0),
QgsField("communes", QVariant.String,'String',220,0)])#,
#QgsField("surface",QVariant.String, 'String', 10,2),
#QgsField("surf_unite",QVariant.String, 'String', 50,0),
#QgsField("lineaire",QVariant.String,'String', 10,2),
#QgsField("lin_unite",QVariant.String, 'String', 50,0),
#QgsField("nb_point",QVariant.Int,'Integer64', 10,0),
#QgsField("ore",QVariant.String, 'String', 5,0),
#QgsField("date_eche",QVariant.String, 'String', 254,0)])
layer.updateFields()
else:
layer = self.dlg.mMapLayerComboBox.currentLayer()
else :
layer = self.dlg.mMapLayerComboBox.currentLayer()
#on recupere l ensemble des valeurs saisies
val1 = self.get_new_nom()
if self.dlg.maj.isChecked():
val2 = "-"
val3 = "-"
val4 = "-"
val5 = "-"
val6 = "-"
val7 = "-"
val8 = "-"
val9 = "-"
val10 = "-"
val11 = "-"
val12 = "-"
val13 = "-"
val14 = "-"
val15 = "-"
#on change les virgules en points
val16 = "0"
val17 = "-"
val18 = "0"
val19 = "-"
val20 = "0"
val21 = "-"
valdate = "-"
val22 = "-"
else :
val2 = self.get_description()
val3 = self.get_decision()
val4 = self.get_refei()
val5 = self.get_duree()
val6 = self.get_categorie()
val7 = self.get_cible()
val8 = self.get_unite()
val9 = self.get_modalite()
val10 = self.get_cout()
val11 = self.get_montant()
val12 = self.get_faunes()
val13 = self.get_flores()
val14 = self.get_echeances()
val15 = self.codeinsee()
valsurf = self.surface_prescrite()
#on change les virgules en points
val16 = valsurf.replace(',','.')
val17 = self.surface_unite()
vallin = self.lineaire_prescrit()
val18 = vallin.replace(',','.')
val19 = self.lineaire_unite()
val20 = self.nb_point_prescrit()
val21 = self.dlg.ORE.isChecked()
valdate = self.date()
val22 = valdate[:-1]
#on ecrit les valeurs.Si tampon active, ces valeurs sont ecrites 2 fois
if self.dlg.tampon.isChecked():
for feat in layer.getFeatures():
layer.changeAttributeValue(feat.id(),0,feat.id())
if val1 == "":
layer.changeAttributeValue(feat.id(),1,"-")
else :
layer.changeAttributeValue(feat.id(),1,val1)
if val6 == "":
layer.changeAttributeValue(feat.id(),2,"E")
else :
layer.changeAttributeValue(feat.id(),2, val6)
if val7 == "":
layer.changeAttributeValue(feat.id(),3,"Habitats naturels")
else :
layer.changeAttributeValue(feat.id(),3, val7)
if val2 == "":
layer.changeAttributeValue(feat.id(),4,"-")
else :
layer.changeAttributeValue(feat.id(),4,val2)
if val3 == "":
layer.changeAttributeValue(feat.id(),5,"-")
else :
layer.changeAttributeValue(feat.id(),5,val3)
if val4 == "":
layer.changeAttributeValue(feat.id(),6,"-")
else :
layer.changeAttributeValue(feat.id(),6,val4)
if val5 == "":
layer.changeAttributeValue(feat.id(),7,"-")
else :
layer.changeAttributeValue(feat.id(),7,val5)
layer.changeAttributeValue(feat.id(),8, val8)
layer.changeAttributeValue(feat.id(),9, val9)
if val10 == "":
layer.changeAttributeValue(feat.id(),10,"")
else :
layer.changeAttributeValue(feat.id(),10,val10)
if val11 == "":
layer.changeAttributeValue(feat.id(),11,"")
else :
layer.changeAttributeValue(feat.id(),11,val11)
if val12 == "":
layer.changeAttributeValue(feat.id(),12,"")
else :
layer.changeAttributeValue(feat.id(),12,val12)
if val13 == "":
layer.changeAttributeValue(feat.id(),13,"")
else :
layer.changeAttributeValue(feat.id(),13,val13)
if val14 == "":
layer.changeAttributeValue(feat.id(),14,"")
else :
layer.changeAttributeValue(feat.id(),14,val14)
if self.get_communes()=="":
layer.changeAttributeValue(feat.id(),15, "")
else :
layer.changeAttributeValue(feat.id(),15, val15)
if val16 == "":
layer.changeAttributeValue(feat.id(),16,"0")
else :
layer.changeAttributeValue(feat.id(),16,val16)
layer.changeAttributeValue(feat.id(),17,val17)
if val18 == "":
layer.changeAttributeValue(feat.id(),18,"0")
else :
layer.changeAttributeValue(feat.id(),18,val18)
layer.changeAttributeValue(feat.id(),19,val19)
if val20 == "":
layer.changeAttributeValue(feat.id(),20,"")
else :
layer.changeAttributeValue(feat.id(),20,val20)
layer.changeAttributeValue(feat.id(),21,val21)
if val22 == "":
layer.changeAttributeValue(feat.id(),22,"")
else :
layer.changeAttributeValue(feat.id(),22,val22)
for feat in kiki.getFeatures():
kiki.changeAttributeValue(feat.id(),0,feat.id())
if val1 == "":
kiki.changeAttributeValue(feat.id(),1,"-")
else :
kiki.changeAttributeValue(feat.id(),1,val1)
if val6 == "":
kiki.changeAttributeValue(feat.id(),2,"E")
else :
kiki.changeAttributeValue(feat.id(),2, val6)
if val7 == "":
kiki.changeAttributeValue(feat.id(),3,"Habitats naturels")
else :
kiki.changeAttributeValue(feat.id(),3, val7)
if val2 == "":
kiki.changeAttributeValue(feat.id(),4,"-")