QGIS for Devs: Unterschied zwischen den Versionen

Aus Geometa Lab OST
Zur Navigation springen Zur Suche springen
(fix bold text)
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
QGIS for Devs
See also:
See also:
* [http://dev.ifs.hsr.ch/ Developer Wiki for Python Programming for (Q)GIS ('python4gis')]
* [http://dev.ifs.hsr.ch/ Developer Wiki for Python Programming for (Q)GIS ('python4gis')]


== Setting up a QGIS IDE ==
<h1> Setting up a QGIS IDE </h1>
The [https://code.visualstudio.com/ Visual Studio Code IDE] is a free, and lightweight editor with advanced debugging tools, including extensions tailored for Python and QGIS development. It also supports version control and code formatting, making plugin development more efficient.
The [https://code.visualstudio.com/ Visual Studio Code IDE] is a free, and lightweight editor with advanced debugging tools, including extensions tailored for Python and QGIS development. It also supports version control and code formatting, making plugin development more efficient.



Version vom 22. Januar 2025, 10:07 Uhr

See also:

Setting up a QGIS IDE

The Visual Studio Code IDE is a free, and lightweight editor with advanced debugging tools, including extensions tailored for Python and QGIS development. It also supports version control and code formatting, making plugin development more efficient.

There is the Plugin Reloader plugin to easily apply your code changes without restarting QGIS. This greatly speeds up debugging and iteration, making development smoother.


The plugin development cycle:

  • Modify the Python files of the AIAMAS plugin.
  • Save changes in VSCode.
  • Use the Plugin Reloader to apply changes instantly.


Manual installation of a python plugin

Die manuelle Installation eines Python-Plugins, das sich noch nicht in einem Repository befindet, passiert wie folgt:

Clone das Repository oder erstelle ein Plugin an einem beliebigen Ort. Plugins are stored in QGIS by default in the folder python\plugins. This folder is located within the user-specific QGIS profile directory.

On Windows, the full path is typically: ``C:\Users\Username\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins``

Here, ``Username`` represents your Windows username. The AppData\Roaming folder is hidden by default, so you may need to enable "Show hidden files" in Windows Explorer to access it. You could also write ``%appdata%`` in the explorer search bar, and then go back once to be in Appdata. In den default\python\plugins folder gehören alle Plugins.

Erstelle nun eine Verknüpfung zum erstellten oder geklonten Plugin an diesem Ort. Die Verknüfung soll aber nur den Ordner mit dem Code darin enthalten. Also nicht das ganze Repository sondern nur den Code. Dataien wie das README.md hat in der Verknüfung und im default\python\plugins folder nichts verloren

Nach einem Neustart von QGIS findet man das Plugin unter Erweiterungen -> Manage and Install Plugins... -> installed.


Writing plugins

Documentation zum Schreiben von PyQGIS-Plugins:

python: https://download.osgeo.org/qgis/doc/manual/qgis-1.1.0_coding-compilation_guide_en.pdf#page=35&zoom=100,-26,120 https://www.zimmi.cz/posts/2017/qgis-plugin-development-getting-started/ Structuring Python Plugins

c++:

Other:


Python Console

In QGIS you can open a console using "Menu > Plugins" or "Ctrl-Alt-P". Then this window should show: ``` 1 Python Console 2 Use iface to access QGIS API interface or Type help(iface) for more info. 3 _ ```

Hint: If you do the following from the Python console: ``` geom = iface.activeLayer().selectedFeatures()[0].geometry() ```

As soon as you do anything with QgsGeometry object, QGIS crashes! This is a long standing unresolved issue 777 with python bindings. This works:

```
feat = iface.activeLayer().selectedFeatures()[0]
geom = QgsGeometry(feat.geometry())

```

Test:

  • geom.type(), geom.length(), geom.asPolyline() crashes if the line has three vertices, with only two vertices it returns an empty array.

See also e.g. Python Scripting (PyQGIS) on qgistutorials.com.


Debugging von QGIS-Plugins

Developers can debug their QGIS plugin using different methods:


We recommend using IceCream (ic()) over print() for debugging. It displays variables and expressions with their values, formats data structures, and highlights output. Typing is faster, and it can optionally show the filename, line number, and function context.


Testing Plugins



Publication of a Plugin

Releasing your plugin.

A ``metadata.txt`` file is crucial because it contains descriptive information about the plugin. It helps users and qgis understand and manage data efficiently.

  • If "hasProcessingProvider" exists, this should also be mentioned in the "about".
  • "hasProcessingProvider" (yes or no). If processing tool / processing tool then this should be in description and about and processing should appear in "tags".
  • The licence must be GPL 2 or 3. Does the "LICENSE" file exist in the repo? If not, add GPL 3 from the template.
  • "homepage" should point to the "real" website or at least to the repo "README.md" (not just to the repo, and README.md should not be called "readme.md")

More details about a metadata.txt.

Preparation:

  • Check if all attributes in the metadata.txt file are in order:
    • The version needs to be different to the previous one in order for the upload to work.
    • If needed change the experimental flag from true to false. Experimental plugins won't be shown in the QGIS plugin list by default.
    • It is recommended to have an Icon set for the plugin. Its max. size does not seem to be specified.
  • Remove all files from the directory you want to upload that are not needed for the plugin to run(e.g. *.pyc files, files and folders from IDEs, .gitignore etc.).
  • File names can only contain ASCII characters in order for the upload to work. Characters like Umlauts in file names will cause an Error when uploading.
  • The plugin directory can't contain hyphens in its name (if it does the plugin might still work in QGIS but it will show an error message).
  • ZIP your plugin directory.

Upload:

  • In order to upload a plugin on the official QGIS page a OSGeo ID (user) is required (e.g. user account "geometalab"). The user account can be created here under sign-in: https://www.osgeo.org/
  • On the page https://plugins.qgis.org/ login with your OSGeo ID.
  • The plugin (ZIP archive) can be uploaded here: https://plugins.qgis.org/plugins/add/ Check experimental field if the plugin still is experimental.
  • After uploading the plugin it won't be immediately available in the plugin list. It first has to get approved. The approval can take up to 2 weeks. Check "How to add your plugin to this repository" on https://plugins.qgis.org/ for the criteria the plugin has to meet in order to get approved.



Weblinks