Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

QGIS Processing at Linuxwochen Wien / PyDays 2017

2,238 views

Published on

Integration of geoprocessing tools in QGIS using Python

Published in: Technology
  • Be the first to comment

QGIS Processing at Linuxwochen Wien / PyDays 2017

  1. 1. QGIS Processing Integration of Geoprocessing Tools in QGIS using Python Anita Graser
  2. 2. About Anita Graser Scientist @ AIT Austrian Institute of Technology QGIS Project Steering Committee OSGeo Board of Directors Moderator on GIS.Stackexchange.com Author of „Learning QGIS“, „QGIS Map Design“ & „QGIS 2 Cookbook“ @underdarkGIS
  3. 3. QGIS Team Developers Translators Infrastructure Managers Community Managers Designers Users Documentation writers Donors & Sponsors Project Steering Committee
  4. 4. Developermeeting, Linuxhotel Essen
  5. 5. QGIS History OSGEOincubation, IntroductionofPSC Firstprofessionalusers QGIS1.0(Kore) QGIS2.0(Dufour) QGIS.ORGAssociation founded QGIS3.0 Source of Search volume interests: https://trends.google.com/ FirstWindowsrelease Developmentstartin2002
  6. 6. QGIS
  7. 7. QGIS Today Most popular Open Source Desktop GIS Second most popular GIS after ESRI ArcGIS Available for: Linux, Windows, OSX (and Android) Translated in > 40 languages More than desktop: QGIS Server, web clients (QWC2, LizMap), data collection solutions (QField, Intramaps Roam)
  8. 8. Python in QGIS Starting with release 0.9 (October 2007) PyQGIS API depends on SIP & PyQt4 Used to  Run commands from console  Customize actions / tools  Develop Plugins  Develop stand-alone applications http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/intro.html
  9. 9. QGIS Python Plugins > 600 plugins http://plugins.qgis.org/plugins/ QGIS 2.x  Python 2.7 (Qt4/PyQt4) QGIS 3.x  Python 3 (Qt5/PyQt5)
  10. 10. QGIS Processing Plugin
  11. 11. Processing Goals Efficiency integration of analytical capabilities by connecting to original binaries of other software, such as SAGA, GRASS GIS, R, or ORFEO Toolbox Modularity consistent behavior across different tools & commonly-needed routines Flexibility algorithms can be reused in any of the framework’s graphical tools Automatic GUI generation based on the algorithm description
  12. 12. Processing: Hello World ##Learning QGIS=group
  13. 13. Processing: Hello World ##Learning QGIS=group ##input_layer=vector
  14. 14. ##Learning QGIS=group ##input_layer=vector my_layer = processing.getObject(input_layer) print my_layer.name() Processing: Hello World
  15. 15. Creating a Vector Layer
  16. 16. Behind the Scenes
  17. 17. QGIS Algorithms
  18. 18. OGR / GDAL
  19. 19. OGR / GDAL Integration option 1: OGR / GDAL Python bindings from osgeo import gdal , osr from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm ... class ExtractProjection(GdalAlgorithm): ... def processAlgorithm(self,progress): rasterPath = self.getParameterValue(self.INPUT) createPrj = self.getParameterValue(self.PRJ_FILE) raster = gdal.Open(unicode(rasterPath)) crs = raster.GetProjection() https://github.com/qgis/QGIS/blob/master/python/plugins/processing/algs/gdal/extractprojection.py
  20. 20. OGR / GDAL Integration option 2: command line interface using Python’s subprocess from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm from processing.algs.gdal.GdalUtils import GdalUtils ... class ClipByExtent(GdalAlgorithm): ... def processAlgorithm(self, progress): out = self.getOutputValue(self.OUTPUT) ... arguments = [] arguments.append(’-of’) arguments.append(GdalUtils.getFormatShortNameFromFilename(out)) ... GdalUtils.runGdal([’gdal_translate’, GdalUtils.escapeAndJoin(arguments)], progress) https://github.com/qgis/QGIS/blob/master/python/plugins/processing/algs/gdal/ClipByExtent.py
  21. 21. GRASS & SAGA Integration via command line interface Main steps 1. Description of algorithm inputs and outputs 2. Input data preparation 3. Algorithm execution 4. Output handling
  22. 22. GRASS & SAGA Algorithm description for GRASS v.voronoi v.Voronoi Creates a Voronoi diagram from an input vector layer containing points. Vector (v.*) ParameterVector|input|Input points layer|0|False ParameterBoolean|-l|Output tessellation as a graph|False *ParameterBoolean|-t|Do not create attribute table|False OutputVector|output|Voronoi diagram https://github.com/qgis/QGIS/blob/master/python/plugins/processing/algs/grass7/description/v.voronoi.txt advanced
  23. 23. R Standard R syntax Extended by additional header elements ##Vector processing=group ##showplots ##Layer=vector ##Field=Field Layer hist(Layer[[Field]], main=paste("Histogram of",Field), xlab=paste(Field))
  24. 24. Processing Commander
  25. 25. Batch Processing
  26. 26. Processing History Log
  27. 27. Processing Modeler Workflow Automation
  28. 28. Getting More Scripts
  29. 29. 1. Extract characteristic points 2. Group by spatial proximity 3. Compute group centroids & Voronoi cells 4. Segment trajectories according to Voronoi cells 5. Count transitions from one cell to another https://anitagraser.com/2016/11/07/movement-data-in-gis-3-visualizing-massive-trajectory-datasets/ Ex1: Trajectory Generalization
  30. 30. Ex2: Edge Bundling i.e. „fixing hairballs“ 1. Cluster edges 2. Bundle similar edges 3. Visualize local bundle strength
  31. 31. http://dx.doi.org/10.3390/ijgi4042219
  32. 32. Plans Processing  Porting Processing core to C++  Parallel processing support General  Migration to Python 3  PyQGIS API documentation improvements User conference 2017 in August in Denmark
  33. 33. Contact Anita Graser anitagraser@gmx.at @underdarkGIS anitagraser.com

×