Diskussion:Workshop QGIS Python GeoPython 2017: Unterschied zwischen den Versionen

Aus Geoinformation HSR
Wechseln zu: Navigation, Suche
K
(Usage of Expression Functions)
 
(40 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
 
See also
 
See also
* https://github.com/simran001/PyQGIS_workshop
+
* Step-by-step guide for the workshop on [https://github.com/simran001/GeoPython-Workshop/blob/master/README.md Github.]
 +
* https://github.com/simran001/PyQGIS
 
* https://etherpad.coredump.ch/p/Python-Workshop
 
* https://etherpad.coredump.ch/p/Python-Workshop
  
''Custom Python Expression Functions for QGIS''
+
== Usage of Expression Functions ==
  
Background - Where are Expression Functions used?
+
Examples where Expression Functions (EFns) can be used in QGIS are: symbology, labeling, calculating fields, defining virtual fields, selecting and filtering data, layouts, atlas serial printing and reports, map tips, custom python expressions, parameters for processing, and many more.
* Any place
 
* Processing => Refactor fields
 
  
Collected use cases:
+
This is a more systematic list:
* Add new (calculated) field
+
# "Server-side" / data-related:
* Autoincrement / Sequence => QGIS 2.18 default Werte (QGIS 3 geplant)
+
## "Select features using an expression" based on a field(Layer property).
 +
## "Filtering features" while loading from source. See form view of Attribute table (button on bottom right corner) > click on 'Show All Features' (bottom left) and select 'Advanced Filter (Expression)'.
 +
## "Layer > Properties > Tab Fields" in Button "Text Edit" in default- and in constraints field.
 +
## "Layer > Properties > Tab Style" in "Label with" field.
 +
## "Field Calculator" to defining new or virtual fields (Layer property).
 +
## "Conditional formatting" of a field in Attribute table (Create a new rule and set the condition to the output of a custom EFn).
 +
# Analysis-related:
 +
## "Statistics Panel" / "Statistical Summary" of a field.
 +
## "Atlas Generation" in the Print Composer. Project > Print Composer > Check 'generate an atlas' > Set EFn based values for page name, filter and output filename.
 +
## Processing
 +
# "Client-side" / style-related:
 +
## "Map Tip" tool (Layer property).
 +
## "Rule based labeling" (drop-down menu) in Layer Properties > Labels; click on '+' button and add a EFn based filter to a field.
 +
## Part of "Geometry generator" for geometry field in "Style > Symbol Layer Type"
  
Possible examples:
+
== Possible examples of custom Custom Expression Functions ==
# Function reading from other feature properties
+
# Function doing something "local" like from other field(s).
# Functions aka predefined variables (@), "Singletons" like System Env (usage "env('USERNAME')") layer properties or number sequence (spcial Plugin needed?)  
+
# Functions reading something like a "Singleton" like a system environment variable (usage "env('USERNAME')") layer properties or number sequence (spcial Plugin needed?).
# Function for remote webservice: geocoding (reading from the internet)
+
# Function for remote webservice: geocoding (reading from the internet).
# Function reading from other layers (1:1)
+
# Function reading from other layers (out of scope for a workshop rather, ev. also a processing or plugin candidate).
  
 +
== Notes ==
  
 +
Collected (special) use cases:
 +
* Autoincrement / Sequence => QGIS 2.18 default Werte (QGIS 3 geplant)
 +
* Given polygon layer and a point one, calculate for each polygon feature, the number of points that it covers: https://lists.osgeo.org/pipermail/qgis-user/2016-October/038139.html http://gis.stackexchange.com/questions/212415/referencing-to-features-geometry-in-an-expression/212762#212762
 +
* Add attributes from a layer in the project or an external file (csv) to a layer (or the composer?) using insert expression? Create a custom expression python function to do this: http://nathanw.net/2012/11/10/user-defined-expression-functions-for-qgis/
  
 
Plugins:
 
Plugins:
* ExpressionPlus (for QGIS)
+
* ExpressionPlus (for QGIS) Extra functions for the expression engine which didn't make it into QGIS 2.0: https://plugins.qgis.org/plugins/qgsexpressionsplus/
* refFunctions
+
* refFunctions: http://plugins.qgis.org/plugins/refFunctions/  
* spatialJoin
+
* spatialJoin (depends on refFunctions): http://plugins.qgis.org/plugins/spatialJoin/
* AutoFields (obsolete)
+
* AutoFields (obsolete?) - Automatic Field Calculator Plugin: http://plugins.qgis.org/plugins/AutoFields/  
 
 
Writing:
 
* How to install and share an Expression Function?
 
** Save and Load in "Function Edtior" (saves to "%USERHOME%.qgis2\python\expressions" (where %USERHOME% under Windows is e.g. "C:\Users\sfkeller\").
 
** Add Fn. to qgis2/python/startup.py
 
** Add Fn. to any (own and loaded) QGIS plugin
 
** Add Fn. to the "Expresion Plus Plugin"
 
* Debugging:
 
** use "print"
 
** use pdb (see QGIS docs and giswiki)
 
** (use Remote Debug Plugin)
 
* FAQ
 
** How to store a value in PyQGIS? Use QSettings (/.qgis) or QGISProject (.qgs)
 
 
 
 
 
Notes:
 
 
 
Add attributes from a layer in the project or an external file (csv) to a layer (or the composer?) using insert expression? Create a custom expression python function to do this:
 
http://nathanw.net/2012/11/10/user-defined-expression-functions-for-qgis/
 
 
 
How to import a user defined expression functions on QGIS start up. => Add them to qgis2/python/startup.py
 
 
 
Given polygon layer and a point one, calculate for each polygon feature, the number of points that it covers: https://lists.osgeo.org/pipermail/qgis-user/2016-October/038139.html 
 
http://gis.stackexchange.com/questions/212415/referencing-to-features-geometry-in-an-expression/212762#212762
 
 
 
Automatic Field Calculator Plugin: http://plugins.qgis.org/plugins/AutoFields/  
 
 
 
Expressions Plus Plugin - Extra functions for the expression engine which didn't make it into QGIS 2.0: https://plugins.qgis.org/plugins/qgsexpressionsplus/
 
  
Resource Sharing Plugin (http://plugins.qgis.org/plugins/qgis_resource_sharing/)
+
Open:
E.g. https://github.com/mara91/qgis_styles.git
+
* How to store a value in PyQGIS? Use QSettings (/.qgis) or QGISProject (.qgs)
 +
* Resource Sharing Plugin (http://plugins.qgis.org/plugins/qgis_resource_sharing/). e.g. https://github.com/mara91/qgis_styles.git

Aktuelle Version vom 20. April 2018, 01:10 Uhr

See also

Usage of Expression Functions

Examples where Expression Functions (EFns) can be used in QGIS are: symbology, labeling, calculating fields, defining virtual fields, selecting and filtering data, layouts, atlas serial printing and reports, map tips, custom python expressions, parameters for processing, and many more.

This is a more systematic list:

  1. "Server-side" / data-related:
    1. "Select features using an expression" based on a field(Layer property).
    2. "Filtering features" while loading from source. See form view of Attribute table (button on bottom right corner) > click on 'Show All Features' (bottom left) and select 'Advanced Filter (Expression)'.
    3. "Layer > Properties > Tab Fields" in Button "Text Edit" in default- and in constraints field.
    4. "Layer > Properties > Tab Style" in "Label with" field.
    5. "Field Calculator" to defining new or virtual fields (Layer property).
    6. "Conditional formatting" of a field in Attribute table (Create a new rule and set the condition to the output of a custom EFn).
  2. Analysis-related:
    1. "Statistics Panel" / "Statistical Summary" of a field.
    2. "Atlas Generation" in the Print Composer. Project > Print Composer > Check 'generate an atlas' > Set EFn based values for page name, filter and output filename.
    3. Processing
  3. "Client-side" / style-related:
    1. "Map Tip" tool (Layer property).
    2. "Rule based labeling" (drop-down menu) in Layer Properties > Labels; click on '+' button and add a EFn based filter to a field.
    3. Part of "Geometry generator" for geometry field in "Style > Symbol Layer Type"

Possible examples of custom Custom Expression Functions

  1. Function doing something "local" like from other field(s).
  2. Functions reading something like a "Singleton" like a system environment variable (usage "env('USERNAME')") layer properties or number sequence (spcial Plugin needed?).
  3. Function for remote webservice: geocoding (reading from the internet).
  4. Function reading from other layers (out of scope for a workshop rather, ev. also a processing or plugin candidate).

Notes

Collected (special) use cases:

Plugins:

Open: