<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Adding and auto extracting scale information in ArcGIS Enterprise Portal Questions</title>
    <link>https://community.esri.com/t5/arcgis-enterprise-portal-questions/adding-and-auto-extracting-scale-information/m-p/232908#M3091</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello Arc desktop users/experts/developers/whoever you ares,,,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Much appreciated if you could kindly go through the longest question in my forum career and provide a solution or ideas.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Background:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Question:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Regrds,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hua&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 10 May 2012 01:32:04 GMT</pubDate>
    <dc:creator>cle444</dc:creator>
    <dc:date>2012-05-10T01:32:04Z</dc:date>
    <item>
      <title>Adding and auto extracting scale information</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-portal-questions/adding-and-auto-extracting-scale-information/m-p/232908#M3091</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello Arc desktop users/experts/developers/whoever you ares,,,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Much appreciated if you could kindly go through the longest question in my forum career and provide a solution or ideas.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Background:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Question:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Regrds,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hua&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 01:32:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-portal-questions/adding-and-auto-extracting-scale-information/m-p/232908#M3091</guid>
      <dc:creator>cle444</dc:creator>
      <dc:date>2012-05-10T01:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: Adding and auto extracting scale information</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-portal-questions/adding-and-auto-extracting-scale-information/m-p/232909#M3092</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I crafted some code which may be helpful.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;First, create Scale field of double type in your data. Then adjust pathes and rounding in script:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;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):
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.dataDrivenPages.currentPageID = pageNum
&amp;nbsp;&amp;nbsp;&amp;nbsp; #check first data frame from Layuot (if you have more than one use wilcard, eg. ListDataFrames(mxd,"Layers")
&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #get the scale of current page (the scale taken is not rounded so first define round factor)
&amp;nbsp;&amp;nbsp;&amp;nbsp; #define round factor: -2: round scale to 100, -1: round scale to 10, etc.
&amp;nbsp;&amp;nbsp;&amp;nbsp; roundFactor = -2
&amp;nbsp;&amp;nbsp;&amp;nbsp; pageScale = round(df.scale, roundFactor)

&amp;nbsp;&amp;nbsp;&amp;nbsp; #take some identificator of feature in current page, eg. OBJECTID, FID, etc.
&amp;nbsp;&amp;nbsp;&amp;nbsp; ddpFeatureID = mxd.dataDrivenPages.pageRow.OBJECTID
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #open UpdateCursor on one row of indexLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; #if you use TEXT field as an identificator use '"textField" = ' + "'" + str(ddpFeatureID) + "'" as a WHERE clause
&amp;nbsp;&amp;nbsp;&amp;nbsp; updCur = arcpy.UpdateCursor(indexLayer, '"OBJECTID" = ' + str(ddpFeatureID))
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for updCurRow in updCur:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #update Scale field of DOUBLE type (create this field before running script)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; updCurRow.setValue("Scale", pageScale)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; updCur.updateRow(updCurRow)
&amp;nbsp;&amp;nbsp;&amp;nbsp; del updCur&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:46:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-portal-questions/adding-and-auto-extracting-scale-information/m-p/232909#M3092</guid>
      <dc:creator>MarcinGasior</dc:creator>
      <dc:date>2021-12-11T11:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: Adding and auto extracting scale information</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-portal-questions/adding-and-auto-extracting-scale-information/m-p/232910#M3093</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I crafted some code which may be helpful.&lt;BR /&gt;First, create Scale field of double type in your data. Then adjust pathes and rounding in script:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;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):
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.dataDrivenPages.currentPageID = pageNum
&amp;nbsp;&amp;nbsp;&amp;nbsp; #check first data frame from Layuot (if you have more than one use wilcard, eg. ListDataFrames(mxd,"Layers")
&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #get the scale of current page (the scale taken is not rounded so first define round factor)
&amp;nbsp;&amp;nbsp;&amp;nbsp; #define round factor: -2: round scale to 100, -1: round scale to 10, etc.
&amp;nbsp;&amp;nbsp;&amp;nbsp; roundFactor = -2
&amp;nbsp;&amp;nbsp;&amp;nbsp; pageScale = round(df.scale, roundFactor)

&amp;nbsp;&amp;nbsp;&amp;nbsp; #take some identificator of feature in current page, eg. OBJECTID, FID, etc.
&amp;nbsp;&amp;nbsp;&amp;nbsp; ddpFeatureID = mxd.dataDrivenPages.pageRow.OBJECTID
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #open UpdateCursor on one row of indexLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; #if you use TEXT field as an identificator use '"textField" = ' + "'" + str(ddpFeatureID) + "'" as a WHERE clause
&amp;nbsp;&amp;nbsp;&amp;nbsp; updCur = arcpy.UpdateCursor(indexLayer, '"OBJECTID" = ' + str(ddpFeatureID))
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for updCurRow in updCur:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #update Scale field of DOUBLE type (create this field before running script)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; updCurRow.setValue("Scale", pageScale)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; updCur.updateRow(updCurRow)
&amp;nbsp;&amp;nbsp;&amp;nbsp; del updCur&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I guess another way would be generate extent/envelop for each polygon and then somehow calculate scale based on corresponding envelop size...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:46:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-portal-questions/adding-and-auto-extracting-scale-information/m-p/232910#M3093</guid>
      <dc:creator>cle444</dc:creator>
      <dc:date>2021-12-11T11:46:57Z</dc:date>
    </item>
  </channel>
</rss>

