Quite a few people have asked what is the best way to learn to program for their GIS based roles. This is generally on the back of a discussion about how repetitive and time consuming some of their tasks are and almost always preceded with the question “well why don’t you program that out?”.
There’s many different ways to learn, and thankfully a whole lot more resources now than when I started learning Python 10 years ago (Please don’t read that as “I’ve been programming in Python for ten years – I haven’t – I’ve been learning Python off and on for ten years!). The first step you need to look for is practicality. What are you going to learn and why? To make it simple, I’m basing this article around learning Python, for GIS, particularly ArcGIS – as that is what is most relevant to me in my career right now and foreseeable future. If you use an alternative like QGIS, you’re in luck as it is expandable with Python also.
Learn the basics
Programming would seem like something that is only within the grasp of the super-intelligent, but the super-intelligent were smart enough to make some elements of programming quite simple for us, and then they went further and made it even easier for us to learn. #thanks. I always recommend starting Python learning on a free learning stream at CodeAcademy or other similar websites – and there’s plenty out there. It is a great online learning tool with plenty of mini-lessons and an interactive console so you don’t need to download, install, configure a single thing before getting started (even though you probably have Python ready to go but just don’t know it). Another website I’ve found recently and am using to hone some other skills, is oneMonth.com – you need to pay for the courses, but the ones I’m completing are so far worth every cent.
Get into the Python community, sign up to one newsletter (at least) and commit to reading it. I’m signed up to three or four but without fail I read the daily from Dan Bader / Real Python these help introduce new concepts and tricks that you might not need now, but will in the future. There’s plenty of forums you can join, and even Python user groups – if you’re a busy person though; read the short and sharp newsletters mentioned above.
By the time you’ve finished CodeAcademy, you will know the basics of Python – enough to make a difference. But that’s no good if you don’t know how you’re going to use your skills, you need a purpose for having them, our purpose as highlighted earlier is programming GIS. Right now we can do some more advanced field calculations using our python skills a (not so great) example is below. Reversing the order of a date.
x = original_time.split('-')
x = x + '-' + x + '-' + x
But we want to do more than this, we want to program entire workflows. We want them to be fast, we want advanced logic (if this then do that or maybe do this instead), want them to be easily maintained, upgraded, we want to be able to get rid of petty tasks quickly.
ModelBuilder is great for rookies, but once your models start getting too big to understand or maintain easily, or have complex iterations, or require a simple fork – you will need to look for an alternative. That’s why you need to step it up a notch and learn Python.
ArcPy – the Python module built specifically for expanding ArcGIS is the next expansion to your skillset. And for a new programmer it can be difficult. The best way to learn this is to just get on in there. Start with something simple, a tool that produces a message in the arc dialog. Then turn it up a notch, export one of your simple modelbuilder scripts to Python and clean that up.
arcpy.AddMessage("Henlo world! Woof!")
Check out the developer docs on the Esri website for more ways you can use the ArcPy library. There’s also a course on Udemy (which I have not tried – this is for info, not an endorsement), and plenty of tutorials around the place. I’ll write a few pieces on here too as well as dissecting bits of my own scrappy older code as I re-write them.
Establish your working environment
It’s best to start experimenting with different IDE’s (Integrated Development Environments) at the early stage, you don’t have to committ to any particular one, they all have their unique selling points but some may have too many or not enough features for your liking. I use PyCharm by JetBrains – it’s not free, but there is a free edition.