<?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 Re: python script: zoom to each county in a state shp and export a pdf map in Mapping Questions</title>
    <link>https://community.esri.com/t5/mapping-questions/python-script-zoom-to-each-county-in-a-state-shp/m-p/376462#M3992</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Bailey,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm glad this helped, and thanks for sharing the code fix, hopefully it will also help others.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 01 Aug 2013 07:22:18 GMT</pubDate>
    <dc:creator>DanielHall_Ballester</dc:creator>
    <dc:date>2013-08-01T07:22:18Z</dc:date>
    <item>
      <title>python script: zoom to each county in a state shp and export a pdf map</title>
      <link>https://community.esri.com/t5/mapping-questions/python-script-zoom-to-each-county-in-a-state-shp/m-p/376459#M3989</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I would like to create a python script that will zoom into each county in a state shapefile and export a pdf map. I have found two DataFrame methods, panToExtent and zoomToSelectedFeatures. I don't want to use panToExtent because I want it to zoom to the shape of the county. My code uses the zoomToSelectedFeatures but i'm not exactly sure how to select features&lt;/SPAN&gt;&lt;PRE class="plain" name="code"&gt;&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;SPAN&gt;. This is what my code looks like so far. Thanks for the help!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy&amp;nbsp; mxd = "C:/ArcPyTests/Untitled.mxd" mapdoc = arcpy.mapping.MapDocument(mxd) counties = "C:/ArcPyTests/countyPopulation.shp" rows = arcpy.SearchCursor(counties) output = "C:/ArcPyTests/" df = arcpy.mapping.ListDataFrames(mapdoc)&amp;nbsp;&amp;nbsp; for row in rows: &amp;nbsp;&amp;nbsp;&amp;nbsp; mapdoc.extent = row.Shape.extent &amp;nbsp;&amp;nbsp;&amp;nbsp; df.zoomToSelectedFeatures(mapdoc.extent) &amp;nbsp;&amp;nbsp;&amp;nbsp; outputname = row.County &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPDF (mapdoc, outputname + ".PDF") &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Output " + outputname + " complete" &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del mapdoc&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Jul 2013 14:31:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/python-script-zoom-to-each-county-in-a-state-shp/m-p/376459#M3989</guid>
      <dc:creator>baileyhanson</dc:creator>
      <dc:date>2013-07-31T14:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: python script: zoom to each county in a state shp and export a pdf map</title>
      <link>https://community.esri.com/t5/mapping-questions/python-script-zoom-to-each-county-in-a-state-shp/m-p/376460#M3990</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Bailey,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Have you tried using Data Driven pages to do this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You need to set up an mxd with the data driven pages settings defined, but you can then use python to run the process.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I've attached some code. This does most of what you need.&amp;nbsp; You just need to change the output filetype to pdf (I'm using tiff here) and delete any of the user-defined parameters I have added.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope this helps.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dan&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): &amp;nbsp; mxd.dataDrivenPages.currentPageID = pageNum&amp;nbsp;&amp;nbsp; &amp;nbsp; # Get the row from the attribute table of the index layer&amp;nbsp; &amp;nbsp; row = mxd.dataDrivenPages.pageRow&amp;nbsp; &amp;nbsp; # Get the value from the field called tilename, e.g. ab1234. (This should be a string field) &amp;nbsp; name = row.getValue("TILE_NAME")&amp;nbsp; &amp;nbsp; # Set Output location &amp;nbsp; outputlocation = arcpy.GetParameterAsText(0) &amp;nbsp;&amp;nbsp; &amp;nbsp; # Concatenate into whole path name &amp;nbsp; outputName = outputlocation + "\\" + name + "_ArcMap" + ".tif"&amp;nbsp; &amp;nbsp; #Set the data frame so the output can be cropped to the data frame extent &amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]&amp;nbsp; &amp;nbsp; #Set the resolution &amp;nbsp; dpi= arcpy.GetParameterAsText(1)&amp;nbsp; &amp;nbsp; #Specify the compression type &amp;nbsp; Compression = arcpy.GetParameterAsText(2) &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; # Export to tiff &amp;nbsp; arcpy.mapping.ExportToTIFF(mxd, outputName, df, df_export_width=5153, df_export_height=5107, tiff_compression=Compression, color_mode="24-BIT_TRUE_COLOR", resolution=dpi)&amp;nbsp; # Clean up del mxd&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Jul 2013 14:57:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/python-script-zoom-to-each-county-in-a-state-shp/m-p/376460#M3990</guid>
      <dc:creator>DanielHall_Ballester</dc:creator>
      <dc:date>2013-07-31T14:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: python script: zoom to each county in a state shp and export a pdf map</title>
      <link>https://community.esri.com/t5/mapping-questions/python-script-zoom-to-each-county-in-a-state-shp/m-p/376461#M3991</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dan, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is very helpful. I took your advice and modified the code you provided and I am getting this error message. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Traceback (most recent call last):
&amp;nbsp; File "C:/ArcPyTests/createPDF_datadrivenpages.py", line 5, in &amp;lt;module&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
AttributeError: 'str' object has no attribute 'dataDrivenPages'&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Update: I resolved the problem by switching the code from:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
mxd = "C:/ArcPyTests/Untitled.mxd"
mapdoc = arcpy.mapping.MapDocument(mxd)
print "import complete"

for pageNum in range(1, mapdoc.dataDrivenPages.pageCount + 1):
&amp;nbsp; mapdoc.dataDrivenPages.currentPageID = pageNum &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;to: &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:/ArcPyTests/Untitled.mxd")

for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
&amp;nbsp; mxd.dataDrivenPages.currentPageID = pageNum &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:23:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/python-script-zoom-to-each-county-in-a-state-shp/m-p/376461#M3991</guid>
      <dc:creator>baileyhanson</dc:creator>
      <dc:date>2021-12-11T17:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: python script: zoom to each county in a state shp and export a pdf map</title>
      <link>https://community.esri.com/t5/mapping-questions/python-script-zoom-to-each-county-in-a-state-shp/m-p/376462#M3992</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Bailey,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm glad this helped, and thanks for sharing the code fix, hopefully it will also help others.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Aug 2013 07:22:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/python-script-zoom-to-each-county-in-a-state-shp/m-p/376462#M3992</guid>
      <dc:creator>DanielHall_Ballester</dc:creator>
      <dc:date>2013-08-01T07:22:18Z</dc:date>
    </item>
  </channel>
</rss>

