#This script will take an mxd and export a pdf mapbook for#each thematic layer in the map. The subtitle of the map #will be dynamically changed with each mapbook.#Import the arcpy packageimport arcpy #Assign the Western States Mapping Document to variable mxd mxd = arcpy.mapping.MapDocument(r"C:\ArcPy_Training\Map_Documents\Western_States.mxd")#Create a data driven pages object using "mxd" and assign it to variable "ddp"ddp = mxd.dataDrivenPages #Create a list of all text elements in the map layouttextlist = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT")#Cycle through the text elements for txt in textlist: #When you find one whose text says "MAP SUBTITLE"... if txt.text == r"MAP SUBTITLE": #....Assign it to variable "subtitle" subtitle = txt #Create a list of the layers in the map documentlayerlist = arcpy.mapping.ListLayers(mxd) #Cycle through each layerfor lyr in layerlist: #If the layer is NOT visible... if lyr.visible == False: #...Turn the layer on lyr.visible = True #Change the Subtitle text element to match the layer's name subtitle.text = lyr.name #Create a string showing the path of the pdf that will be written out pdfpath = "C:\\arcpy_training\\pdfs\\" + lyr.name + r" mapbook.pdf" #Print that we are exporting a mapbook print "Exporting " + pdfpath + "....." #Export the mapbook to pdf mxd.dataDrivenPages.exportToPDF(pdfpath,"ALL") #Turn the layer off again lyr.visible = False #Delete variables to clean up memory usagedel ddp, mxd print "Done!"
>>> import arcpy, os>>> outPath=r"F:\projectx\\">>> finalPdf=arcpy.mapping.PDFDocumentCreate(outPath + "ParcelReport.pdf")>>> mxd=arcpy.mapping.MapDocument(r"F:\projectx\testscript.mxd")>>> df=arcpy.mapping.ListDataFrames(mxd, "Layers")[0]>>> lyrList=["perc_nwa", "perc_old"]>>> for lyrName in lyrList:... lyr=arcpy.mapping.ListLayers(mxd, lyrName, df)[0]... lyr.visible=True... >>> tmpPdf=outPath + lyrName + "_temp.pdf">>> if os.path.exists(tmpPdf):... os.remove(tmpPdf)... >>> arcpy.mapping.ExportToPDF(mxd, tmpPdf)>>> finalPdf.appendPages(tmpPdf)>>> lyr.visible=False>>> del lyr, tmpPdf>>> del mxd, df, finalPdf
arcpy.mapping opens up many possibilities for the types of map books you can create. For example, you can create a thematic atlas with multiple pages specifying a different theme on each page. The following example zooms to a selected parcel, toggles on different layer visibility and exports the layout for multiple themes in order to create a parcel report with a soil map, a flood map and a zoning map: import arcpy, os #Specify output path and final output PDF outPath = r"C:\MyProject\output\\" finalPdf = arcpy.mapping.PDFDocumentCreate(outPath + "ParcelReport.pdf") #Specify the map document and the data frame mxd = arcpy.mapping.MapDocument(r"C:\MyProject\MyParcelMap.mxd") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] #Select a parcel using the LocAddress attribute and zoom to selectedparcelLayer = 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 from: http://blogs.esri.com/dev/blogs/arcgisdesktop/archive/2010/12/14/combining-data-driven-pages-with-python-and-arcpy.mapping.aspx
It is not possible in arcpy.mapping. The Python mapping module is very very simple: you can only move about and make (some) adjustements to elements already in existance, and apply symbolization already stored in a layer file.To create layout elements, and do the other stuff you want, you will need to use ArcObjects. For that you need the (free) VBA capability for Arc10 (knowing that VBA is slated to be lost forever in 10.1) OR use VB.Net or C#.
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.