-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
54 lines (48 loc) · 1.08 KB
/
Copy pathutils.py
File metadata and controls
54 lines (48 loc) · 1.08 KB
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
# -*- coding: utf-8 -*-
"""
utils.py — Petits utilitaires génériques sans dépendance à l'interface QGIS.
"""
from qgis.core import QgsMapLayer, QgsWkbTypes
from .qt_compat import qenum
# Caractères remplacés par "_" lors de la génération d'un nom de fichier sûr
_CARACTERES_SPECIAUX = [
" ",
"/",
"\\",
":",
"*",
"?",
'"',
"<",
">",
"|",
"é",
"è",
"ê",
"à",
"â",
"î",
"ô",
"û",
"ç",
"(",
")",
"[",
"]",
"{",
"}",
";",
",",
]
def clean_filename(name):
"""Convertit un nom de couche QGIS en nom de fichier sûr pour le système de fichiers."""
for char in _CARACTERES_SPECIAUX:
name = name.replace(char, "_")
while "__" in name:
name = name.replace("__", "_")
return name.strip("_")
def get_geometry_type(layer):
"""Retourne le type de géométrie lisible d'une couche QGIS (ou 'Inconnu')."""
if layer.type() != qenum(QgsMapLayer, "LayerType", "VectorLayer"):
return "Inconnu"
return QgsWkbTypes.geometryType(layer.wkbType())