Commit b37cdd15 authored by Alice Salsé's avatar Alice Salsé
Browse files

🔨 find layer selection key

parent 627bf103
......@@ -166,11 +166,16 @@ class NetworkTools:
def activeLayerSelection(self) :
layer = self.iface.activeLayer()
if not layer :
if not layer:
self.iface.messageBar().pushMessage("Veuillez sélectionner une couche d'abord", Qgis.Warning)
return
l_pks = layer.primaryKeyAttributes()
if len(l_pks) < 1 :
self.iface.messageBar().pushMessage("La couche sélectionnée n'a pas de clé unique", Qgis.Warning)
return
else :
l_ids = [f["id"] for f in layer.selectedFeatures()]
l_pk=layer.fields().names()[l_pks[0]]
l_ids = [f[l_pk] for f in layer.selectedFeatures()]
if l_ids:
return layer.id(), l_ids
else :
......@@ -180,13 +185,16 @@ class NetworkTools:
def allLayerSelection(self) :
lyrs = {}
for layer in [l.layer() for l in self.root.findLayers() if l.layer().type() == QgsMapLayerType.VectorLayer] : ## 0 = VectorLayer
layer_id=layer.id()
l_ids = [f["id"] for f in layer.selectedFeatures()]
if l_ids:
if layer_id in lyrs :
lyrs[layer_id] = list(set(lyrs[layer_id] + l_ids))
else :
lyrs[layer_id] = l_ids
l_pks = layer.primaryKeyAttributes()
if len(l_pks) > 0 :
layer_id=layer.id()
l_pk=layer.fields().names()[l_pks[0]]
l_ids = [f[l_pk] for f in layer.selectedFeatures()]
if l_ids:
if layer_id in lyrs :
lyrs[layer_id] = list(set(lyrs[layer_id] + l_ids))
else :
lyrs[layer_id] = l_ids
return lyrs
def mergePipes(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment