Python Training

Course Outlines

Python Essentials (1 day) - Next course dates

The course covers the following topics:

 

1.Setup

● Installation
● Executing Scripts
● Using the interpreter

2. Introduction

● Imports
● Functions
● Indentation
● Variables

3. Strings

● Strings
● if condition
● Exercise  - basic/stringl.py

4. Lists

● Lists
● Looping

5. Sorting

● sorted function
● Tuples
● Exercise - basic/stringl.py

6. Dicts and Files

● Dicts
● Reading and writing files

  • Extra: Using with context manager
  • Unicode Errors Simply Explained
  • Exercise - basic/wordcount.py

7. Regular Expressions (optional)

● Exercise - babynames/babynames.py

8. The standard library

● File System
● Errors and Exceptions
● HTTP (optional)
● Exercise - copyspecial/copyspecial.py
● Exercise - logpuzzle/logpuzzle.py (optional)

9. Further Topics

● A gentle introduction to classes
● Installing packages via pip (python -m pip)
● Postgres using psycopg

  • Python psycopg2 & PostGIS

 

Python for QGIS (1 day)

This course assumes some previous knowledge of Python and a basic familiarity with QGIS. It covers using Python to interact with and extend QGIS.

1. Brief introduction to QGIS

2. An introduction to PyQGIS

● What's possible

3. Python Expressions

● Exercise - Using Custom Python Expression Functions

4. Using the QGIS Python console

● Exercise - Getting started with Python Programming

  • Extras
    • String formatting (4 decimal places for coordinates)
    • Write column header
    • Output all columns (see info about attributes and accessing attributes)
    • Create a function
    • Use with other layers
    • Handle there being no selected layer (hint: display a QgsMessageBar, as shown in Communicating with the user)

5. Exploring the PyQGIS API

● Loading Projects
● Loading Layers
● Using Vector Layers
● Filter vector features
● Vector layer summary
● Geometry Handling
● Map Rendering and Printing
● Logging

6. Plugins

    • Use function written in [Getting Started With Python Programming]
    • Alert the user when the process is complete (hint: QgsMessageBar from Communicating with the user)
    • Change the iconExtras

7. Writing a Processing plugin

8. Further topics

  • Database access via QGIS