Hi All,
I have to make about 17 to 20 maps for a given location ranging from soils, topographic, wetlands, etc. I have to make these maps for about 145 different locations. So in total i will be making about 2500 maps.
I have worked extensively with data driven pages and find it works great when the location varies but the layer stays the same, e.g. the wetland layer maps for all fields. I think of this as horizontal results.
I have also made a scrip that will output all the maps for a give location. It will create the soil, topographic, wetland, and otherwise maps for a given location. I think of this as vertical results.
import arcpy, os
# Specify output path and final output PDF
outPath = r'C:\Outputs\TEST'
pdfPath = os.path.join(outPath, '1. WetlandSupportdocs.pdf')
if os.path.exists(pdfPath):
os.remove(pdfPath)
finalPdf = arcpy.mapping.PDFDocumentCreate(pdfPath)
# Specify the map document and the data frame
mxd = arcpy.mapping.MapDocument(r'C:\Geodata\Template.mxd')
df = arcpy.mapping.ListDataFrames(mxd, 'Layers')[0]
#################### ASSIGN VARIABLES ###########################
#################################################################
#################################################################
#################################################################
Farm = ("2222")
Tract = ("1111")
CLU = ("1")
District = ("District")
County = ("Wyoming")
AssistedBy = ("Bob Conservationsit")
FieldOffice = ("Hamilton")
Customer = ("Joe Landowner")
#################################################################
#################################################################
#################################################################
#################################################################
LandUnits = ('Farm ' +str(Farm) + ',' + 'Tract ' +str(Tract))
#Change County text
TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","District")[0]
TextElement.text = District
#Change County text
TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","County")[0]
TextElement.text = County
#Change AssistedBy text
TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","AssistedBy")[0]
TextElement.text = AssistedBy
#Change Field Office text
TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","FieldOffice")[0]
TextElement.text = FieldOffice
#Change Customer name
TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","CustomerName")[0]
TextElement.text = Customer
#Change Landunits
TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","LandUnits")[0]
TextElement.text = LandUnits
# Select a tract using the TRACNBR attribute and zoom to selected
lyr = arcpy.mapping.ListLayers(mxd, 'clu_a_053', df)[0]
if CLU == "":
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", 'TRACTNBR IN ({0}) '.format(Tract))
df.zoomToSelectedFeatures()
lyr.definitionQuery = 'TRACTNBR IN ({0})'.format(Tract)
else:
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", 'TRACTNBR IN ({0}) AND CLUNBR IN ({1})'.format(Tract, CLU))
df.zoomToSelectedFeatures()
lyr.definitionQuery = 'TRACTNBR IN ({0})AND CLUNBR IN ({1})'.format(Tract, CLU)
df.zoomToSelectedFeatures()
arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")
arcpy.RefreshActiveView()
# Turn on visibility for each theme and export the page
lyrList = ['FSA Wetspots','National Wetlands Inventory','NYSDEC Wetlands','Madison County Soils','Soil Special Features','Percent Hydric Soils','Highly Erodible Land','Madison 2ft Contours','Topographic Image','DEC Unconsolidated Aquifers of NY State','EPA NYS sole source aquifers','USGS Potential Carbonate Karst Topography ','Surficial Geology','NYS Bedrock Geology ','NYS EcoRegion','NYS Important Bird Areas','Northern Long Eared Bat Location Data' ]
# Don't assume the layers are turned off...Turn them off first.
print("First, turn off all the layers")
for lyrName in lyrList:
lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
lyr.visible = False
print("\tSet layer-visibility for '" + lyr.name + "' to " + str(lyr.visible))
print("Second, export to PDF")
for lyrName in lyrList:
print("---")
lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
lyr.visible = True
print("\tSet layer-visibility for '" + lyr.name + "' to " + str(lyr.visible))
#Change title text
TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]
TextElement.text = lyrName
#Change Landowner name
TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","CustomerName")[0]
TextElement.text = 'Holmes-Acre LLC'
#Change Landunits
TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","FarmTractNbr")[0]
TextElement.text = 'Farm NUB Tract 2215'
#Export each theme to a temporary PDF and append to the final PDF
tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')
if os.path.exists(tmpPdf):
os.remove(tmpPdf)
arcpy.mapping.ExportToPDF(mxd, tmpPdf)
print("\tPDF Exported to following path: " + tmpPdf)
finalPdf.appendPages(tmpPdf)
#Turn off layer visibility and clean up for next pass through the loop
lyr.visible = False
print("\tSet layer-visibility for '" + lyr.name + "' to " + str(lyr.visible))
################################### Wetland Data #################################################
# Turn on visibility for each theme and export the page
lyrListWET = ['National Wetlands Inventory','NYSDEC Wetlands']
# Don't assume the layers are turned off...Turn them off first.
print("First, turn on all the layers")
for lyrName in lyrListWET:
lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
lyr.visible = True
#Change title text
TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]
TextElement.text = "Wetlands"
#Export each theme to a temporary PDF and append to the final PDF
tmpPdf = os.path.join(outPath, "Wetlands" + '_temp.pdf')
if os.path.exists(tmpPdf):
os.remove(tmpPdf)
arcpy.mapping.ExportToPDF(mxd, tmpPdf)
print("\tPDF Exported to following path: " + tmpPdf)
finalPdf.appendPages(tmpPdf)
#Turn off layer visibility and clean up for next pass through the loop
for lyrName in lyrListWET:
lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
lyr.visible = False
del lyr
################################### CIR Data #################################################
# Turn on visibility for each theme and export the page
lyrListCIR = ['CIR_doqq_flight_dates','Infrared Ortho Imagery']
# Don't assume the layers are turned off...Turn them off first.
print("First, turn on all the layers")
for lyrName in lyrListCIR:
lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
lyr.visible = True
#Change title text
TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]
TextElement.text = lyrName
#Export each theme to a temporary PDF and append to the final PDF
tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')
if os.path.exists(tmpPdf):
os.remove(tmpPdf)
arcpy.mapping.ExportToPDF(mxd, tmpPdf)
print("\tPDF Exported to following path: " + tmpPdf)
finalPdf.appendPages(tmpPdf)
#Turn off layer visibility and clean up for next pass through the loop
for lyrName in lyrListCIR:
lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
lyr.visible = False
del lyr
################################### 2008 Data ##############################################
# Turn on visibility for each theme and export the page
lyrList2008 = ['ortho_1-1_1n_ny053_2008_1','2008 Ortho Imagery']
# Don't assume the layers are turned off...Turn them off first.
print("2008 data")
for lyrName in lyrList2008:
lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
lyr.visible = True
#Change title text
TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]
TextElement.text = lyrName
#Export each theme to a temporary PDF and append to the final PDF
tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')
if os.path.exists(tmpPdf):
os.remove(tmpPdf)
arcpy.mapping.ExportToPDF(mxd, tmpPdf)
print("\tPDF Exported to following path: " + lyr.name + tmpPdf)
finalPdf.appendPages(tmpPdf)
#Turn off layer visibility and clean up for next pass through the loop
for lyrName in lyrList2008:
lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
lyr.visible = False
del lyr
################################### 2009 Data ##############################################
# Turn on visibility for each theme and export the page
lyrList2009 = ['ortho_1-1_1n_ny053_2009_1','2009 Ortho Imagery']
# Don't assume the layers are turned off...Turn them off first.
print("2009 data")
for lyrName in lyrList2009:
lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
lyr.visible = True
#Change title text
TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]
TextElement.text = lyrName
#Export each theme to a temporary PDF and append to the final PDF
tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')
if os.path.exists(tmpPdf):
os.remove(tmpPdf)
arcpy.mapping.ExportToPDF(mxd, tmpPdf)
print("\tPDF Exported to following path: " + lyr.name + tmpPdf)
finalPdf.appendPages(tmpPdf)
#Turn off layer visibility and clean up for next pass through the loop
for lyrName in lyrList2009:
lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
lyr.visible = False
del lyr
################################### 2011 Data ##############################################
# Turn on visibility for each theme and export the page
lyrList2011 = ['ortho_1-1_1n_ny053_2011_1','2011 Ortho Imagery']
# Don't assume the layers are turned off...Turn them off first.
print("2011 Data")
for lyrName in lyrList2011:
lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
lyr.visible = True
#Change title text
TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]
TextElement.text = lyrName
#Export each theme to a temporary PDF and append to the final PDF
tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')
if os.path.exists(tmpPdf):
os.remove(tmpPdf)
arcpy.mapping.ExportToPDF(mxd, tmpPdf)
print("\tPDF Exported to following path: " + lyr.name + tmpPdf)
finalPdf.appendPages(tmpPdf)
#Turn off layer visibility and clean up for next pass through the loop
for lyrName in lyrList2011:
lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
lyr.visible = False
del lyr
################################### 2013 Data ##############################################
# Turn on visibility for each theme and export the page
lyrList2013 = ['ortho_1-1_1n_s_ny053_2013_1','2013 Ortho Imagery']
# Don't assume the layers are turned off...Turn them off first.
print("2013 data")
for lyrName in lyrList2013:
lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
lyr.visible = True
#Change title text
TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]
TextElement.text = lyrName
#Export each theme to a temporary PDF and append to the final PDF
tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')
if os.path.exists(tmpPdf):
os.remove(tmpPdf)
arcpy.mapping.ExportToPDF(mxd, tmpPdf)
print("\tPDF Exported to following path: " + lyr.name + tmpPdf)
finalPdf.appendPages(tmpPdf)
#Turn off layer visibility and clean up for next pass through the loop
for lyrName in lyrList2013:
lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
lyr.visible = False
del lyr
################################### 2015 Data ##############################################
# Turn on visibility for each theme and export the page
lyrList2015 = ['ortho_1-1_hn_s_ny053_2015_1','2015 Ortho Imagery']
# Don't assume the layers are turned off...Turn them off first.
print("2015 data")
for lyrName in lyrList2015:
lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
lyr.visible = True
#Change title text
TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]
TextElement.text = lyrName
#Export each theme to a temporary PDF and append to the final PDF
tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')
if os.path.exists(tmpPdf):
os.remove(tmpPdf)
arcpy.mapping.ExportToPDF(mxd, tmpPdf)
print("\tPDF Exported to following path: " + lyr.name + tmpPdf)
finalPdf.appendPages(tmpPdf)
#Turn off layer visibility and clean up for next pass through the loop
for lyrName in lyrList2015:
lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
lyr.visible = False
del lyr
################################### 2019 Data ##############################################
# Turn on visibility for each theme and export the page
lyrList2019 = ['NAIP2019_otho_flight_lines_a_NY','2019 Ortho Imagery']
# Don't assume the layers are turned off...Turn them off first.
print("2019 data")
for lyrName in lyrList2019:
lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
lyr.visible = True
#Change title text
TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]
TextElement.text = lyrName
#Export each theme to a temporary PDF and append to the final PDF
tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')
if os.path.exists(tmpPdf):
os.remove(tmpPdf)
arcpy.mapping.ExportToPDF(mxd, tmpPdf)
print("\tPDF Exported to following path: " + lyr.name + tmpPdf)
finalPdf.appendPages(tmpPdf)
#Turn off layer visibility and clean up for next pass through the loop
for lyrName in lyrList2019:
lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
lyr.visible = False
del lyr
finalPdf.saveAndClose()
del mxd, df, finalPdf
Is there anyway to intergrate both a vertical and horizonal result? Selecting the tracts i need maps for and iterating through making maps for each selected tract?
Thanks