[GIS] Clip to Shape & Extent Indicators

arcgis-10.2arcgis-desktopextents

I have a map showing the outline of an area which I'm using to clip other layers using the data frame > clip options.

Data frame Clip

In addition, I have other data frames to show some detail and want to show the extent indicators on the first map.

Is it possible to exclude the extent indicator from the data frame clip options as it isn't listed as a separate layer in the Exclude Layers… button?

So in the in the image below I want to keep the blue lines clipped to the shape, but have the entire red extent indicator visible.

Extent indicator

Best Answer

The script below will create a new shapefile with a feature representing the extent of each data frame in a map document. The data frame name is saved in a field called DFName. Once you've run this you can add it to your main data frame as a normal layer and exclude it as you would any other (the "Exclude layers..." button).

You'll still need to leave the existing extent indicators on if you want to use leader lines between the dataframes and their extent indicators.

import arcpy
import os

folder = r'C:\Data' # adjust as required

mxd = arcpy.mapping.MapDocument('CURRENT')
dfs = arcpy.mapping.ListDataFrames(mxd)

fc = arcpy.CreateFeatureclass_management(folder, 'extent.shp', "POLYGON", None, "DISABLED", "DISABLED", None)
arcpy.AddField_management(fc, 'DFName', 'TEXT', None, None, 250, "", "NULLABLE", "NON_REQUIRED")  

cur = arcpy.InsertCursor(os.path.join(folder, 'extent.shp'))

for df in dfs:
    extent = df.extent
    array = arcpy.Array()
    array.add(extent.lowerLeft)
    array.add(extent.lowerRight)
    array.add(extent.upperRight)
    array.add(extent.upperLeft)
    array.add(extent.lowerLeft)
    polygon = arcpy.Polygon(array)

    feat = cur.newRow()
    feat.shape = polygon
    feat.DFName = df.name
    cur.insertRow(feat)

    array.removeAll()

del(cur)
Related Question