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'm customizing an automated mapping method using arcpy.mapping and data driven pages.

Essentially I have a script that loops through each page, and modifies the location of the inset map, legend, and other map or graphic elements.

I've got everything working, except for some maps, it is necessary to change the extent of the main dataframe so that the inset map, or legend does not overlap with the region of interest. As an example, the data frame may need to shift 500 metres North and East, so that there is no overlap. This is what I can't get to work.

I'm using a for loop, with conditional statements to make the necessary adjustments. An example condition is:

if (pgIndex == 4):

    # Set position of the Legend
    elLeg = arcpy.mapping.ListLayoutElements(tempMap,"LEGEND_ELEMENT", "")[0]
    elLeg.elementPositionX = 0.0186
    elLeg.elementPositionY = 0.4124
    # Move scalebar
    scaleBar = arcpy.mapping.ListLayoutElements(tempMap, "MAPSURROUND_ELEMENT", "Alternating Scale Bar")[0]
    scaleBar.elementPositionX = 0.1
    scaleBar.elementPositionY = 0.1
    #Move North Arrow
    NorthArrow = arcpy.mapping.ListLayoutElements(tempMap, "MAPSURROUND_ELEMENT", "North Arrow")[0]
    NorthArrow.elementPositionX = 0.75
    NorthArrow.elementPositionY = 0.1
    #Move Legend NeatLine
    Neatline = arcpy.mapping.ListLayoutElements(tempMap, "GRAPHIC_ELEMENT", "")[0]
    Neatline.elementPositionX = 0
    Neatline.elementPositionY = 0
    #Move inset map position
    inset = arcpy.mapping.ListDataFrames(tempMap, "LocatorDF")[0]
    inset.ElementPositionX = 0
    inset.ElementPositionY = 3.25
    #Set extent for main data frame (THIS IS WHAT IS NOT WORKING)
    mainMap = arcpy.mapping.ListDataFrames(tempMap, "MainDF")[0]
    extent_4 = arcpy.Extent(423017.450685167,4991568.14747271,438257.481165228,4976328.11699265)
    mainMap.extent = extent_4
share|improve this question

1 Answer 1

up vote 3 down vote accepted

Your extent object is not valid.

The syntax to create an arcpy.Extent object is arcpy.Extent({XMin},{YMin},{XMax},{YMax}). However, your code currently has the YMin parameter (4,991,568) larger than the YMax parameter (4,976,328). Perhaps you intended to have:

extent_4 = arcpy.Extent(423017.450685167,4976328.11699265,438257.481165228,4991568.14747271)

I'm surprised that arcpy didn't throw an error though. Do you have this inside of a larger try-except statement?

share|improve this answer
Thanks for picking that up @dmahr. I think the main issue is that I'm taking advantage of data driven pages in my code. As a result, I think the extent of the dataframe is limited by the data "driving" the pages. My work around at this point is to use point data (instead of polygon data) to drive the pages, and change the scale where necessary instead of the extent. It's not the most elegant way of doing it, but it works. –  Czed Sep 6 '12 at 18:58
Yeah, Data Driven Pages becomes unecessary once you start using the arcpy mapping module to edit map elements and data frame extents. I'm not surprised that it overrode your data frame extent setting. –  dmahr Sep 6 '12 at 19:06

Your Answer


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.