<?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: Getting activeMap extent coordinates after setting activeMap.spatialReference in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/getting-activemap-extent-coordinates-after-setting/m-p/1156974#M64135</link>
    <description>&lt;P&gt;This worked, thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 23 Mar 2022 19:49:25 GMT</pubDate>
    <dc:creator>EricEagle</dc:creator>
    <dc:date>2022-03-23T19:49:25Z</dc:date>
    <item>
      <title>Getting activeMap extent coordinates after setting activeMap.spatialReference</title>
      <link>https://community.esri.com/t5/python-questions/getting-activemap-extent-coordinates-after-setting/m-p/1156450#M64126</link>
      <description>&lt;P&gt;In ArcGIS Pro (2.9), I'm doing some processing work based on a mask I derive from the active map view.&lt;/P&gt;&lt;P&gt;The processor expects UTM-projected data.&amp;nbsp; However, it might be that the user has not projected their map project to UTM, so I am trying to catch and handle that in the flow.&amp;nbsp; Right now my code looks like this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;d = arcpy.Describe(raster_in)
r_in_sr = d.spatialReference

# Make sure data is not unprojected or in common GCS
if r_in_sr.factoryCode in [4326, 3857, None]:
    raise ProjectionException("Input data not projected. Please ensure all inputs are projected and retry.")

# Make sure the active map is set to same spatial reference as input layer
p = arcpy.mp.ArcGISProject("CURRENT")
m = p.activeMap
m.spatialReference = r_in_sr  # successfully switches active map coord system!

# Now get the view extent
view_extent = p.activeView.camera.getExtent()
arcpy.AddMessage(view_extent)  # Yields GCS Lat/Lons, not UTM!

extent_poly = arcpy.Polygon(
    arcpy.Array(
        [
            view_extent.lowerLeft,
            view_extent.lowerRight,
            view_extent.upperRight,
            view_extent.upperLeft,
            view_extent.lowerLeft
        ]
    ), spatial_reference=r_in_sr
).projectAs(r_in_sr)  # neither of these sr's do anything, I still get GCS lat/lons

mask = arcpy.CopyFeatures_management(extent_poly, os.path.join(scratch, "mask"))  # scratch is arcpy.env.scratchGDB&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The interesting thing here is that if I START the process with a UTM-projected active map, the whole thing works fine.&amp;nbsp; I get extent coordinates in UTM.&lt;/P&gt;&lt;P&gt;If I start the process with a common GCS, the script does set the active map to a UTM coordinate system.&amp;nbsp; But nothing I do seems to coerce the Polygon object to UTM: it still reports GCS Lat/Lon coordinates.&amp;nbsp; Therefore when I call 'mask' on UTM-projected input layers, it throws an error and tells me the extent is wrong.&lt;/P&gt;&lt;P&gt;The amusing thing is, that if I simply re-run it after that, the script starts out with the active map in the UTM projection set from the previous attempt, and runs fine.&lt;/P&gt;&lt;P&gt;This &lt;EM&gt;feels&lt;/EM&gt; like a bug, but I could definitely be doing something wrong, so I thought I'd check with the experts before I file it with our customer rep.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 22:03:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-activemap-extent-coordinates-after-setting/m-p/1156450#M64126</guid>
      <dc:creator>EricEagle</dc:creator>
      <dc:date>2022-03-22T22:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: Getting activeMap extent coordinates after setting activeMap.spatialReference</title>
      <link>https://community.esri.com/t5/python-questions/getting-activemap-extent-coordinates-after-setting/m-p/1156459#M64127</link>
      <description>&lt;P&gt;At the end of a very long thread, this may be a workaround:&lt;/P&gt;&lt;P&gt;&lt;LI-MESSAGE title="ArcGIS Pro | ArcPy - How To Refresh the Map" uid="406325" url="https://community.esri.com/t5/arcgis-pro-questions/arcgis-pro-arcpy-how-to-refresh-the-map/m-p/406325#U406325" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-pro-questions/arcgis-pro-arcpy-how-to-refresh-the-map/m-p/1153373/highlight/true#M52737" target="_blank"&gt;https://community.esri.com/t5/arcgis-pro-questions/arcgis-pro-arcpy-how-to-refresh-the-map/m-p/1153373/highlight/true#M52737&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 22:31:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-activemap-extent-coordinates-after-setting/m-p/1156459#M64127</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2022-03-22T22:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: Getting activeMap extent coordinates after setting activeMap.spatialReference</title>
      <link>https://community.esri.com/t5/python-questions/getting-activemap-extent-coordinates-after-setting/m-p/1156471#M64128</link>
      <description>&lt;P&gt;Interesting! &amp;nbsp;I’m away from my workstation but will give it a try tomorrow and report back.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 23:13:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-activemap-extent-coordinates-after-setting/m-p/1156471#M64128</guid>
      <dc:creator>EricEagle</dc:creator>
      <dc:date>2022-03-22T23:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: Getting activeMap extent coordinates after setting activeMap.spatialReference</title>
      <link>https://community.esri.com/t5/python-questions/getting-activemap-extent-coordinates-after-setting/m-p/1156534#M64129</link>
      <description>&lt;P&gt;Do it the other way around: instead of setting the map coordinate system, project the extent.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;d = arcpy.Describe(raster_in)
r_in_sr = d.spatialReference

# Make sure data is not unprojected or in common GCS
if r_in_sr.factoryCode in [4326, 3857, None]:
    raise ProjectionException("Input data not projected. Please ensure all inputs are projected and retry.")

# Get the current view extent
p = arcpy.mp.ArcGISProject("CURRENT")
view_extent = p.activeView.camera.getExtent()
arcpy.AddMessage(view_extent.polygon.spatialReference.factoryCode)
arcpy.AddMessage(view_extent.polygon.firstPoint)

# project view_extent; note that you don't have to construct the polygon yourself!
extent_poly = view_extent.polygon.projectAs(r_in_sr)
arcpy.AddMessage(extent_poly.spatialReference.factoryCode)
arcpy.AddMessage(extent_poly.firstPoint)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 07:31:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-activemap-extent-coordinates-after-setting/m-p/1156534#M64129</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-03-23T07:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Getting activeMap extent coordinates after setting activeMap.spatialReference</title>
      <link>https://community.esri.com/t5/python-questions/getting-activemap-extent-coordinates-after-setting/m-p/1156974#M64135</link>
      <description>&lt;P&gt;This worked, thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 19:49:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-activemap-extent-coordinates-after-setting/m-p/1156974#M64135</guid>
      <dc:creator>EricEagle</dc:creator>
      <dc:date>2022-03-23T19:49:25Z</dc:date>
    </item>
  </channel>
</rss>

