Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have data driven pages enabled on a mxd, with a page definition query set on one of the layers to only show features that match the current index feature. This layer looks like this:

Full layer

After enabling the page definition query, right clicking on the layer and clicking Zoom to Layer yields this:

Using the UI to zoom to layer

I would like to perform this function in arcpy. Setting the data frame's extent to the extent of the layer using the getExtent() method zooms to the extent of the entire layer:

Arcpy method

This method does not honour the extent of the page definition query. I cannot use the zoomToSelectedFeatures() method of the data frame because nothing is actually selected; similarly I cannot use the layer's getSelectedExtent() method. The only workaround I see is updating a normal definition query on the layer from arcpy and then getting the extent.

My question is, is there a way to use the UI's Zoom to Layer method from arcpy?

share|improve this question
    
I believe you can find your answer here. gis.stackexchange.com/questions/1711/… –  mittence Oct 3 '13 at 16:15
    
@mittence That's not what I asked, I am referring specifically to zooming to the extent defined by a page definition query set by having data driven pages enabled. No features are actually selected, so using the normal getSelectedFeatures() method zooms to the extent of the entire layer. –  Arabella Oct 4 '13 at 5:06

1 Answer 1

As suggested in your Question, the way that I do this is by "updating a normal definition query on the layer from arcpy" and then using getSelectedExtent().

Some code using a Queensland (Australia) Lot on Plan example:

import arcpy

inputMap = r"C:\temp\test.mxd"
inputLotNo = "1"
inputPlanNo = "RP1"

mxd = arcpy.mapping.MapDocument(inputMap)
df = arcpy.mapping.ListDataFrames(mxd,"Main Map")[0]
subjectLotLayer = arcpy.mapping.ListLayers(mxd,"Subject Lot",df)[0]

where_clause = "LOT = '" + inputLotNo + "' AND PLAN = '" + inputPlanNo + "'"
subjectLotLayer.definitionQuery = where_clause
df.extent = subjectLotLayer.getSelectedExtent(False)

If you must do this using page definition queries then I suspect that you will need to work through the support system and/or ArcGIS Ideas to try and achieve that.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.