<?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 Issues with spatial reference object from currently active map in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/issues-with-spatial-reference-object-from/m-p/1252364#M66732</link>
    <description>&lt;P&gt;&lt;SPAN&gt;I'm having an arcpy issue where I'm trying to pull a spatial reference object from the currently active map to use to create a point geometry.&amp;nbsp; It works fine if I pull it from the first layer in the ToC:&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;insr = arcpy.Describe(layers[0]).spatialReference &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;B&lt;/SPAN&gt;&lt;SPAN&gt;ut if I pull it from the currently active map:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps()[0]
insr = m.spatialReference&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;then I get an error. Both the layer and the map return a spatial reference object, but when I use the one from the map, it ends up erroring out on this line:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;point1 = arcpy.PointGeometry(arcpy.Point(extent.XMin,extent.YMin),insr)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;T&lt;SPAN&gt;raceback (most recent call last):&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;File "&amp;lt;string&amp;gt;", line 12, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\arcobjects\geometries.py", line 86, in __init__&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;super().__init__(inputs, spatial_reference, has_z, has_m)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\arcobjects\mixins.py", line 223, in __init__&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;self._arc_object = gp.CreateObject('geometry', self.__type_string__,&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in &amp;lt;lambda&amp;gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return lambda *args: val(*gp_fixargs(args, True))&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 43, in gp_fixargs&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;new_args.append(gp_fixarg(arg, string_results, pass_arc_object))&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 30, in gp_fixarg&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if isinstance(arg, Result) and string_results:&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;RuntimeError: SpatialReference: Get attribute __class__ does not exist&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The attached images are an example of the object it's returning where&amp;nbsp;&lt;STRONG&gt;insr&amp;nbsp;&lt;/STRONG&gt;is the SR object from a layer and&amp;nbsp;&lt;STRONG&gt;insr2&amp;nbsp;&lt;/STRONG&gt;is the object from the map. They are different projections but that shouldn't be an issue.&amp;nbsp; If I use&amp;nbsp;&lt;STRONG&gt;exportToString()&amp;nbsp;&lt;/STRONG&gt;on the map object and then use that to&amp;nbsp;&lt;STRONG&gt;loadFromString()&amp;nbsp;&lt;/STRONG&gt;on a new SR object then it will also work, but that seems like a needless workaround.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance for any help.&lt;/P&gt;</description>
    <pubDate>Fri, 27 Jan 2023 15:13:02 GMT</pubDate>
    <dc:creator>SeanConway</dc:creator>
    <dc:date>2023-01-27T15:13:02Z</dc:date>
    <item>
      <title>Issues with spatial reference object from currently active map</title>
      <link>https://community.esri.com/t5/python-questions/issues-with-spatial-reference-object-from/m-p/1252364#M66732</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I'm having an arcpy issue where I'm trying to pull a spatial reference object from the currently active map to use to create a point geometry.&amp;nbsp; It works fine if I pull it from the first layer in the ToC:&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;insr = arcpy.Describe(layers[0]).spatialReference &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;B&lt;/SPAN&gt;&lt;SPAN&gt;ut if I pull it from the currently active map:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps()[0]
insr = m.spatialReference&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;then I get an error. Both the layer and the map return a spatial reference object, but when I use the one from the map, it ends up erroring out on this line:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;point1 = arcpy.PointGeometry(arcpy.Point(extent.XMin,extent.YMin),insr)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;T&lt;SPAN&gt;raceback (most recent call last):&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;File "&amp;lt;string&amp;gt;", line 12, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\arcobjects\geometries.py", line 86, in __init__&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;super().__init__(inputs, spatial_reference, has_z, has_m)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\arcobjects\mixins.py", line 223, in __init__&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;self._arc_object = gp.CreateObject('geometry', self.__type_string__,&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in &amp;lt;lambda&amp;gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return lambda *args: val(*gp_fixargs(args, True))&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 43, in gp_fixargs&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;new_args.append(gp_fixarg(arg, string_results, pass_arc_object))&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 30, in gp_fixarg&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if isinstance(arg, Result) and string_results:&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;RuntimeError: SpatialReference: Get attribute __class__ does not exist&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The attached images are an example of the object it's returning where&amp;nbsp;&lt;STRONG&gt;insr&amp;nbsp;&lt;/STRONG&gt;is the SR object from a layer and&amp;nbsp;&lt;STRONG&gt;insr2&amp;nbsp;&lt;/STRONG&gt;is the object from the map. They are different projections but that shouldn't be an issue.&amp;nbsp; If I use&amp;nbsp;&lt;STRONG&gt;exportToString()&amp;nbsp;&lt;/STRONG&gt;on the map object and then use that to&amp;nbsp;&lt;STRONG&gt;loadFromString()&amp;nbsp;&lt;/STRONG&gt;on a new SR object then it will also work, but that seems like a needless workaround.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance for any help.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 15:13:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issues-with-spatial-reference-object-from/m-p/1252364#M66732</guid>
      <dc:creator>SeanConway</dc:creator>
      <dc:date>2023-01-27T15:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with spatial reference object from currently active map</title>
      <link>https://community.esri.com/t5/python-questions/issues-with-spatial-reference-object-from/m-p/1252835#M66733</link>
      <description>&lt;P&gt;Yeah, sometimes arcpy can be tricky with the conversion between Result objects, geoprocessing xyz objects and the "pure" xyz objects.&lt;/P&gt;&lt;P&gt;In this case, you can just create a new SpatialReference with the factory code of your extracted sr:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;m = arcpy.mp.ArcGISProject("current").activeMap
extent = m.defaultCamera.getExtent()

map_sr = m.spatialReference
map_point = arcpy.PointGeometry(arcpy.Point(extent.XMin,extent.YMin), map_sr)  # error

map_sr = arcpy.SpatialReference(map_sr.factoryCode)
map_point = arcpy.PointGeometry(arcpy.Point(extent.XMin,extent.YMin), map_sr)  # works&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 30 Jan 2023 13:41:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issues-with-spatial-reference-object-from/m-p/1252835#M66733</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-01-30T13:41:16Z</dc:date>
    </item>
  </channel>
</rss>

