EAlterton

Definition Query

Discussion created by EAlterton on Mar 5, 2013
Latest reply on Oct 29, 2013 by EAlterton
Hello

I'm trying to use a python script tool to generate a number of maps showing walking routes and their starting points.

I've set up the data driven pages based on each of the walking routes, and have written a script that runs through each page and only displays the walking route in question. Then exports each map to a pdf.

This works fine except that all the starting point information shows all the time.
Each walking route record has the name of the starting point associated with it stored in a field. How can I script taking the value from the walking route field and use it to create a definition query in the starting point dataset? This definition query will need to be updated each time the script iterates through the data driven pages.

The script I'm using is below - where and what do I need to add to get the starting point layer working at the same time?

I hope this makes sense

Thanks
Emma



[INDENT]import arcpy
import os

#Get parameter for input project location
mxdName = arcpy.GetParameterAsText(0)
#Get parameter for output location
outPath = arcpy.GetParameterAsText(1)+"\\"
finalPdf = arcpy.mapping.PDFDocumentCreate(outPath + "HealthWalks.pdf")

#Specify the map document and the data frame
mxd = arcpy.mapping.MapDocument(mxdName)
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]

#Get data driven index layer and name field
lyrName = mxd.dataDrivenPages.indexLayer
lyrField = mxd.dataDrivenPages.pageNameField.name

pLayer = arcpy.mapping.ListLayers(mxd, lyrName)[0]

for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
mxd.dataDrivenPages.currentPageID = pageNum
fldName = mxd.dataDrivenPages.pageRow.NAME  #Get field used in dynamic query
pLayer.definitionQuery = lyrField + " = '" + fldName + "'"

#Export each theme to a temporary PDF and append to the final PDF
tmpPdf = outPath + fldName + "_temp.pdf"
if os.path.exists(tmpPdf):
    os.remove(tmpPdf)
arcpy.mapping.ExportToPDF(mxd, tmpPdf)
finalPdf.appendPages(tmpPdf)
os.remove(tmpPdf)

del tmpPdf
del mxd, df, finalPdf[/INDENT]

Outcomes