How can programming be used in mapping? These days, maps just aren’t made up of lines and areas on a page. They are made up of very rich complex data. Each line can have a myriad of attribution detailing type of feature, use, width and more.

Programming or scripting is used to make this attribution into a very usable, visually pleasing product. We have created the Python Insights blog series to help other Python users by providing solutions to common problems and handy hints.

Our first blog in the series includes basic examples of different ways you can streamline your coding, and an insight into how we use Python at Spatial Vision.

At Spatial Vision we make use of the Python module ArcPy and ArcPy.mapping through ArcGIS software to bring maps to life. The code can be as simple as only selecting the major roads to be visible to organising complex bridge tunnels and bridges to display in correct order to finding where annotation is incorrect and doesn’t match the vector attribution.

Different Ways of Using String Variables

In this example, there are at least 3 ways to create a variable made up of other variables.

The advantage of using the 3rd example is you don’t have to know or worry about the type of the variable or changing the type to suit the other variable as in first example.

Creating a File Geodatabase 

When coding to create a file geodatabase, it is usually best to find out if there is an existing geodatabase first. When creating a file geodatabase, the function requires the full workspace to find out firstly if it exists, a breakdown of the folder name, followed by the geodatabase name to create the file geodatabase. There are two options for coding this.

As you can see the second example reduces the code compared to the first, but both of these examples have their advantages.

Writing Paths in Python and The Dreaded Escape Character (\)

When you copy a path from Windows explorer or ArcCatalog the string looks like this:


Python uses the backslash (\) as an escape character. It tells Python not to count the next character when working out if the line makes sense or contains errors.

An example for this would be:

The character “\” tells Python to ignore the apostrophe so that it doesn’t treat it as the quotation mark that closes the whole string. In the above example C:\Temp, Python would try to ignore the T and try to do something with “C:emp”. Some Python IDE’s recognise this and fix when compiling, but some don’t.

To overcome this, try using one of the following:

v = “C:\\Temp”

v = “C:/Temp”

or  (and this is the easiest as nothing needs to be changed)

v = r“C:\Temp”

The r makes everything within the quotation marks exactly as it is written.

Writing a List Without Having To Run The Frequency Tool

Want a list of feature types without doing a frequency? You can create a frequency table of a field to create a unique list of attributes, then pass this into a list for use in your code. But, this requires a table to be created, an advanced ArcGIS licence and lots of code. To bypass this you can use just a few lines of code:

We hope you have enjoyed our first Python Insights blog and have learnt some skills that you can apply in your own workplace. Stay tuned for Python Insights Part 2!

For further information, please contact Spatial Vision at

Mandy Tyrer
Latest posts by Mandy Tyrer (see all)