Getting Data Driven Pages to scale raster symbology from each page's current extent

450
4
Jump to solution
02-05-2013 06:54 AM
JeffOlsenholler
New Contributor
I'm generating a country-wide atlas at the (U.S. equivalent) county level.  I'm auto-clipping the raster coverages to each county-equivalent.  All is fine and good, except that the rasters do not scale to the current display extent unless I go to layer propertieson each individual layer.  That's not a practical solution.

So, is there a python script that will both recalculate the stretch for every data page and then export each page as an appropriately named PDF file?  Or is there an ESRI patch that will address this refresh issue?

Thanks,
Jeff
0 Kudos
1 Solution

Accepted Solutions
JeffBarrette
Esri Regular Contributor
Unfortunately arcpy.mapping can't work with the stretched renderer.  Rather than the raster being a permanent layer in the MXD, what if you tried adding and deleting it with each page? 

Below is a sample snippet of code from the arcpy.mapping DDP Class help topic that I modified to add/remove your raster between DDP pages.  It just requires that you save your raster out as a layer file.

import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\ParcelAtlas.mxd") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] rasLyrFile = arcpy.mapping.Layer(r"C:\Project\Data\Basemap.lyr") for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):     mxd.dataDrivenPages.currentPageID = pageNum     arcpy.mapping.AddLayer(df, rasLyrFile, "BOTTOM")   #You can use InsertLayer for more precise placement        mxd.dataDrivenPages.exportToPDF(r"C:\Project\Output\Page" + str(pageNum) + ".pdf", "CURRENT")     arcpy.mapping.RemoveLayer(df, rasLyrFile) del mxd


Jeff

View solution in original post

0 Kudos
4 Replies
JeffBarrette
Esri Regular Contributor
I'm not sure what you mean by "rasters do not scale to the current display extent".

If the rasters are symbolized with a raster classified renderer you may be able to call .Refresh() to get what you want.  Take a look at:

http://resources.arcgis.com/en/help/main/10.1/#/RasterClassifiedSymbology/00s30000005p000000/

Jeff
0 Kudos
JeffOlsenholler
New Contributor
What I mean by "rasters do not scale to the current display extent" is that as each new page is generated with, say a DEM, the scale does not change according to the current display extent, but remains what is was on page 1.  In the case of the DEM, I'd like to have each data driven page recalculate the layer properties to rescale the DEM according to the current extent - see attached image.
0 Kudos
JeffBarrette
Esri Regular Contributor
Unfortunately arcpy.mapping can't work with the stretched renderer.  Rather than the raster being a permanent layer in the MXD, what if you tried adding and deleting it with each page? 

Below is a sample snippet of code from the arcpy.mapping DDP Class help topic that I modified to add/remove your raster between DDP pages.  It just requires that you save your raster out as a layer file.

import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\ParcelAtlas.mxd") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] rasLyrFile = arcpy.mapping.Layer(r"C:\Project\Data\Basemap.lyr") for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):     mxd.dataDrivenPages.currentPageID = pageNum     arcpy.mapping.AddLayer(df, rasLyrFile, "BOTTOM")   #You can use InsertLayer for more precise placement        mxd.dataDrivenPages.exportToPDF(r"C:\Project\Output\Page" + str(pageNum) + ".pdf", "CURRENT")     arcpy.mapping.RemoveLayer(df, rasLyrFile) del mxd


Jeff

View solution in original post

0 Kudos
TheoFaull
Occasional Contributor III
Unfortunately arcpy.mapping can't work with the stretched renderer.  Rather than the raster being a permanent layer in the MXD, what if you tried adding and deleting it with each page? 

Below is a sample snippet of code from the arcpy.mapping DDP Class help topic that I modified to add/remove your raster between DDP pages.  It just requires that you save your raster out as a layer file.


import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\ParcelAtlas.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
rasLyrFile = arcpy.mapping.Layer(r"C:\Project\Data\Basemap.lyr")
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
    mxd.dataDrivenPages.currentPageID = pageNum
    arcpy.mapping.AddLayer(df, rasLyrFile, "BOTTOM")   #You can use InsertLayer for more precise placement  
    mxd.dataDrivenPages.exportToPDF(r"C:\Project\Output\Page" + str(pageNum) + ".pdf", "CURRENT")
    arcpy.mapping.RemoveLayer(df, rasLyrFile)
del mxd


Jeff

Jeff,
I'm trying this code now in the python module of my DDP project. I replaced the layer and mxd location lines, and also the export location. However when I run it it says:
Runtime error
Traceback (most recent call last):
  File "<string>", line 3, in <module>
IndexError: list index out of range
0 Kudos