Clipping layers while using Data Driven Pages

One of the hardest things about writing a blog is deciding on a title for the article… I’m still not convinced this is the right title to describe this article…. But anyway….

Apart from talking about Python and ArcPy I also teach anything and everything about ArcGIS for Desktop and on a recent course I was asked this question:

“I know that Data Driven Pages can be used to create a map based upon the extent of each feature in the index layer…. But how can I display just that feature from my Data Driven Pages index layer, and not any other features? And can I choose what layers are clipped by the outline of the index layer?

It has been ages since I wrote a blog post (apologies but work and life have gotten in the way in the latter part of 2016 / early 2017 ) and this question has stimulated me to finally write something – Action this Day if you like…

In my map document I have a basemap from ArcGIS Online and three feature layers, made up of building outlines, ward boundaries and the road network. My wards layer is my Data Driven Pages index layer and is currently displaying Grange Ward.

My map is shown below – apologies to any cartographers who might have stumbled across this blog entry. Please leave your carto-criticisms in the comments section where they will be dealt with in the traditional way by most complaints departments….


So let’s answer the second question first – “How can I display just that feature from my Data Driven Pages index layer, and not any other features?”

This is achieved by working with the Data Frame Properties dialog box. So:

  • Click the Data Frame tab and notice the area called “Clip Options”.


By default it is set to No Clipping.

  • Click on the drop-down and choose “Clip to current data driven page extent” and press the OK button.


When the changes have been applied you will then see that the current Data Driven Page feature is used to clip all of the layers (including raster layers) in your map. Notice that only the current index layer feature is displayed (Grange Ward) and it is used to clip all features and pixels within the active Data Frame.


Pressing the Next Page button on the Data Driven Pages toolbar will display the next Data Driven Page feature in the index layer and will also clip the data accordingly.


Now that the current feature in the index layer is clipping the data it is quite straightforward to control what layers are clipped and what ones are not clipped. The second question –  “And can I choose what layers are clipped by the outline of the index layer?” can now be answered.

Once again this is done from within the Data Frame Properties > Data Frame tab.

  • Locate the Clip Options area (the Clip to current data driven page extent option should still be chosen).

Notice the Exclude Layers… button.


  • Click the Exclude Layers… button.
  • Choose the layers which are no longer to be clipped. In the example below the basemap and the roads are chosen and will no longer be clipped to the current index layer feature.


The result is that the OS Lines are clipped to the single Grange Ward index feature. The roads and the basemap are no longer clipped to the index feature.


To highlight your particular clipping feature a border style can be applied:


The map below shows the clipping feature with a “Single, Nautical Dash”:


So, you probably knew this anyway: I didn’t and thought it was a nice feature I wanted to share.

I wonder if ArcGIS Pro 2.0 has this built into it yet? Something to look at as and when…



Using Python to close an ArcMap map document down

This article isn’t particularly mainstream but at the recent Esri UK user conference I was asked the following question:

How do I close down an open ArcMap map document through a Python script? If I have a number of map documents open I just want a particular map document to close and leave all of the other ones open….

“Hmmmmm – good question. Email me and I will see what I can think of…”

Well the customer emailed earlier this week asking the same question. How am I going to solve this?

Normally I might have a look in the excellent ArcGIS for Desktop help for ArcPy but there was nothing there as this is really not an ArcPy problem.

An internet search found that there were a number of others who had asked the same question but did not really receive a satisfactory reply.

For example:

Use the os.system(“TASKKILL /F /IM ArcMap.exe”)

Which was suggested in this thread

Or use the Python library psutil to get a list of processes and if the name of a process (Arcmap.exe) is found then stop it using the terminate() method which was suggested on this thread

There are countless others asking pretty much the same sort of thing (not necessarily to do with a map document) on

As you can imagine both options will close all open instances of ArcMap.

But what is you wanted to be a little more choosy about which instance of ArcMap you wanted to close down? What about if you wanted to close ArcMap down based upon the name of its open map document?


Using the psutil Python module

The answer to this is to use the Python module psutil. This module is used to obtain information from running processes – basically anything you have running in Task Manager can be obtained using this module, and a whole lot more.

It is not part of Python’s Standard Library which means you will need to download it and install it onto your machine which you want to run the script on. Thankfully it is incredibly easy to do this as it is part of the Python Package Index (PyPI) repository and modules found here can be installed easily as long as you have an internet connection.

Let’s go and install the psutil

1: Open up a command line prompt

2: At the command prompt, Change Directory (CD) into your Python \Scripts directory, for example:

cd C:\Python27\ArcGISx6410.3\Scripts

Inside this folder are a number of python utility scripts – the one we want to use is pip.exe as this will install the named module within the PyPI repository.

3: At the command prompt type in:

pip.exe install psutil

and press <return>

This will start to install psutil into your Python \Site-Packages folder. As it installs you will see messages along the lines of:

Downloading psutil-4.3.0-cp27-none-win_amd64.whl (169kB)

100% |################################| 172kB 1.9MB/s

Installing collected packages: psutil

Successfully installed psutil-4.3.0

And that is all you have to do to install it! You can now import the module into your script and take advantage of its functionality.

Information about psutil can be found here:

It is well documented and the nice thing about such an unfamiliar (to me) module is that it contains many ‘easy to follow’ samples. If only all Python modules were as well documented….


Let’s consider this problem….

I have a number of ArcMap map documents open and part of my workflow is to close a particular map document (Editing.mxd) once I have made some changes to using ArcPy functionality.

Inspecting the Task Manager shows that a number of ArcMap applications are open and each application has its own process ID (View menu > Select Columns and tick PID (Process Identifier) )


But which one is the Editing.mxd process? Task Manager can not provide that level of information.

This is where the psutil module comes in handy. This can be used to close down the Editing.mxd map document.

Let’s write some code to do this:

1: Import psutil and get a list of process IDs

mxdName = "Editing.mxd"
import psutil
pidList = psutil.pids()

2: Process the PID list to obtain the corresponding operating system process and get its name

for pidID in pidList:
  process = psutil.Process(pidID)
  pidName =

3: Find the ArcMap processes and get their memory maps.

  if (pidName == "ArcMap.exe"):
    tMemMaps = process.memory_maps()

The memory_maps() method retrieves information about the processes (ArcMap.exe) as a Python list of tuples.

The information contained in the list of tuples can be inspected using a for .. in loop and one of the items contained within it is the name (and location) of the current ArcMap object which is being processed, for example,  Editing.mxd.


4: Parse each memory map, obtain path information and see if the desired mxd is present

      for eachMemMap in tMemMaps:
        mxdPresent = eachMemMap[0].find(mxdName)

The find() method belongs on the string object and returns the index number at which the value contained in mxdName (i.e. Editing.mxd) is found.

5: If the index number is greater than -1 kill the process

        if mxdPresent > -1:
          process.kill()   # Close the desired ArcMap

If the string is not found then a value of -1 is returned from the find() method. If the number is greater than -1 then the map document name is the one we want to close, so let’s kill the process. The break statement is there as it is assumed there is only one instance of the map document called Editing.mxd open so there is no point processing any other process’ memory maps.

The finished script is displayed below:

mxdName = "Editing.mxd"
import psutil
pidList = psutil.pids()

for pidID in pidList:
    process = psutil.Process(pidID)
    pidName =
    if (pidName == "ArcMap.exe"):   # Process only the
                                    # ArcMap.exe
        #Get the process memory map
        tMemMaps = process.memory_maps() # A list of
                                         # tuples
        for eachMemMap in tMemMaps:
            mxdPresent = eachMemMap[0].find(mxdName)
            if mxdPresent > -1:
                process.kill()      # Close the desired
                                    # ArcMap process
print(mxdName + " has been closed down")

It is available in GitHub at:


Let’s go Pro!

Saying that though, this script will not work with ArcGIS Pro – it’s a bit of a Misfire.

Yes – there is an ArcGISPro.exe process which can be seen in Task Manager and the process does have a memory map but within the memory map there is no reference to the currently opened map project (.aprx file).

This isn’t the end of the world though as you can only ever have one instance of ArcGIS Pro running. If you try and launch another ArcGIS Pro project while one is already open then this is the message which will be displayed:


In which case you can use the solution as suggested in one of the GeoNet posts, with a very slight amendment:

import os
os.system(“TASKKILL /F /IM ArcGISPro.exe”)

And there you have it! The Python module psutil is a pretty useful module if you want to see what is associated with a particular process. I am thinking of this module as the Python equivalent of Sysinternals very handy “Process Explorer” application.

I think I have only really scratched the surface of this module and it is one I suspect I will use more in the future.

Useful links
Python Standard Library

Python Package Index (PyPI) repository

psutil module homepage

Sysinternals Process Explorer