Skip to content

Commit 3520724

Browse files
committed
Import - MAJIC: détection automatique des fichiers dans le répertoire
1 parent 9a559ce commit 3520724

9 files changed

Lines changed: 360 additions & 189 deletions

File tree

cadastre/cadastre_import.py

Lines changed: 203 additions & 118 deletions
Large diffs are not rendered by default.

cadastre/definitions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,17 @@
33
)
44

55
URL_DOCUMENTATION = "https://docs.3liz.org/QgisCadastrePlugin/"
6+
7+
REGEX_BATI = "BATI"
8+
REGEX_FANTOIR = "FANTOIR|FANR"
9+
REGEX_LOTLOCAL = "LLOC|D166"
10+
REGEX_NBATI = "NBAT"
11+
REGEX_PDL = "PDL"
12+
REGEX_PROP = "PROP"
13+
14+
IMPORT_MEMORY_ERROR_MESSAGE = "<b>ERREUR : Mémoire</b></br>"
15+
"Veuillez recommencer l'import en baissant la valeur du "
16+
"paramètre <b>'Taille maximum des requêtes INSERT'</b> selon la "
17+
"documentation : {}/extension-qgis/configuration/#performances</br>".format(
18+
URL_DOCUMENTATION
19+
)

cadastre/dialogs/dialog_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def check_database_for_existing_structure(self):
274274
self.dialog.hasMajicData = has_majic_data
275275
self.dialog.hasMajicDataParcelle = has_majic_data_parcelle
276276
self.dialog.hasMajicDataProp = has_majic_data_prop
277-
self.dialog.hasMajicData = has_majic_data_voie
277+
self.dialog.hasMajicDataVoie = has_majic_data_voie
278278

279279
def checkDatabaseForExistingTable(self, tableName, schemaName=''):
280280
"""

cadastre/dialogs/import_dialog.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,13 @@ def chooseDataPath(self, key):
180180
Ask the user to select a folder
181181
and write down the path to appropriate field
182182
"""
183+
root_directory = str(self.pathSelectors[key]['input'].text()).strip(' \t')
184+
if not root_directory:
185+
root_directory = os.path.expanduser("~")
183186
ipath = QFileDialog.getExistingDirectory(
184187
None,
185188
"Choisir le répertoire contenant les fichiers",
186-
str(self.pathSelectors[key]['input'].text().encode('utf-8')).strip(' \t')
189+
root_directory
187190
)
188191
if os.path.exists(str(ipath)):
189192
self.pathSelectors[key]['input'].setText(str(ipath))

cadastre/dialogs/options_dialog.py

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
from qgis.PyQt.QtGui import QIcon
1313
from qgis.PyQt.QtWidgets import QDialog, QFileDialog, QMessageBox
1414

15+
from cadastre.definitions import (
16+
REGEX_BATI,
17+
REGEX_FANTOIR,
18+
REGEX_LOTLOCAL,
19+
REGEX_NBATI,
20+
REGEX_PDL,
21+
REGEX_PROP,
22+
)
1523
from cadastre.tools import set_window_title
1624

1725
OPTION_FORM_CLASS, _ = uic.loadUiType(
@@ -109,30 +117,30 @@ def getValuesFromSettings(self):
109117
from settings and set corresponding inputs
110118
"""
111119
s = QgsSettings()
112-
batiFileName = s.value("cadastre/batiFileName", 'REVBATI.800', type=str)
113-
if batiFileName:
114-
self.inMajicBati.setText(batiFileName)
115-
fantoirFileName = s.value("cadastre/fantoirFileName", 'TOPFANR.800', type=str)
116-
if fantoirFileName:
117-
self.inMajicFantoir.setText(fantoirFileName)
118-
lotlocalFileName = s.value("cadastre/lotlocalFileName", 'REVD166.800', type=str)
119-
if lotlocalFileName:
120-
self.inMajicLotlocal.setText(lotlocalFileName)
121-
nbatiFileName = s.value("cadastre/nbatiFileName", 'REVNBAT.800', type=str)
122-
if nbatiFileName:
123-
self.inMajicNbati.setText(nbatiFileName)
124-
pdlFileName = s.value("cadastre/pdlFileName", 'REVFPDL.800', type=str)
125-
if pdlFileName:
126-
self.inMajicPdl.setText(pdlFileName)
127-
propFileName = s.value("cadastre/propFileName", 'REVPROP.800', type=str)
128-
if propFileName:
129-
self.inMajicProp.setText(propFileName)
120+
regexBati = s.value("cadastre/regexBati", REGEX_BATI, type=str)
121+
if regexBati:
122+
self.inMajicBati.setText(regexBati)
123+
regexFantoir = s.value("cadastre/regexFantoir", REGEX_FANTOIR, type=str)
124+
if regexFantoir:
125+
self.inMajicFantoir.setText(regexFantoir)
126+
regexLotLocal = s.value("cadastre/regexLotLocal", REGEX_LOTLOCAL, type=str)
127+
if regexLotLocal:
128+
self.inMajicLotlocal.setText(regexLotLocal)
129+
regexNbati = s.value("cadastre/regexNbati", REGEX_NBATI, type=str)
130+
if regexNbati:
131+
self.inMajicNbati.setText(regexNbati)
132+
regexPdl = s.value("cadastre/regexPdl", REGEX_PDL, type=str)
133+
if regexPdl:
134+
self.inMajicPdl.setText(regexPdl)
135+
regexProp = s.value("cadastre/regexProp", REGEX_PROP, type=str)
136+
if regexProp:
137+
self.inMajicProp.setText(regexProp)
130138
tempDir = s.value("cadastre/tempDir", type=str)
131139
if tempDir and Path(tempDir).exists():
132140
self.inTempDir.setText(tempDir)
133141
else:
134142
self.inTempDir.setText(tempfile.gettempdir())
135-
maxInsertRows = s.value("cadastre/maxInsertRows", 100000, type=int)
143+
maxInsertRows = s.value("cadastre/maxInsertRows", 50000, type=int)
136144
if maxInsertRows:
137145
self.inMaxInsertRows.setValue(maxInsertRows)
138146
spatialiteTempStore = s.value("cadastre/spatialiteTempStore", 'MEMORY', type=str)
@@ -183,12 +191,12 @@ def onAccept(self):
183191

184192
# Save Majic file names
185193
s = QgsSettings()
186-
s.setValue("cadastre/batiFileName", self.inMajicBati.text().strip(' \t\n\r'))
187-
s.setValue("cadastre/fantoirFileName", self.inMajicFantoir.text().strip(' \t\n\r'))
188-
s.setValue("cadastre/lotlocalFileName", self.inMajicLotlocal.text().strip(' \t\n\r'))
189-
s.setValue("cadastre/nbatiFileName", self.inMajicNbati.text().strip(' \t\n\r'))
190-
s.setValue("cadastre/pdlFileName", self.inMajicPdl.text().strip(' \t\n\r'))
191-
s.setValue("cadastre/propFileName", self.inMajicProp.text().strip(' \t\n\r'))
194+
s.setValue("cadastre/regexBati", self.inMajicBati.text().strip(' \t\n\r'))
195+
s.setValue("cadastre/regexFantoir", self.inMajicFantoir.text().strip(' \t\n\r'))
196+
s.setValue("cadastre/regexLotLocal", self.inMajicLotlocal.text().strip(' \t\n\r'))
197+
s.setValue("cadastre/regexNbati", self.inMajicNbati.text().strip(' \t\n\r'))
198+
s.setValue("cadastre/regexPdl", self.inMajicPdl.text().strip(' \t\n\r'))
199+
s.setValue("cadastre/regexProp", self.inMajicProp.text().strip(' \t\n\r'))
192200

193201
# Save temp dir
194202
s.setValue("cadastre/tempDir", self.inTempDir.text().strip(' \t\n\r'))

cadastre/forms/cadastre_import_form.ui

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>720</width>
10-
<height>694</height>
10+
<height>883</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -24,8 +24,8 @@
2424
<rect>
2525
<x>0</x>
2626
<y>0</y>
27-
<width>686</width>
28-
<height>691</height>
27+
<width>700</width>
28+
<height>830</height>
2929
</rect>
3030
</property>
3131
<layout class="QVBoxLayout" name="verticalLayout_6">
@@ -449,8 +449,8 @@
449449
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
450450
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
451451
p, li { white-space: pre-wrap; }
452-
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
453-
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
452+
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu Sans'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
453+
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu';&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
454454
</property>
455455
<property name="acceptRichText">
456456
<bool>true</bool>
@@ -493,5 +493,6 @@ p, li { white-space: pre-wrap; }
493493
<header>qgis.gui</header>
494494
</customwidget>
495495
</customwidgets>
496+
<resources/>
496497
<connections/>
497498
</ui>

cadastre/forms/cadastre_option_form.ui

Lines changed: 81 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>543</width>
10-
<height>663</height>
10+
<height>825</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -25,7 +25,7 @@
2525
<x>0</x>
2626
<y>0</y>
2727
<width>523</width>
28-
<height>643</height>
28+
<height>805</height>
2929
</rect>
3030
</property>
3131
<layout class="QVBoxLayout" name="verticalLayout_2">
@@ -69,25 +69,88 @@
6969
<item>
7070
<widget class="QGroupBox" name="groupBox">
7171
<property name="title">
72-
<string>Nom des fichiers MAJIC</string>
72+
<string>Mot-clés pour trouver les fichiers MAJIC</string>
7373
</property>
7474
<layout class="QVBoxLayout" name="verticalLayout_3">
75+
<item>
76+
<widget class="QLabel" name="label_9">
77+
<property name="text">
78+
<string>Cette configuration permet de définir comment le plugin trouve les fichiers dans le répertoire MAJIC, en fonction de chaque type de fichier. Un simple mot ou une expression régulière peuvent être utilisés.</string>
79+
</property>
80+
<property name="wordWrap">
81+
<bool>true</bool>
82+
</property>
83+
</widget>
84+
</item>
7585
<item>
7686
<layout class="QGridLayout" name="gridLayout">
87+
<item row="5" column="2">
88+
<widget class="QLineEdit" name="inMajicProp">
89+
<property name="text">
90+
<string>PROP</string>
91+
</property>
92+
</widget>
93+
</item>
94+
<item row="4" column="0">
95+
<widget class="QLabel" name="label_6">
96+
<property name="text">
97+
<string>PDL</string>
98+
</property>
99+
</widget>
100+
</item>
101+
<item row="6" column="0">
102+
<widget class="QLabel" name="label_10">
103+
<property name="text">
104+
<string>TOPO</string>
105+
</property>
106+
</widget>
107+
</item>
77108
<item row="0" column="0">
78109
<widget class="QLabel" name="label">
79110
<property name="text">
80111
<string>BATI</string>
81112
</property>
82113
</widget>
83114
</item>
84-
<item row="0" column="1">
85-
<widget class="QLineEdit" name="inMajicBati"/>
115+
<item row="0" column="2">
116+
<widget class="QLineEdit" name="inMajicBati">
117+
<property name="text">
118+
<string>BATI</string>
119+
</property>
120+
</widget>
86121
</item>
87-
<item row="1" column="0">
88-
<widget class="QLabel" name="label_2">
122+
<item row="4" column="2">
123+
<widget class="QLineEdit" name="inMajicPdl">
89124
<property name="text">
90-
<string>FANTOIR</string>
125+
<string>PDL</string>
126+
</property>
127+
</widget>
128+
</item>
129+
<item row="5" column="0">
130+
<widget class="QLabel" name="label_5">
131+
<property name="text">
132+
<string>PROP</string>
133+
</property>
134+
</widget>
135+
</item>
136+
<item row="3" column="2">
137+
<widget class="QLineEdit" name="inMajicNbati">
138+
<property name="text">
139+
<string>NBAT</string>
140+
</property>
141+
</widget>
142+
</item>
143+
<item row="2" column="2">
144+
<widget class="QLineEdit" name="inMajicLotlocal">
145+
<property name="text">
146+
<string>LLOC|D166</string>
147+
</property>
148+
</widget>
149+
</item>
150+
<item row="6" column="2">
151+
<widget class="QLineEdit" name="lineEdit">
152+
<property name="text">
153+
<string>TOPO</string>
91154
</property>
92155
</widget>
93156
</item>
@@ -98,42 +161,27 @@
98161
</property>
99162
</widget>
100163
</item>
101-
<item row="5" column="1">
102-
<widget class="QLineEdit" name="inMajicProp"/>
103-
</item>
104-
<item row="2" column="1">
105-
<widget class="QLineEdit" name="inMajicLotlocal"/>
106-
</item>
107164
<item row="2" column="0">
108165
<widget class="QLabel" name="label_3">
109166
<property name="text">
110167
<string>LOTLOCAL</string>
111168
</property>
112169
</widget>
113170
</item>
114-
<item row="1" column="1">
115-
<widget class="QLineEdit" name="inMajicFantoir"/>
116-
</item>
117-
<item row="3" column="1">
118-
<widget class="QLineEdit" name="inMajicNbati"/>
119-
</item>
120-
<item row="5" column="0">
121-
<widget class="QLabel" name="label_5">
171+
<item row="7" column="2">
172+
<widget class="QLineEdit" name="inMajicFantoir">
122173
<property name="text">
123-
<string>PROP</string>
174+
<string>FANTOIR|FANR</string>
124175
</property>
125176
</widget>
126177
</item>
127-
<item row="4" column="0">
128-
<widget class="QLabel" name="label_6">
178+
<item row="7" column="0">
179+
<widget class="QLabel" name="label_2">
129180
<property name="text">
130-
<string>PDL</string>
181+
<string>FANTOIR</string>
131182
</property>
132183
</widget>
133184
</item>
134-
<item row="4" column="1">
135-
<widget class="QLineEdit" name="inMajicPdl"/>
136-
</item>
137185
</layout>
138186
</item>
139187
</layout>
@@ -196,7 +244,7 @@
196244
<item row="0" column="0">
197245
<widget class="QLabel" name="label_7">
198246
<property name="text">
199-
<string>Taille maximum des requêtes INSERT</string>
247+
<string>Nombre de lignes MAJIC insérées par lot</string>
200248
</property>
201249
</widget>
202250
</item>
@@ -257,18 +305,19 @@
257305
<tabstop>btInterfaceCadastre</tabstop>
258306
<tabstop>btInterfaceQgis</tabstop>
259307
<tabstop>inMajicBati</tabstop>
260-
<tabstop>inMajicFantoir</tabstop>
261308
<tabstop>inMajicLotlocal</tabstop>
262309
<tabstop>inMajicNbati</tabstop>
263310
<tabstop>inMajicPdl</tabstop>
264311
<tabstop>inMajicProp</tabstop>
312+
<tabstop>lineEdit</tabstop>
313+
<tabstop>inMajicFantoir</tabstop>
265314
<tabstop>inComposerTemplateFile</tabstop>
266315
<tabstop>btComposerTemplateFile</tabstop>
267316
<tabstop>inTempDir</tabstop>
268317
<tabstop>btTempDir</tabstop>
269318
<tabstop>inMaxInsertRows</tabstop>
270319
<tabstop>inSpatialiteTempStore</tabstop>
271-
<tabstop>buttonBox</tabstop>
272320
</tabstops>
321+
<resources/>
273322
<connections/>
274323
</ui>

docs/extension-qgis/configuration.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Configuration
22

3-
Avant d'importer les premières données cadastrales dans la base de données, il faut au préalable configurer
3+
Avant d'importer les premières données cadastrales dans la base de données, vous pouvez si vous le souhaitez configurer
44
l'extension :
55

66
* Menu **Cadastre ➡ Configurer le plugin** ou l'icône **outils** de la barre d'outil Cadastre.
@@ -16,15 +16,26 @@ interface simplifiée adaptée à une utilisation de consultation du Cadastre.
1616
fonctionnalité lorsque ce sera possible. En attendant, il faut donc le faire manuellement, comme expliqué dans
1717
la fenêtre d'aide.
1818

19-
## Nom des fichiers MAJIC
19+
## Mots-clés pour trouver les fichiers MAJIC
2020

21-
Cette partie permet de spécifier comment sont appelés les fichiers MAJIC sur votre poste de travail.
21+
Cette partie permet de spécifier **comment sont recherchés les fichiers MAJIC** sur votre poste de travail
22+
dans le répertoire que vous choisissez dans l'outil d'import.
2223

23-
En effet, les conventions de nommage peuvent changer d'un département à l'autre. Souvent, les fichiers se
24-
terminent par une extension relative au département et à la direction, par exemple `.800` pour les fichiers
25-
du département de la Somme.
24+
Pour chaque type de fichier (propriétés bâties, non bâties, propriétaires, etc.), un mot-clé,
25+
ou une liste de mots-clés séparés par `|` permettent de trouver les fichiers s'ils respectent
26+
les conventions classiques de nommage.
2627

27-
**Il est important de bien configurer ces noms de fichiers avant votre premier import.**
28+
Par exemple, les fichiers contenant les propriétaires peuvent s'appeller
29+
`REVPROP.txt` ou `ART.DC21.W19132.PROP.A2019.N000688`. Dans ce cas,
30+
il seront bien trouvés par le mot-clé `PROP`.
31+
32+
A noter :
33+
34+
* la recherche est **insensible à la casse**;
35+
* les mots-clés sont en fait des **expressions régulières**. Par exemple `LLOC|D166`, qui permet
36+
de trouver les fichiers des locaux, trouve les fichiers contenant `LLOC` ou `D166`.
37+
38+
**Le plugin propose les mots-clés les plus courants. Vous pouvez les modifier si vos fichiers sont nommés différemment.**
2839

2940
Si l'extension ne trouve pas les fichiers MAJIC pendant l'import, alors que vous aviez spécifié le bon
3041
répertoire d'import, un message vous avertira et vous proposera d'annuler l'import.
2.5 KB
Loading

0 commit comments

Comments
 (0)