A Guide To Pyqgis 3 Aka How To Help Yourself: Part 1

This post is something I’ve been thinking about writing for a while and will be several parts. I was inspired to write it by my own trials and tribulations, which are still ongoing, while working with the QGIS API, trying to programmatically do stuff in QGIS instead of relying on available widgets and plugins. After spending many years working with ESRI/ArcGIS I have made the transition to QGIS almost completely and have become a big fan. But this does not mean the transition has been seemless. I have spent, and will probably continue to spend, many hours scouring the internet and especially Stack Overflow looking for answers of how to use various classes, methods, attributes, etc. Especially in the beginning, but still quite often, I feel like probably the dumbest person to have ever installed QGIS. I thought to myself many a time: “Am I an idiot or is this not as easy as it appears?”. After getting in contact with more QGIS users it appears that I am not alone. A great number of people are struggling just as I am. One common thought I hear is: “I wish the documentation was a little more fleshed out, provided more examples, was easier to follow…”. This quelled my fears somewhat, it appeared I was not alone.

Read More

How To Create And Export Print Layouts In Python For Qgis 3

I’ve been struggling off and on for literally months trying to create and export a print layout using Python for QGIS 3. Or PyQGIS 3 for short. I have finally figured out may of the ins and outs of the process and hopefully this will serve as a guide to save someone else a lot of effort and time.

Read More

How To Manually Install Qgis Plugins

I recently took up a side project working with a colleague to add some functionality to an existing QGIS plugin. This led me down a road of exploration, frustration, hand wringing, and ultimately learning. First, I’ll quickly address what a plugin is. Basically a plugin is a bit of extra functionality, probably written by a third party, which you can download and use in QGIS. The official list of qgis plugins are availabe here.

Read More

#100daysofcode In Python Review

Sometime in August, 2018 I was at a crossroads in my programming path. I had been learning for a few months and was enjoying Python as a whole, but I still didn’t feel good enough to “take the bull by the horns” and dive into my own projects so I was feeling a bit directionless. I don’t remember how but at that time I discovered the #100DaysOfCode in Python, presented by Talk Python[‘training’]. This was adapted from Alexander Kallaway’s original #100DaysOfCode, which was to force himself to code for 1 hour a day for 100 days. I’m not sure which came first but many other #100DaysOfX challenges have sprung up such as #100DaysOfHealth and #100DaysOfFitness.

Read More

How To Use Field Calculator In Python For Qgis 3

A really common task in GIS workflow is to make new fields (columns) in a layer’s attribute table and then populate that field based on the values from other fields in the attribute table. You can write all sorts of expressions using a handy tool called the Field Calculator. You can use math, values from other attributes, etc. to write expressions to calculate these values. However, you can also do this programatically using Python. When I first attempted to tackle this problem using Python for QGIS 3, I couldn’t find an example online that was simple enough for me to easily implement in my own code. What I found was either for older versions of QGIS or too convoluted for me to wrap my brain around. Though I did eventually manage to wrap my head around this, hopefully this post will serve as an example for both you and I to avoid wasted time in the future. In this example I’m going to use a subset of the data and walk through the steps. Download the sample data and you should be able to reproduce this with minimal changes to my code.

Read More

How To Apply A Graduated Color Symbology With Python In Qgis 3

The biggest reason I write in this blog is to provide myself with good records and explanation of programming (or other) problems that trip me up. If I can document the issue while its still fresh in my mind, I will hopefully be able to refer back to it here without having to re-invent the wheel.

Read More