Making an atlas of thematic maps with DDP

476
3
09-03-2013 07:30 AM
JasmineBath
New Contributor
HELP!

Trying to used arcpy and ddp to make a series of pdfs (or one large pdf) that displays five different layers turned on and off for each index feature.

I have found serveral different codes that all could be helpful, but I'm having toruble putting them together.

From http://blogs.esri.com/esri/arcgis/2010/12/14/combining-data-driven-pages-with-python-and-arcpy-mappi...
import arcpy, os

#Specify output path and final output PDF
outPath = r�?�C:MyProjectoutput\�?�
finalPdf = arcpy.mapping.PDFDocumentCreate(outPath + �??ParcelReport.pdf�?�)

#Specify the map document and the data frame
mxd = arcpy.mapping.MapDocument(r�?�C:MyProjectMyParcelMap.mxd�?�)
df = arcpy.mapping.ListDataFrames(mxd, �??Layers�?�)[0]

#Select a parcel using the LocAddress attribute and zoom to selected
parcelLayer = arcpy.mapping.ListLayers(mxd, �??Parcels�?�, df)[0]
arcpy.SelectLayerByAttribute_management(parcelLayer, �??NEW_SELECTION�?�, �??�?�LocAddress�?� = �??519 Main St�??�?�)
df.zoomToSelectedFeatures()

#Turn on visibility for each theme and export the page
lyrList = ["Soils", "Floodplains", "Zones"]
for lyrName in lyrList:
     lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
     lyr.visible = True

     #Export each theme to a temporary PDF and append to the final PDF
     tmpPdf = outPath + lyrName + �??_temp.pdf�?�
     if os.path.exists(tmpPdf):
          os.remove(tmpPdf)
     arcpy.mapping.ExportToPDF(mxd, tmpPdf)
     finalPdf.appendPages(tmpPdf)
    
     #Turn off layer visibility and clean up for next pass through the loop
     lyr.visible = False
     del lyr, tmpPdf
del mxd, df, finalPdf

Will this loop through all the index features in my map?

Thanks!
0 Kudos
3 Replies
JeroenWisse
New Contributor
I am not entirely sure what you are trying to do.
Could you please explain it.

Also when you post code can you use the code tag? It makes the code more readable.
0 Kudos
JasmineBath
New Contributor
Basically I have 800+ districts and for each one I want to create a PDF with five different maps (five different layers turned on and off).

So instead of five 800-page pdfs, or 800 * 5 individual pdfs, I want 800 pdfs each with five page.
0 Kudos
JeroenWisse
New Contributor
I haven't tested this code but it should work, or at least not much editing 🙂

#Specify output path and final output PDF
outPath = r"C:MyProjectoutput\"
finalPdf = arcpy.mapping.PDFDocumentCreate(outPath + "ParcelReport.pdf")

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

#Select a parcel using the LocAddress attribute and zoom to selected
parcelLayer = arcpy.mapping.ListLayers(mxd, "Parcels", df)[0]
arcpy.SelectLayerByAttribute_management(parcelLayer, "NEW_SELECTION", "LocAddress" = '519 Main St')
df.zoomToSelectedFeatures()

#Turn on visibility for each theme and export the page
lyrList = ["Soils", "Floodplains", "Zones"]
for lyrName in lyrList:
    lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
    lyr.visible = True

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

    #Turn off layer visibility and clean up for next pass through the loop
    lyr.visible = False
    del lyr, tmpPdf
    
del mxd, df, finalPdf



The above code only exports the 3 pdf's for location address 519 Main St.
The layers it sets as visible are Soils,Floodplains and Zones.

If you want to automate the entire process then you need to have a list or a way to get the locaddresses.
You could then loop trough the location adressess like this:
lyrList = ["Soils", "Floodplains", "Zones"]
for locaAddress in locAdresses:
    finalPdf = arcpy.mapping.PDFDocumentCreate(outPath + "ParcelReport "+locAddress+".pdf")
    arcpy.SelectLayerByAttribute_management(parcelLayer, "NEW_SELECTION", "LocAddress" = locAddress)
    df.zoomToSelectedFeatures()
    for lyrName in lyrList:
        lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
        lyr.visible = True

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

        #Turn off layer visibility and clean up for next pass through the loop
        lyr.visible = False
        del lyr, tmpPdf

Again the above code isn't tested but the idea is that it should give you 800 pdf's name for example ParcelRepor t519 Main St.pdf
It should contain 3 pages (because the lyrList has 3 items).

I hope this helps
0 Kudos