Adding and auto extracting scale information

465
2
05-09-2012 06:32 PM
cle444
by
New Contributor III
Hello Arc desktop users/experts/developers/whoever you ares,,,

Much appreciated if you could kindly go through the longest question in my forum career and provide a solution or ideas.

Background:
I have got a polygon feature class of 100 features. I use data driven page tool to loop through these features to produce 100 maps. In data driven page settings, the extent configuration is 'use best fit with 20% margin', which results a different scale for each of these 100 maps/polygon features.

Question:
Since scale for each page/polygon feature varies after running the data driven page tool, I am wondering if there is an automated way of extracting and storing the scale information? Once I get this 'best scale' for each polygon, I can add it as an extra field 'SCALE' for other cartography purposes.

Thanks!
Regrds,
Hua
Tags (2)
0 Kudos
2 Replies
MarcinGasior
Regular Contributor
I crafted some code which may be helpful.
First, create Scale field of double type in your data. Then adjust pathes and rounding in script:
import arcpy
mxdDocumentPath = r"C:\tmp\MapProjects\DataDrivenPages.mxd"
mxd = arcpy.mapping.MapDocument(mxdDocumentPath)
indexLayer = r"C:\tmp\Test.gdb\PolygonFeatures"


#iterate through data driven pages
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
    mxd.dataDrivenPages.currentPageID = pageNum
    #check first data frame from Layuot (if you have more than one use wilcard, eg. ListDataFrames(mxd,"Layers")
    df = arcpy.mapping.ListDataFrames(mxd)[0]
    
    #get the scale of current page (the scale taken is not rounded so first define round factor)
    #define round factor: -2: round scale to 100, -1: round scale to 10, etc.
    roundFactor = -2
    pageScale = round(df.scale, roundFactor)

    #take some identificator of feature in current page, eg. OBJECTID, FID, etc.
    ddpFeatureID = mxd.dataDrivenPages.pageRow.OBJECTID
    
    #open UpdateCursor on one row of indexLayer
    #if you use TEXT field as an identificator use '"textField" = ' + "'" + str(ddpFeatureID) + "'" as a WHERE clause
    updCur = arcpy.UpdateCursor(indexLayer, '"OBJECTID" = ' + str(ddpFeatureID))
    
    for updCurRow in updCur:
        #update Scale field of DOUBLE type (create this field before running script)
        updCurRow.setValue("Scale", pageScale)
        updCur.updateRow(updCurRow)
    del updCur
0 Kudos
cle444
by
New Contributor III
I crafted some code which may be helpful.
First, create Scale field of double type in your data. Then adjust pathes and rounding in script:
import arcpy
mxdDocumentPath = r"C:\tmp\MapProjects\DataDrivenPages.mxd"
mxd = arcpy.mapping.MapDocument(mxdDocumentPath)
indexLayer = r"C:\tmp\Test.gdb\PolygonFeatures"


#iterate through data driven pages
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
    mxd.dataDrivenPages.currentPageID = pageNum
    #check first data frame from Layuot (if you have more than one use wilcard, eg. ListDataFrames(mxd,"Layers")
    df = arcpy.mapping.ListDataFrames(mxd)[0]
    
    #get the scale of current page (the scale taken is not rounded so first define round factor)
    #define round factor: -2: round scale to 100, -1: round scale to 10, etc.
    roundFactor = -2
    pageScale = round(df.scale, roundFactor)

    #take some identificator of feature in current page, eg. OBJECTID, FID, etc.
    ddpFeatureID = mxd.dataDrivenPages.pageRow.OBJECTID
    
    #open UpdateCursor on one row of indexLayer
    #if you use TEXT field as an identificator use '"textField" = ' + "'" + str(ddpFeatureID) + "'" as a WHERE clause
    updCur = arcpy.UpdateCursor(indexLayer, '"OBJECTID" = ' + str(ddpFeatureID))
    
    for updCurRow in updCur:
        #update Scale field of DOUBLE type (create this field before running script)
        updCurRow.setValue("Scale", pageScale)
        updCur.updateRow(updCurRow)
    del updCur


Well, this is not 'may be help', it definitely helps a lot. Although I am not a good python user, your code makes a lot sense. I will try it and let you know.

I guess another way would be generate extent/envelop for each polygon and then somehow calculate scale based on corresponding envelop size...
0 Kudos