I would like to rewrite some of my QGIS plugins to use more common functions used by all of my plugins.

There exist some older functions (GIS2) like



and something newer like

https://github.com/boundlessgeo/lib-qgis-commons https://pypi.org/project/qgiscommons/ or https://github.com/inasafe/inasafe/tree/master/safe/utilities

Are there any other known collections of PyQGIS3 common functions that can be used to do basic tasks like load vectorlayers, show comboboxes, create toolbar-actions or something like that without having to write these code-snippets everytime on your own?


If I want to lad a vectorlayer I can make use of the function load_layer from https://github.com/qgis/pyqgis_wrappers/blob/master/parfait/layer_wrappers.py

 def load_layer(filename, name = None):
    Tries to load a layer from the given file
    :param filename: the path to the file to load.
    :param name: the name to use for adding the layer to the current project.
    If not passed or None, it will use the filename basename
    name = name or os.path.splitext(os.path.basename(filename))[0]
    qgslayer = QgsVectorLayer(filename, name, 'ogr')
    if not qgslayer.isValid():
        qgslayer = QgsRasterLayer(filename, name)
        if not qgslayer.isValid():
            raise RuntimeError('Could not load layer: ' + unicode(filename))

return qgslayer

This question has an open bounty worth +50 reputation from markgraeflerland ending in 4 days.

This question has not received enough attention.

  • This is a very open ended question. I think there's a better chance to get an answer on the QGIS developer mailing list - if anything like that exists for QGIS3 – underdark 2 days ago

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.