+ Reply to Thread
Results 1 to 3 of 3

Thread: updating extent of dataframe

  1. #1
    Anthony Fischbach
    Join Date
    Mar 2012
    Posts
    3
    Points
    0
    Answers Provided
    0


    0

    Default updating extent of dataframe

    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)

  2. #2
    Jeffrey Barrette

    Join Date
    Oct 2009
    Posts
    714
    Points
    201
    Answers Provided
    64


    0

    Default Re: updating extent of dataframe

    Try setting your extent twice in a row:

    Code:
    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

  3. #3
    Anthony Fischbach
    Join Date
    Mar 2012
    Posts
    3
    Points
    0
    Answers Provided
    0


    0

    Default Re: updating extent of dataframe

    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

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts