[Qgis-user] layers not displayed in the layer window
Yoann QUENACH DE QUIVILLIC
yquenach at itlink.fr
Fri Aug 28 06:18:22 PDT 2020
Oh you're right, my mistake. Here is a slightly modified version of the
function that relies on the QgsLayerTree instead of the QgsCanvas. This one
won't remove layers that are only unchecked in the layer tree.
def remove_odd_layers():
project = QgsProject.instance()
project_layers = project.mapLayers().values()
tree_layers = [l.layer() for l in project.layerTreeRoot().findLayers()]
for layer in project_layers:
if layer not in tree_layers:
project.removeMapLayer(layer)
Regards,
Le jeu. 27 août 2020 à 22:03, Jens Beutmann <beutmann at arcor.de> a écrit :
> That seems to be working. Thanx a lot, Yoann!!!
> Before running the function, you have to switch on in the layer dialog all
> the layers you want to keep, because otherwise the function kills all
> layers that are not visible. But after doing that, I got the result I
> wanted.
> That helped me a lot!
>
>
> Am 27.08.2020 um 11:44 schrieb Yoann QUENACH DE QUIVILLIC:
>
> I had the exact same problem some time ago. The layers are present in the
> QgsProject, but not added to the QgsCanvas, so they don't appear in the
> Layer Panel but the entry is there in the Layer Styling Panel.
> You can use PyQGIS to solve it
> Here is a simple function that iters over the layers in the project, and
> removes the layers not present in the canvas:
>
> def remove_odd_layers():
> for layer in QgsProject.instance().mapLayers().values():
> if layer not in iface.mapCanvas().layers():
> QgsProject.instance().removeMapLayer(layer)
>
> remove_odd_layers ()
>
> Le dim. 23 août 2020 à 13:03, Jens Beutmann <beutmann at arcor.de> a écrit :
>
>> I got a problem with layers that are displayed in the layer design
>> dialog ("Layergestaltung" in German) but not in the layer window itself.
>> I would like to delete these layers but this is not possible. I opened
>> the project in QGIS 2.18 and in 3.10 and it happens in both versions.
>> Can anybody help?
>>
>>
>> --
>> Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
>> https://www.avast.com/antivirus
>>
>> _______________________________________________
>> Qgis-user mailing list
>> Qgis-user at lists.osgeo.org
>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
>
>
>
> --
>
> <https://www.itlink.fr/>
>
> Yoann Quenach de Quivillic
>
> Ingénieur d'étude
>
> www.itlink.fr
>
>
>
>
>
> ------------------------------
> [image: Avast logo] <https://www.avast.com/antivirus>
>
> Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
> www.avast.com <https://www.avast.com/antivirus>
>
> <#m_6622802105708209006_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
--
<https://www.itlink.fr/>
Yoann Quenach de Quivillic
Ingénieur d'étude
www.itlink.fr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20200828/496a65ac/attachment-0001.html>
More information about the Qgis-user
mailing list