2

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
asked Sep 5, 2012 at 17:48

1 Answer 1

5

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?

answered Sep 5, 2012 at 23:08
2
  • 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. Commented Sep 6, 2012 at 18:58
  • 1
    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. Commented Sep 6, 2012 at 19:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.