<?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: Change a data frame's coordinate system based on a shapefile attribute in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/change-a-data-frame-s-coordinate-system-based-on-a/m-p/152560#M11757</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You need to fetch the first row from the cursor, then get the first value from the row.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;NZone &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"12"&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN class="comment token"&gt;# Default value in case no rows found&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;ShpShp&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"UTM_Zone"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; searchCursor&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; searchCursor&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NZone &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; row&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;break&lt;/SPAN&gt;‍‍‍‍‍

&lt;SPAN class="comment token"&gt;# Remainder of code down here...&lt;/SPAN&gt;
‍‍‍‍‍‍‍UTMRef &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;"Coordinate Systems\Projected Coordinate Systems\UTM\NAD 1983\NAD 1983 UTM Zone "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;NZone&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"N.prj"&lt;/SPAN&gt;‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;There are more concise ways to create a cursor and fetch only its first row and first value, but I generally stick to this pattern of "with" on the first line and iteration on the second because it suits the majority of my use cases (may differ for others).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 08:10:59 GMT</pubDate>
    <dc:creator>JamesMacKay3</dc:creator>
    <dc:date>2021-12-11T08:10:59Z</dc:date>
    <item>
      <title>Change a data frame's coordinate system based on a shapefile attribute</title>
      <link>https://community.esri.com/t5/python-questions/change-a-data-frame-s-coordinate-system-based-on-a/m-p/152559#M11756</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to write a script tool that, among other things, sets the coordinate system of the map to a given UTM zone based on the attribute data of a shapefile (generated by a spatial join earlier in the script). The relevant bit is as follows: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NZone = arcpy.da.SearchCursor(ShpShp, ["UTM_Zone"])&lt;BR /&gt;#UTMRef = r"Coordinate Systems\Projected Coordinate Systems\UTM\NAD 1983\NAD 1983 UTM Zone 12N.prj"&lt;BR /&gt;UTMRef = r"Coordinate Systems\Projected Coordinate Systems\UTM\NAD 1983\NAD 1983 UTM Zone " + str(NZone) + "N.prj"&lt;BR /&gt;MXD = arcpy.mapping.MapDocument("CURRENT")&lt;BR /&gt;DF = arcpy.mapping.ListDataFrames(MXD)[0]&lt;BR /&gt;sr = arcpy.SpatialReference(UTMRef)&lt;BR /&gt;DF.spatialReference = sr&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(ShpShp is a variable for the shapefile in question, including ".shp")&lt;/P&gt;&lt;P&gt;Note that the commented-out line works if I use that instead. This also works if I change the first line to "NZone = 12". Since I want this to work for any potential UTM zone 1 through 20 (all North), I wanted to use the UTM_Zone field that was the result of the spatial join.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The field is type string, and the values are written exactly as the projection files display (ie no leading zeroes or anything).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Am I using SearchCursor wrong? Everything else seems to work fine; I adapted the rest of the above code from &lt;A _jive_internal="true" href="https://community.esri.com/thread/11492"&gt;this earlier discussion&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any tips?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Feb 2018 22:53:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-a-data-frame-s-coordinate-system-based-on-a/m-p/152559#M11756</guid>
      <dc:creator>NickDierks</dc:creator>
      <dc:date>2018-02-12T22:53:31Z</dc:date>
    </item>
    <item>
      <title>Re: Change a data frame's coordinate system based on a shapefile attribute</title>
      <link>https://community.esri.com/t5/python-questions/change-a-data-frame-s-coordinate-system-based-on-a/m-p/152560#M11757</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You need to fetch the first row from the cursor, then get the first value from the row.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;NZone &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"12"&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN class="comment token"&gt;# Default value in case no rows found&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;ShpShp&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"UTM_Zone"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; searchCursor&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; searchCursor&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NZone &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; row&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;break&lt;/SPAN&gt;‍‍‍‍‍

&lt;SPAN class="comment token"&gt;# Remainder of code down here...&lt;/SPAN&gt;
‍‍‍‍‍‍‍UTMRef &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;"Coordinate Systems\Projected Coordinate Systems\UTM\NAD 1983\NAD 1983 UTM Zone "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;NZone&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"N.prj"&lt;/SPAN&gt;‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;There are more concise ways to create a cursor and fetch only its first row and first value, but I generally stick to this pattern of "with" on the first line and iteration on the second because it suits the majority of my use cases (may differ for others).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:10:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-a-data-frame-s-coordinate-system-based-on-a/m-p/152560#M11757</guid>
      <dc:creator>JamesMacKay3</dc:creator>
      <dc:date>2021-12-11T08:10:59Z</dc:date>
    </item>
    <item>
      <title>Re: Change a data frame's coordinate system based on a shapefile attribute</title>
      <link>https://community.esri.com/t5/python-questions/change-a-data-frame-s-coordinate-system-based-on-a/m-p/152561#M11758</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It works! Thank you so much!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And there are probably more concise ways to do a lot of things in my script, but I've only just started learning Python, so anything that works is a big help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Feb 2018 23:19:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-a-data-frame-s-coordinate-system-based-on-a/m-p/152561#M11758</guid>
      <dc:creator>NickDierks</dc:creator>
      <dc:date>2018-02-12T23:19:34Z</dc:date>
    </item>
  </channel>
</rss>

