ArcPy for Beginners

Posted on June 17, 2019

Interested in learning how to use ArcPy to improve your ArcGIS experience? Read on.

a quick Q&A

What is ArcPy?

ArcPy is a Python (programming language) module that interacts with the tools already included in ArcMap (like Project, Create Feature Class, etc.). It lets you to create your own custom tools.

Why use ArcPy?

It can save you loads of time, automating things you have to do manually now. If there are repetitive, laborious tasks you do in ArcMap over and over for your project work, you can use ArcPy to build your own tool that will fit your project needs exactly.

How to use ArcPy inforgraphic
Click here for an infographic that sums up
some of the resources in this article.

Basically, if you ever find yourself working in ArcMap and wishing that you didn’t have to do all these little steps every single dang time, you’re going to love ArcPy.

Can you give me an example?

Using some code I found on Stack Exchange + ArcPy functions, I was able to build a tool that creates Seismic Hazard maps, breaking down a long, often frustrating task into a process that takes minutes. And that’s just one example.

But what if I’ve never coded before?

I didn’t start with much experience, either. Using ArcPy isn’t that difficult.

What is difficult is sifting through the reams of information on the internet about how to use it. That’s why I’m writing this – to give you a starting point and to share the resources that I found most helpful as a person who didn’t have a lot of programming experience.

Are you an ArcPy expert?

No, but I’m learning more every time I sit down to build or refine a tool. There’s a lot I don’t know. But I can definitely get you started.

Steps to Get You Started

Step 1: Learn the basics.

(If you have programming basics/a familiarity with Python syntax, skip to Step 3.)

If you’re completely new to the world of code, start with a free trial at Treehouse. This is an excellent online learning resource, and they recently updated their Python Basics course. It’ll help you get the grammar of the language down and teach you some programming basics.

Step 2: Get a script editor.

I use Atom.

Step 3: Find a good starting ArcPy tutorial. 

I started here, with Fran Polignano’s YouTube tutorials. The reason I like these tutorials is because the examples given are fairly simple, but build in complexity, and they’re designed for ArcPy newbies. The tone is conversational and pretty easy to understand, and the YouTuber who made them did so for basically the same reason I’m writing this – to fill a content need that would help people just starting out with ArcPy.

They’re not perfect, and some parts could be a little clearer, but after working my way through this series and practicing variations on his example, I was able to write my first simple program using ArcPy.

This would also be a good time to bookmark this page: ArcPy Functions. This is ESRI’s official documentation for the ArcPy module. You’ll be visiting these pages a lot.

Note: He recommends using PyCharm as a script editor; I personally like Atom, but PyCharm is also a good option. You’ll also note that, to test his code, he runs it in PyCharm; you can also copy-paste your code into the Python window in ArcMap.

Step 4: Practice. 

Experiment with doing some Very Simple Things before you try to build that big, complicated tool, especially if you’re new to coding altogether. I recommend trying variations on the examples in the projects above, which is what I did.

One of my earliest programs just added a field to an attribute table. Start Small.

Step 5: Be tenacious.

Sometimes finding the right working solution to your problem can take awhile. That’s okay. Here are a few things I recommend to stave off frustration:

  • Walk away. Sometimes the solution can come to you during your commute, or when you’re about to go to sleep, etc.
  • Show your code to someone else. Even if they don’t have experience with ArcPy specifically, another person familiar with coding will sometimes see things you don’t.

A Few Final Tips

Common ‘oopsies’ that can mess you up:

  • Reading documentation for the wrong version of ArcGIS on ESRI’s website. When you’re looking at documentation, always check that the version selected in the dropdown at the top of the page matches your current ArcGIS version. Some functions have changed slightly with subsequent versions, and as you already know (or are about to find out), a tiny typo in a program will crash the whole thing.
  • A missing colon. An extra colon. A lowercase letter. An uppercase letter. (You get the picture.) Proofread your code carefully.

What if I just can’t figure something out? 

Don’t despair; try the GIS Stack Exchange. There are are plenty of folks there who have either a) already done the thing you’re trying to do, or b) can look at your code and easily tell you where you’ve gone wrong. In my experience, people respond pretty quickly.

Be sure to observe site etiquette: check to see that your question hasn’t already been answered elsewhere, and post your code-in-progress instead of just describing the problem.

 

This isn’t an exhaustive list of resources by any means, but it’s definitely enough to get you started. Good luck – and have fun!

Sarah Kelley is a marketer, researcher, digital content specialist, and ArcPy enthusiast.