QGIS for Devs: Unterschied zwischen den Versionen

Aus Geoinformation HSR
Wechseln zu: Navigation, Suche
K
K (Writing Python plugins)
 
(28 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
 
See also:
 
See also:
* [[QGIS Plugins mit Python]], [[Eigene GIS-Fachapplikationen mit Quantum GIS erstellen]], [[QGIS]], [[Python]]
+
* [[QGIS Plugins mit Python]], [[Eigene GIS-Fachapplikationen mit QGIS 2 erstellen]], [[QGIS]], [[Python]]
 
* [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')]
  
== Writing Plugins ==
+
== Python Console ==
  
Es gibt eine Plugin-Schnittstelle für C++ und für [[Python]]:
+
In QGIS you can open a console using "Menu > Plugins" or "Ctrl-Alt-P". Then this window should show:
* QGIS Plugins mit Python: Siehe [[QGIS Plugins mit Python]]
 
* QGIS Plugins mit C++: PyQGIS Developer Cookbook: http://www.qgis.org/pyqgis-cookbook/
 
  
== UX Guidelines ==
+
  1 Python Console
 +
  2 Use iface to access QGIS API interface or Type help(iface) for more info.
 +
  3 _
  
These are the User Interface Design (UX/GUI) Guidelines for QGIS:
+
Hint: If you do the following from the Python console:
# You can find the (rather small) HIG (Human Interface Guidelines) in chap. 5 of "Developers guide for QGIS"  https://github.com/qgis/QGIS/blob/master/CODING . See also starting on line 1441 of https://github.com/qgis/QGIS/blob/master/doc/CODING.t2t . HTML version here: http://htmlpreview.github.io/?https://raw.github.com/qgis/QGIS/master/doc/CODING.html#toc60
+
  geom = iface.activeLayer().selectedFeatures()[0].geometry()  
# In addition there is this (rather large)  (Graphical) User Interface (UI/GUI) Design with Qt: http://qt-project.org/doc/qt-4.8/qt-gui-concepts.html
 
# Finally, there exist the “Windows 8 App UX Guidelines”. This is only “good to know” and can be used in cases of doubt or where the two Guidelines (QGIS+Qt) don’t apply: http://msdn.microsoft.com/en-us/library/windows/apps/hh465424.aspx
 
  
== Testing ==
+
As soon as you do anything with QgsGeometry object, QGIS crashes!
 +
This is a long standing unresolved [http://hub.qgis.org/issues/777 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.  [http://www.qgistutorials.com/en/ Python Scripting (PyQGIS)] on qgistutorials.com.
 +
 
 +
== Writing Python plugins ==
 +
 
 +
There's a plugin interface for C++ and for [[Python]]:
 +
* QGIS Plugins with Python: See [[QGIS Plugins mit Python#Writing QGIS Plugins]]
 +
* QGIS Plugins with C++: PyQGIS Developer Cookbook: http://www.qgis.org/pyqgis-cookbook/
 +
 
 +
See also:
 +
* QGIS Python diagram classes by Thomas Gratier: https://github.com/webgeodatavore/qgis-class-diagram
 +
* Tutorials:
 +
** 2017, https://www.zimmi.cz/posts/2017/qgis-plugin-development-getting-started/
 +
** 2014, Getting started writing QGIS Python plugins, by Peter Wells, Lutra: http://www.lutraconsulting.co.uk/blog/2014/10/17/getting-started-writing-qgis-python-plugins/
 +
** 2014, Getting started writing QGIS 2.x plugins by Anita Graser, underdark: http://anitagraser.com/2014/04/26/getting-started-writing-qgis-2-x-plugins/
 +
* QGIS Plugin Workshops
 +
** 2014, Dhakal, Archana K.C, Shrestha and Timilsina: http://de.slideshare.net/Qust04/workshop-with-python-qgis
 +
** 2013, by Victor Olaya: https://github.com/volaya/qgis-plugin-workshop
 +
** 2013(?), by Nathan Woodrow: http://nathanw2.github.io/dmsnz-pyqgis-workshop/
 +
** 2016, by Martin Dobias, Lutra: http://www.sigte.udg.edu/jornadassiglibre2016/wp-content/uploads/2016/01/girona-workshop-2016.pdf
 +
** qgis2to3 https://github.com/opengisch/qgis2to3
 +
 
 +
== Manual installation of a Python plugin ==
 +
 
 +
Die manuelle Installation eines Python-Plugins, das sich noch nicht in einem Repository befindet, passiert wie folgt:
 +
* Plugins befinden sich in QGIS standardmässig im Ordner .qgis2\python\plugins. Der Ordner .qgis2 wiederum befindet sich im Homeordner. Dieser ist zum Beispiel unter Windows C:\Users\Benutzername.
 +
* Dorthin gehören alle Programm- und Daten-Dateien.
 +
* Nach einem Neustart von QGIS kann man das Plugin unter Erweiterungen -> Plugins aktivieren, falls es nicht schon ist.
 +
 
 +
== Guidelines ==
 +
 
 +
Her are some recommendations and guidelines:
 +
 
 +
Regarding In/Output:
 +
* A "File open..." dialog should open 1. in the user directory the first time it's used, 2. in the directory last used, 3. and this directory last used should be stored in the "Qt User Database".
 +
* Prefer Memory Layer, then GeoPackage over Shapefile, when there's a need to store or export results.
 +
 
 +
These are the User Interface Design (UX/GUI) Guidelines for QGIS (click-based! e.g. for desktops and laptops):
 +
# You can find the (rather small) HIG (Human Interface Guidelines) in chap. 5 of "Developers guide for QGIS"  https://github.com/qgis/QGIS/blob/master/CODING . See also starting on line 1441 of https://github.com/qgis/QGIS/blob/master/doc/CODING.t2t . HTML version here: http://htmlpreview.github.io/?https://raw.github.com/qgis/QGIS/master/doc/CODING.html#toc60 .
 +
# In addition there is this (rather large)  (Graphical) User Interface (UI/GUI) Design with Qt: http://qt-project.org/doc/qt-4.8/qt-gui-concepts.html .
 +
# Finally, there exist the “Windows 8 App UX Guidelines”. This is only “good to know” and can be used in cases of doubt or where the two Guidelines (QGIS+Qt) don’t apply
 +
 
 +
User Interface Design (UX/GUI) Guidelines (touch-based! e.g. for tablets):
 +
* QGIS and the UX Guidelines for QGIS are based in a click-based UX paradigm; tablets need touch-based paradigm.
 +
* “Windows 8 App UX Guidelines”: http://msdn.microsoft.com/en-us/library/windows/apps/hh465424.aspx .
 +
* See e.g. the project [[BLUgis]], an application for rescue services.
 +
 
 +
== Testing Python Plugins ==
  
 
* Configuration for Debugging and Unit Testing of PyQGIS: See [[QGIS Plugins mit Python]].
 
* Configuration for Debugging and Unit Testing of PyQGIS: See [[QGIS Plugins mit Python]].
 +
 +
== Publication of a Python Plugin ==
 +
 +
See '[[QGIS_Plugins_mit_Python#How_to_publish_a_plugin|How to publish a plugin]]'.
  
 
== Weblinks ==
 
== Weblinks ==

Aktuelle Version vom 14. Februar 2022, 18:34 Uhr

See also:

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.

Writing Python plugins

There's a plugin interface for C++ and for Python:

See also:

Manual installation of a Python plugin

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

  • Plugins befinden sich in QGIS standardmässig im Ordner .qgis2\python\plugins. Der Ordner .qgis2 wiederum befindet sich im Homeordner. Dieser ist zum Beispiel unter Windows C:\Users\Benutzername.
  • Dorthin gehören alle Programm- und Daten-Dateien.
  • Nach einem Neustart von QGIS kann man das Plugin unter Erweiterungen -> Plugins aktivieren, falls es nicht schon ist.

Guidelines

Her are some recommendations and guidelines:

Regarding In/Output:

  • A "File open..." dialog should open 1. in the user directory the first time it's used, 2. in the directory last used, 3. and this directory last used should be stored in the "Qt User Database".
  • Prefer Memory Layer, then GeoPackage over Shapefile, when there's a need to store or export results.

These are the User Interface Design (UX/GUI) Guidelines for QGIS (click-based! e.g. for desktops and laptops):

  1. You can find the (rather small) HIG (Human Interface Guidelines) in chap. 5 of "Developers guide for QGIS" https://github.com/qgis/QGIS/blob/master/CODING . See also starting on line 1441 of https://github.com/qgis/QGIS/blob/master/doc/CODING.t2t . HTML version here: http://htmlpreview.github.io/?https://raw.github.com/qgis/QGIS/master/doc/CODING.html#toc60 .
  2. In addition there is this (rather large) (Graphical) User Interface (UI/GUI) Design with Qt: http://qt-project.org/doc/qt-4.8/qt-gui-concepts.html .
  3. Finally, there exist the “Windows 8 App UX Guidelines”. This is only “good to know” and can be used in cases of doubt or where the two Guidelines (QGIS+Qt) don’t apply

User Interface Design (UX/GUI) Guidelines (touch-based! e.g. for tablets):

Testing Python Plugins

Publication of a Python Plugin

See 'How to publish a plugin'.

Weblinks