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
https://github.com/NathanW2/parfait
https://github.com/qgis/pyqgis_wrappers
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?
Example:
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
No comments:
Post a Comment