I need a list containing all the vector layers in a QGIS session. I have this code to get all layers, how can I put a filter to get only vector layers?

layers = QgsProject.instance().mapLayers().values()

Use a list comprehension and filter only vector layers:

layers = [l for l in QgsProject.instance().mapLayers().values() if l.type() == QgsVectorLayer.VectorLayer]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.