You are on page 1of 15

How to Clip Multiple Layers in ArcMap

Introduction
This document outlines the steps required to import and create the batchclip tool and the
procedures for clipping multiple layers in ArcMap. Using Visual Basic and a batchclip
script written by Li he Wang, it is possible to clip all layers at once while preserving the
projection data. Although the script works in ArcGIS, there are still a few problems,
which have yet to be resolved. Further investigation and suggestions for making these
procedures more efficient are welcome.
ArcGIS 9.1 was used for these procedures. It should be noted that there may be variations
in the examples, depending upon the version of software that is being used.
Function of the script
Lihe Wangs script clips all layers in the current window with the first layer. All
layers must be in the same projection.
Acquiring the script
The batchclip script can be downloaded from the ESRI ArcScripts website at
http://arcscripts.esri.com.
In the ArcScripts Search Box, type clip all layers (without the quotation marks)
in the Search for box
Download the Clip All Layers script. The download file name is AS13040.zip.
Unzip the file. The batchclip script consists of 3 files: ClipAllLayers.frx,
ClipAllLayers.frm, and Readme.txt.
Loading the script

Launch ArcMap
Open Visual Basic from the ArcMap menu (select ToolsMacrosVisual
Basic Editor) ( Fig.1)


Figure 1

The window that appears is the session of Visual Basic that runs parallel to the ArcMap
session. (Fig.2)
In Project Explorer, select (i.e. single click) Normal (Normal.mxt).
Open the Properties Window, if it is not open (from the menu, select View
Properties Window).

Figure 2


From the Virtual Basic menu, select ToolsReferences. In References, check
Microsoft Shell Controls and Automation. Click OK. (Fig.3)


Figure 3



From the Virtual Basic menu, click FileImport File. Navigate to and select
previously downloaded file ClipAllLayers.frm. ( Fig.4)


Figure 4


Open the ClipAllLayers.frm file.

The new file (ClipLayers) appears in Project Explorer in a folder called Forms.
(Fig.5)

Figure 5


Right-click on ClipLayers in Project Explorer; select InsertModule (Fig.6)


Figure 6


The following screen (with the Module1 code window) should appear: (Fig.7)


Figure 7

In the Properties Window for Name, change Module1 to Batchclip, as in the
following example: (Fig.8)

Figure 8

Copy and paste, or type the following code in the main window of the Batchclip
module: (Fig.9)

Sub Opener ( )
Load ClipLayers
ClipLayers.Show
End Sub


Figure 9

Click the save button.

Renaming the output file in the script
According to this script, all the output files will have the name with the following
extension: OriginalFileName_ClipResult.
For example, if the input files are ONtlc.shp and ONmrc.shp, the output files will be
ONtlc_ClipResult.shp and ONmrc_ClipResult.shp.
It is possible to change the output name in the batchclip script code.
Right-Click on the ClipLayers form inVisual Basic Editor and select View Code.
(Fig.10)




Figure 10

In the code, scroll down and find the line that specifies the output filename.
Change _ClipResult to desired filename, be careful not to erase the quotation
marks. (Fig.11)


Figure 11




Click the save button.
Exit from Visual Basic (select FileClose and Return to ArcMap).


Adding the Batchclip Button to the ArcMap Main Menu
In ArcMap, from the main menu, select ToolsCustomize (Fig.12)


Figure 12




Select the Commands tab and scroll down to select Macros (Fig.13)


Figure 13

Note that the newly created command and icon for Batchclip appears on the right hand
side of the Customize Dialogue Box with the name Normal.Batchclip.Opener.

Click and drag the icon to the ArcMap main menu bar. (Fig.14)



Figure 14

Close the Customize Dialogue Box.

Now, the batchclip button can be used to clip data in ArcMap.







Loading the Data and Running the Batchclip in ArcMap
Add all the layers to be clipped, including the boundary layer that will be used as
the clip file. The boundary clip layer must be a polygon feature.
All layers must be in the same projection and all files must have attributes in
the area being clipped.
When all layers are added, make sure the boundary layer is the first layer in
the Table of Contents. If not, move it to the top of the table of contents. (Fig.15)


Figure 15

Right-click on the boundary layer that will be used as the clip, and select
Selection Select All. This will identify the boundary footprint for the
clipping. (Fig.16)


Figure 16
If the output file name for the clipped data needs to be modified, open Visual
Basic from the ArcMap menu, and follow procedures in the section
Renaming the output file in the script.
Click the newly created batchclip button. (Fig.17)


Figure 17


Select an empty folder to save the output, as instructed in the dialog box.
Click the Clip button.

The appeared status bar will show the progress of operation. (Fig.18)


Figure 18
Note: The newly clipped files will not appear in the ArcMap Table of Contents.
They will be located in the folder used to save the clipped output.

Close theClip All Layers Dialogue Box.
Navigate to the folder containing the clipped files, and add them to ArcMap to see
the results.
Close ArcMap.

Troubleshooting:

Sometimes an error output is created. Depending on the error code, there could be
various reasons for the error. The most frequent error is: (Fig.19)



Figure 19

In this case, several reasons for the error are possible:
1) The layer has a different projection. As stated at the beginning, all layers
must have the same projection.
2) The features in the layer being clipped are not found within the area
specified by the boundary layer (used as the clip footprint).
3) The boundary file (used as the clip footprint) is not the first layer in the
Table of Contents.













* We would like to thank the staff from Ryerson University, Brock University and
McMaster University, who took the time to test these procedures and provide
feeback.

You might also like