Advertisements

This tutorial aims to help GIS users to get started with Python programming for QGIS 3. In contrast to many tutorials out there, the idea is to not assume any previous programming knowledge.

If you found this tutorial on your own, you probably won’t require much external motivation to give this programming thing a go. (If you do, check out “Benefits of Learning Python”.) Python is a great versatile programming language that is widely used in the GIS world and beyond. Knowing how to program will enable you to be more efficient by automating workflows and making your work reproducible.

Unlike many introductions to Python, this one does not start with an installation and setup guide. Why? Because if you have installed QGIS, you already have a working installation of Python on your system. All you need to get started is to launch QGIS and open the Python console (Plugins | Python console).

If you are looking for a more classical introduction, I strongly recommend Gary Sherman’s PyQGIS Programmer’s Guide

Contents

This is a work in progress. I’d appreciate any feedback, particularly from beginners!


External resources

 

 

Advertisements
29 comments
  1. Adrian said:

    Looks very promising

    • Thank you for your feedback! If you have any specific questions or ideas, let me know.

    • Thank you for your feedback! If you have any specific questions or ideas, let me know.

  2. Matt M said:

    This is great!

    Just a few ideas…

    Do one for writing an entire script that loads a few layers and does some sort of processing on it. The individual tasks you complete are an important foundation, this adds even more practicality.

    And then maybe write one explaining commonly used structures/logic of scripts, such as looping through features in a layer, creating new calculated columns. This enables learners to apply pyqgis to numerous problems.

    Lastly I’d love to see one for writing a script and then setting up a UI/Dialog Box for user input and how to add it to the processing toolbox.

    Your work is awesome!

    • Thank you Matt! More loops are certainly on my todo list, as is using Processing tools from code. Creating a Processing script from scratch will probably be a bit further down the line.

  3. Raúl said:

    I was looking for some like this just to start working with pyqgis. I like this who much!!!!
    Also I agree with the third idea by Matt…
    Thank you for this work!!!

  4. John said:

    Anita, Pretty much anything you do I will check out. Just try an remember, most of us are not even in the same realm of brilliance as you. Keep us dullards in mind.

    • Thank you for your feedback John! Please let me know in the comments if anything remains unclear.

  5. Hi Anita,
    A few Raster examples can also be nice.

    • Hi Harel, I’ve added a first raster example now.

  6. Kevin said:

    Hi Anita,

    Will you cover using python to change layout properties if I were to automate map creation or something of that sort?

    These posts have been helpful for me as I begin learning PyQGIS. Thanks again!

    • Hi Kevin,
      Thank you for the suggestion. It’s probably an advanced topic but I’ll keep it in mind.

      • Kevin said:

        Thanks for taking it into consideration. And what you’ve done already has been helpful to me!

  7. wow! am from Kenya and this tutorial is amazing creating an impact in me, looking forward for more

  8. Chris said:

    Such a great initiative ! Thanks a lot.
    I’m learning programming and one of my “goal” is to implement in a way or another median filter for rasters in QGIS.
    Numpy can already do it so i guess an easy way to achieve my objective would be to “call” numpy within QGIS.
    Do you think it’s achievable in a reasonable time for a true beginner ?

    • I think the part of using numpy should be rather straightforward. I have some Python2 numpy code that I could adapt for this tutorial. There might be a simpler way to achieve a median filter though but I don’t have a solution ready.

      • Chris said:

        I’m not looking for a solution ready but for a practical objective to motivate me to learn code. =)
        So if you can already help with “how to use numpy within QGIS” that would be great already !

  9. DELPORTE Bruno said:

    Bonjour,
    It’s now several weeks that I attend to learn QGis and PyQgis. Up to now, the tutorials were not efficient for different reasons : too short, too quick, too hard, and/or too olds (methods that don’t work any more with the latest version of QGis)… for beginners like me. Your course is very practical. And the progression of difficulties is very good.
    I do like it

  10. Geert said:

    Hi Anita,
    I’m a beginner in PyQgis and this is a great tutorial, very useful! Thank you for posting it. I’ll be on the lookout for more! :-) I’m especially interested in how to automate map making (using a Layout template and exporting it to a PDF file, for example).

    • Hi Geert, an example for exporting a layout to PDF is published now.

  11. Edd said:

    Hola muchas gracias, voy a iniciar a revisar, soy neofito en el tema!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: