Example API

This is an example of what your API will look like.

Python code

———————————————————————————————————————-
Date : October 2020 todo: change date, copyright and email in all files
Copyright : © 2020 by Ann Crabbé
Acknowledgements : Based on ‘Create A QGIS Plugin’ [https://bitbucket.org/kul-reseco/create-qgis-plugin]
Crabbé Ann and Somers Ben; funded by BELSPO STEREO III (Project LUMOS - SR/01/321)

This file is part of the [INSERT PLUGIN NAME] plugin and [INSERT PYTHON PACKAGE NAME] python package.
todo: make sure to fill out your plugin name and python package name here.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation, either version 3 of the License, or any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License (COPYING.txt). If not see www.gnu.org/licenses.
———————————————————————————————————————-
class qgisplugin.core.my_code.MyCode(image: numpy.ndarray, normalize: bool = False, quotient: int = 255)[source]

Bases: object

todo: Give a short summary of what this code does here.

e.g.: This script is a super simple example of a set of functions: one to multiply an image with a factor, one to add a constant to an entire image and one to set all values below a threshold to 0.

This script only contains the mathematical part of your code and should be completely independent of i/o. You start from matrices, integers and other variables, and not from files or widgets!

add_to_image(constant: float) → numpy.ndarray[source]

Add a constant to an image.

Parameters:constant – The constant to add to each pixel of the image.
Returns:The new image.
execute(constant: float, threshold: float, set_progress: callable = None, log: callable = <built-in function print>) → numpy.ndarray[source]

This part is usually the core of your plugin: this function is called when the user clicks “run”.

Here we don’t do anything special: we add a number to an image and then set all values in an image to 0 where they are below a given threshold.

Parameters:
  • constant – The constant to add to each pixel of the image.
  • threshold – all values below this threshold are set to 0
  • set_progress – communicate progress (refer to the progress bar in case of GUI; otherwise print to console)
  • log – communicate messages (refer to the print_log tab in the GUI; otherwise print to the console)
Returns:

the new image

qgisplugin.core.my_code.printProgress(value: int)[source]

Replacement for the GUI progress bar

Command Line Interface

todo: Give a short summary of what this code does here.

e.g.: This script is a super simple example of a set of functions: one to multiply an image with a factor, one to add a constant to an entire image and one to set all values below a threshold to 0.

This script only contains the mathematical part of your code and should be completely independent of i/o. You start from matrices, integers and other variables, and not from files or widgets!

usage: mycli [-h] [-n N] [-c C] [-t T] [-o O] image

Positional Arguments

image Path to the input image.

Named Arguments

-n To normalize your image, set the quotient here. (default: not set)
-c

Add this constant to the image (default: 0.01).

Default: 0.01

-t

Threshold for setting cells to 0 (default: 0.2).

Default: 0.2

-o Output file (default: in same folder with name ‘output.tif’