Performance Issue when using arcpy.mapping.ListDataFrames

1041
8
11-07-2011 06:48 AM
ShawnaErnst
Occasional Contributor
I am using arcpy.mapping to create an atlas that will run via ArcGIS Server - the atlas uses two dataframes.  One of the dataframes holds the data driven pages grid and the other dataframe has a locked extent (so it zooms to wherever the atlas dataframe is zoomed to).  Everything works very well, except very slow performance for one step of my code. 

Here's some of the code I'm running- to find the mxd and then start updating some definition queries in my second dataframe (the one that has a locked extent):

mxd = arcpy.mapping.MapDocument(r"pathtomxd.mxd")
print datetime.datetime.now()

for df in arcpy.mapping.ListDataFrames(mxd, "Street View"):
     print datetime.datetime.now()


When I compare the two datetime stamps- there is a 7 minute gap between the two.  Why is that?  The rest of the code runs in just about a minute (which is fine since it is exporting a whole map book).  But I just can't figure out why this one step takes 7 minutes.

Any ideas would be most appreciated!  😄

Shawna
Tags (2)
0 Kudos
8 Replies
ShawnaErnst
Occasional Contributor
Update:  I've found that it doesn't seem to matter what the second line of code is...even if I simply reference my data driven pages, it takes 6-7 minutes between the call to the mxd and the next call.

mxd = arcpy.mapping.MapDocument(r"pathtomxd.mxd")
print datetime.datetime.now()

ddp = mxd.dataDrivenPages
print datetime.datetime.now()


Why would that take so long?
0 Kudos
JeffBarrette
Esri Regular Contributor
How large is the mxd?  Is it possible it is bloated? Have you tried saving it to a new file?

Do you have any broken SDE data sources?

Jeff
0 Kudos
ShawnaErnst
Occasional Contributor
Hi Jeff,

There are sixteen layers in my mxd and no broken connections.  I have tried saving it to a new file, but that doesn't make a difference in speed.

I do have a join to a SQL database for labels, but I've tested removing the join and don't see any performance gain.  It still takes 7 minutes.

Do you have any other ideas for me to test?

Thanks,
Shawna
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Can you try using the 'time' module to see if you have any improvement in performance? 

import arcpy, time
now = time.localtime(time.time())

mxd = arcpy.mapping.MapDocument(r"C:\TaxMapPages_DDP.mxd")
print time.asctime(now)

ddp = mxd.dataDrivenPages
print time.asctime(now)
0 Kudos
ShawnaErnst
Occasional Contributor
Okay- the culprit is my atlas grid.  I tried creating a very small grid (just a few pages) and that runs almost instantly.

So, I guess I need to have a smaller grid.  That's unfortunate because I really need a comprehensive, County-wide atlas.

Jake- thanks for your post, using a different time module wasn't the issue in this case.
0 Kudos
JeffBarrette
Esri Regular Contributor
Could you please send me a map package that includes your grid.  I'd like to do some testing on it.  There is no reason it should take 7 minutes.  Please send map package or zip to jbarrette@esri.com

Thanks,
Jeff
0 Kudos
ShawnaErnst
Occasional Contributor
I figured out a work-around for the performance issue.  I don't load my entire atlas grid at once.  Instead, I have a definition query on the grid to limit the number of pages.  Then (since this script is going to take user input) I have my users enter in their area of interest.  I take that input and updated my definition query.  Finally, I have to refresh the data driven pages object to have the atlas update to the new area of interest.

Adding these additional steps made it so an atlas book that had taken 7 minutes to run took just 30 seconds.  So much better!!!
0 Kudos
ShawnaErnst
Occasional Contributor
Correction - you do not need to use definition queries to limit the number of atlas pages.  After working with Jeff (thanks, Jeff) - we determined that I had a corrupt atlas grid.  Once my grid was fixed, my performance issue was resolved with no need for extra steps in code.
0 Kudos