Create Multiple Data Driven Data Frames within a single ArcMap Document

4458
1
06-04-2016 01:07 PM

Create Multiple Data Driven Data Frames within a single ArcMap Document

I needed to create a ArcMap Document with Multiple Data Driven Data Frames. I realised that Data Driven Pages wouldn't allow me to accomplish the following as well as I needed it to handle any number of Data Frames without having to rewrite my Python Function. I have accomplished the following by creating a list of unique features based on my index layer that one would use if using Data Driven Pages. I then loop through each Data Frame, three layers within each Data Frame that needs to be updated based on the index layer. I then apply a definition query to each of the layers to create the view that I'm looking for for each index. I then obtain the extent of each index and set the Data Frames extent to the indexes extent as well as adjusted the Data Frames scale to the nearest 5000, which can be adjusted as needed. I've attached print screens of the ArcMap Documents with: X2 Data Frames ; X3 Data Frames ; X4 Data Frames as well as the code.

'''
Created on 02 Jun 2016

Export mxds to jpegs:

Multiple Data Driven

Frames

@author: PeterW
'''
# import site-packages and modules
import math
import arcpy


# set arguments
input_mxd = r"E:\Projects\2016\G112358\SAA\Models\Settlements\mxd\Python_Setup_Mutliple_DataFrames\DDP_Settlements02_Python.mxd"
output_folder = r"E:\Projects\2016\G112358\SAA\Models\Settlements\mxd\Python_Setup_Mutliple_DataFrames\jpegs02"


# set environment settings
arcpy.env.overwriteOutput = True


# export mxd with multiple data driven dataframes
def multiple_dataframes_jpeg(input_mxd, output_folder):
    mxd = arcpy.mapping.MapDocument(input_mxd)
    dfs = arcpy.mapping.ListDataFrames(mxd)
    index_lyr = arcpy.mapping.ListLayers(mxd, "", dfs[0])[0]
    with arcpy.da.SearchCursor(index_lyr, ["NAME"]) as scur:
        for row in scur:
            settlements = sorted({row[0][:-2] for row in scur})
    for settlement in settlements:
        for df in dfs:
            df_position = int(df.name[-2:])
            lyrs = arcpy.mapping.ListLayers(mxd, "", df)[:3]
            name = "{0}0{1}".format(settlement, df_position)
            def_query1 = "{0} = {1} AND {2} = '{3}'".format("DATAFRAME", df_position, "NAME", name)
            lyrs[0].definitionQuery = def_query1
            def_query2 = "{0} = '{1}'".format("NAME", name)
            lyrs[1].definitionQuery = def_query2
            def_query3 = "{0} = '{1}'".format("NAME", name)
            lyrs[2].definitionQuery = def_query3
            with arcpy.da.SearchCursor(lyrs[0], ["SHAPE@"]) as scur:
                for row in scur:
                    df.extent = row[0].extent
                    df.scale = int(math.ceil(df.scale/5000)*5000)
                    arcpy.RefreshActiveView()
        output_jpeg = "{0}\\{1}.jpg".format(output_folder, settlement.replace(" ", ""))
        print output_jpeg
        arcpy.mapping.ExportToJPEG(mxd, output_jpeg, df_export_width=1200, df_export_height=1200, resolution=300)

multiple_dataframes_jpeg(input_mxd, output_folder) 

DataFame_X2.PNG

Dynamic Data Frames X2

DataFame_X3.PNG

Dynamic Data Frames X3

DataFrame_X4.PNG

Dynamic Data Frames X4

Comments

Hi! I am new in this python stuff, I would like to know if you can attach the mxd to see how is set, in order to understand better the script.

Version history
Last update:
‎12-12-2021 03:43 AM
Updated by: