Taking hold of the Python – Part 2


Getting started

You don’t have to be a programmer to write Python scripts. You can start by learning the basic Python syntax and its built-in types. Once you know the basics, you can write Python scripts to automate geoprocessing, map production, and data management tasks in ArcGIS.

I think ModelBuilder actually provides the easiest start. Note that once you’ve constructed your Graphic UI model in ModelBuilder, when you save it, it gets compiled into Python script which allows you to go through and get more familiar with the syntax and logic construction.

Something similar can be done from the Results window, where you have the option to copy geoprocessing tool results as Python snippet code. Being able to access a detailed record of your geoprocessing operations, with tool inputs pre-populated, is a powerful timesaver when you need to repeat the same workflows.

The article ‘Python Scripting in ArcGIS10: 25 Potential Sources of Confusion’ (http://nrm.salrm.uaf.edu/~dverbyla/workshops/arcpy_sources_of_confusion_AKSMC2011.pdf)

provides many examples that help to make the transition easier. Especially difficult for many people is the way the Field Calculator works with code blocks. The ArcGIS 10.x Help topic ‘Calculate Field examples’ explains how the code block is used is determined by the Expression Type. Python functions are defined using the def keyword followed by the name of the function and the function’s input parameters. Values are returned from the function using a return statement.

For a further understanding of Python for ArcGIS as well as many resources for learning the Python language: http://www.esri.com/news/arcuser/0405/files/python.pdf

Esri publishes a wealth of material on using Python in ArcGIS. You can refer to the arcgis.com Geoprocessing Resource Center to view model and script tool galleries and share your own Python script tools.

When in doubt or if in need of something more Pythonic than ArcGIS specific, have a look at some more generic Python help sites, especially with database related processes.

Good luck taking hold of the Python!

Ricardo A

One thought on “Taking hold of the Python – Part 2

  1. Nitin Reddy Katkam

    If you can write Python scripts, you’re a programmer 🙂

    The Python website provides a tutorial and lots of documentation on how to use Python. Then, there are lots of blogs out there (mine included) that provide help on specific Python features.

    I think the differences between Python versions is what makes the learning harder for newbies because when they try examples that they see online, it may not work for them depending on the version of the Python used in the examples and the version of Python that they are running.

    Reply

Got something to say?

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s