QGis Scripting With Python Intro
QGis Scripting With Python Intro
Geomeetup SF
Alex Mandel
Geography Phd Candidate Davis, California 95616 blog.wildintellect.com [email protected]
Quantum GIS
What is it?
A GUI based Desktop GIS application for data viewing, exploration, manipulation and output. A customizable and expandable GIS platform. GPL Licensed
A Typical GIS
http://plugins.qgis.org/
SEXTANTE - Analysis Tools Atlas - Batch map production QSpatialite, PostGIS Manager, RT Postgres Extractor Time Manager - Time Slider and video exporter OpenLayers - Load Google, OSM etc in the canvas ManageR - Pass data to/from R
Plugin Manager - Turn on/o plugins from Menu/Toolbars Fetch Python Plugins - Download and Update plugins from online repositories
Plugin Management
Getting Started
Plugin Builder - Build a skeleton for a new plugin Plugin Reloader - Reload plugin code without QGIS restart ScriptRunner - Test small python snippets from le Python Console - Interactive python in QGIS
Anatomy of Plugin
PluginFolder
init .py Metadata PluginCode Core Functions not tied to interface specics PluginDialog Interface Interaction, Middle Man PluginUI User Interface resources and images (logo.png)
Important Resources
QGIS Plugins Code http://hub.qgis.org/ QGIS Workshop http://www.qgisworkshop.org/ QGIS Python Cookbook http://www.qgis.org/pyqgis-cookbook/ QGIS API http://www.qgis.org/api/ Qt Docs doc.qt.digia.com PyQt Docs http://www.riverbankcomputing.co.uk/ static/Docs/PyQt4/html/classes.html
Example: Number of nodes in a Polygon for selected features in the active Layer QGIS Interface . activeLayer . selectedFeatures . featurelist . geometry . asPolygon
1 2 3 4
layer = qgis . utils . iface . activeLayer () featlist = layer . selectedFeatures () geom = featlist [0]. geometry () len ( geom . asPolygon () [0])
http://qgis.org/api/1.8/group__gui.html http://www.qgis.org/pyqgis-cookbook/vector.html
PyQt tips
Learn Signals & Slots http://www.riverbankcomputing.co.uk/static/Docs/ PyQt4/html/new_style_signals_slots.html pyuic4 and pyrcc4 - Every time you make a change to a plugin UI you need to run these.
pyuic4, converts a .ui le to a .py pyrcc4, bundles up things like icons into a single le p y u i c 4 o m e t a e d i t U i . py m e t a e d i t . u i p y r c c 4 o r e s o u r c e s r c . py r e s o u r c e s . q r c
Special Thanks
Tim Sutton, Pirmin Kalberer, Aaron Racicot, Gary Sherman QGIS Developers & Contributors Open Source Geospatial Foundation (OSGeo)
This presentation and others are available on http://www.scribd.com/wildintellect