updating extent of dataframe

3028
2
03-02-2012 01:15 PM
AnthonyFischbach
New Contributor
I wish to work through a long list of tracked animal behavior bouts,
updating my map layer definitions to the depict behaviors from this bout,
zooming to the behaviors within this bout, and exporting the resultant map as a graphic.

Here is a script outline to do this.

The problem is that the map extent does not get updated after the first bout is handled.

Have I missed a trick to ensure that the map extent is properly updated and the result
reflected in the output map?



import pyodbc
cnxn = pyodbc.connect(DRIVER, DBQ=  db, autocommit=True)
cursor = cnxn.cursor()
SQL = "SELECT * from trackedAnimalBehaviorBout_tbl"
cursor.execute(SQL)

import arcpy
for row in cursor.fetchall():
Bout = row.Bout ## grab behavior bout from trackedAnimalBehaviorBout_tbl

mxd=arcpy.mapping.MapDocument(MYMXD) ## Open an mxd
df=arcpy.mapping.ListDataFrames(mxd)[0] ## grab the first dataframe
for lyr in arcpy.mapping.ListLayers(mxd): ## Loop through list of layers in the dataframe
  if lyr.name == "BehaviorX":    ## Handle layer for 'BehaviorX'
            dfQ = "[BehaviorX] = 1 and [Bout] = '" + Bout + "'"
            lyr.definitionQuery = dfQ   ## Update layer def query
            BehaveBoutExtent = lyr.getExtent() ## grab hold of Exent of this layer

try: ## Try to zoom the dataframe to the extent of Behavior X for row.Bout
        print ("updating df extent from ")
        print df.extent
        print "to"
        print BehaveBoutExtent
        df.extent = BehaveBoutExtent   ## Zoom to the BehaveBoutExtent
        print("Updated Extent to")
        print df.extent

try: ## Export to a graphic file for later reveiw
  mxd.save()
  png = (r"\\" + r"MYFILELOCATION" + os.sep + str(Bout) + ".png")
        arcpy.mapping.ExportToPNG(mxd,png, resolution=80)
0 Kudos
2 Replies
JeffBarrette
Esri Regular Contributor
Try setting your extent twice in a row:

BehaveBoutExtent = lyr.getExtent() 
df.extent = BehaveBoutExtent
df.extent = BehaveBoutExtent 


We found an issue with 10.0 where in some cases the extent does NOT get set properly based on several conditions.

Jeff
0 Kudos
AnthonyFischbach
New Contributor
Jeff, thank you for your reply. 
I am afraid that this has not worked for me.
Please let me know if there will there be an anouncement when these tools become stable for general use.

Until that time I will work through R's spatial tools
(http://cran.r-project.org/web/packages/sp/index.html)
to meet my scripted cartography needs.

Best Wishes, -Tony
0 Kudos