lundi 23 mars 2015

Using Python to export multiple layers to .pdfs


I am fairly new to Python. Here is my question:


I have individual range maps for several hundred invertebrate species, each of which has the same extent. I would like to export these maps to .pdf using Python in ArcGIS 10.2. Each map also needs to have a "Places" and "Rivers" shapefile (these two shapefiles are the same for all of the species).


I have tried modifying the script from a similar post (Export each layer in map to a separate image), but I can't seem to get the range map rasters to show up.


The following script needs work (and I must give credit to Roy, who answered the other post I mentioned), but this is what I have so far:



mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, '')[0]

allLayers = arcpy.GetParameterAsText(0)
lyrList = allLayers.split(";")

PDFPath = arcpy.GetParameterAsText(1)

for lyr in arcpy.mapping.ListLayers(mxd, '', df):
for layer in lyrList:
if lyr.name == "Places":
lyr.visible = True
if lyr.name == "Rivers":
lyr.visible = True
if lyr.name == layer:
lyr.visible = True
arcpy.mapping.ExportToPDF(mxd, os.path.join(r"C:\Project_7\Newer_data\Inverts\GO", PDFPath, lyr.name + ".pdf"), resolution=150) #EDIT: This line is working now.
lyr.visible = False
arcpy.RefreshActiveView()
del mxd


I don't think I have added the loops in the correct place. I need the "Places" and "Rivers" layers displayed on the map every time (i.e., for each range map).


I am unclear how to modify the following to fit my data: EDIT: I HAVE FIGURED THIS PART OUT THANKS TO jon_two. arcpy.mapping.ExportToPNG(mxd, PDFPath+"\" + lyr.name + ".pdf") Specifically, what do I replace the "\" with? Do both backslashes need to be there? (i.e., PDFPath+"C:\Project_7\Newer_data\Inverts\GO\)


Also, I have tried just running the following code without the addition of the two shapefiles, but the layers don't seem to turn on. EDIT: THIS IS THE PART THAT STILL ISN'T WORKING.



for lyr in arcpy.mapping.ListLayers(mxd, '', df):
for layer in lyrList:
if lyr.name == layer:
lyr.visible = True
arcpy.RefreshActiveView()


Thanks in advance for any suggestions.





Aucun commentaire:

Enregistrer un commentaire