<?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: Workspace Environment Issue for ArcPy Spatial Analyst in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/workspace-environment-issue-for-arcpy-spatial/m-p/128340#M5533</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nicholas,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for sharing these workarounds/fixes and the your observations. I had the same experience when printing the workspace to verify it hadn't been "unset." At this point, I've opted to always use&amp;nbsp;my own workspace variable for outputs, or alternatively, use EnvManager, which seems to fix the issue (although is even more cumbersome than using full paths when dealing with lots of outputs).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jul 2020 22:30:59 GMT</pubDate>
    <dc:creator>VinceE</dc:creator>
    <dc:date>2020-07-15T22:30:59Z</dc:date>
    <item>
      <title>Workspace Environment Issue for ArcPy Spatial Analyst</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/workspace-environment-issue-for-arcpy-spatial/m-p/128334#M5527</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm having issues using arcpy and spatial analyst functions. The workspace environment seems to get selectively ignored. I am running this code directly in the Python window in ArcGIS Pro 2.5.1. The behavior appears the same in an existing project versus a brand new unsaved project.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; ap
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; arcpy &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; env
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;sa &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;*&lt;/SPAN&gt;

testing &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;

env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;workspace &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;"C:\Users\Desktop\Prop\Prop_Slope.gdb"&lt;/SPAN&gt;

dem &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;"F:\5_Tools\SlopeClass\AARM.gdb\DEM_AOI"&lt;/SPAN&gt;
demfs1 &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; FocalStatistics&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;dem&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Circle 5 CELL"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"MEAN"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
demfs2 &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; FocalStatistics&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;demfs1&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Circle 5 CELL"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"MEAN"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
demfs3 &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; FocalStatistics&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;demfs2&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Circle 5 CELL"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"MEAN"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;#with arcpy.EnvManager(workspace = env.workspace):&lt;/SPAN&gt;
Contour&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;demfs3&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Contour"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;10&lt;/SPAN&gt;&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; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

remap &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"0 19.999 1;20 49.999 2;50 10000 3"&lt;/SPAN&gt;
rclass &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; Reclassify&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;demfs3&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"VALUE"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; remap&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"NODATA"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;#with arcpy.EnvManager(workspace = env.workspace):&lt;/SPAN&gt;
ap&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;conversion&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;RasterToPolygon&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;rclass&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Reclass_Polygon"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"SIMPLIFY"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"VALUE"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
        &lt;SPAN class="string token"&gt;"SINGLE_OUTER_PART"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; testing&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    demfs1&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;save&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"FS1"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    demfs2&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;save&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"FS2"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    demfs3&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;save&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"FS3"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    rclass&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;save&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Reclassified"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;del&lt;/SPAN&gt; demfs1&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; demfs2&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; demfs3&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; rclass‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&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;/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;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;/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;The code itself executes without a hitch, however the outputs get saved in different locations. Calling the .save() method on the returned raster objects will create permanent saves in the location specified in "env.workspace". However, both the outputs of "Contour" and "RasterToPolygon", get saved to the Default geodatabase for the project (either a named default, or just the "Default.gdb" in an unsaved project).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using the currently commented-out "EnvManager" and "with" blocks corrects this problem. Why does it appear necessary to explicitly define the workspace for these tools, when I have already done it globally at the top? What aspect of the workspace environment am I missing? Perhaps the use of spatial analyst tools here is coincidental, but it's when using these tools that I tend to experience strange behavior with the workspace environment.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:15:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/workspace-environment-issue-for-arcpy-spatial/m-p/128334#M5527</guid>
      <dc:creator>VinceE</dc:creator>
      <dc:date>2021-12-11T07:15:16Z</dc:date>
    </item>
    <item>
      <title>Re: Workspace Environment Issue for ArcPy Spatial Analyst</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/workspace-environment-issue-for-arcpy-spatial/m-p/128335#M5528</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I always explicitly create a variable called outWS and direct my outputs there.&amp;nbsp; This is the first time I've seen a reference to the arcpy.EnvManager; I don't know how I've missed that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think when you set the workspace env as you do line 7 it allows you to refer to access existing data in that workspace. However, the geoprocessing tools probably just look at the default workspace / gdb for out put.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2020 18:56:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/workspace-environment-issue-for-arcpy-spatial/m-p/128335#M5528</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2020-05-20T18:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: Workspace Environment Issue for ArcPy Spatial Analyst</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/workspace-environment-issue-for-arcpy-spatial/m-p/128336#M5529</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Be inetreresting to see Esri's pitch on this, thanks for the&amp;nbsp;&lt;SPAN style="display: inline !important; float: none; background-color: #f5f2f0; color: slategray; font-family: inherit; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: pre; word-spacing: 0px;"&gt;arcpy.EnvManager&lt;/SPAN&gt;&amp;nbsp; **steals**&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2020 19:05:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/workspace-environment-issue-for-arcpy-spatial/m-p/128336#M5529</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2020-05-20T19:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: Workspace Environment Issue for ArcPy Spatial Analyst</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/workspace-environment-issue-for-arcpy-spatial/m-p/128337#M5530</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Joe. I usually do that as well (f"{outWS}\output") and completely skip the env.workspace setting because it isn't reliable. It would just be cleaner to use the workspace if possible. I've used the workspace setting successfully in other scripts, but it seems to have issues with spatial analyst, maybe other scenarios, but I can't diagnose what causes it. Also, RasterToPolygon isn't an SA tool, so that might invalidate my theory that spatial analyst is to blame.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The documentation says "&lt;SPAN style="color: #4d4d4d; background-color: #fefefe;"&gt;Tools that honor the Current Workspace environment setting use the workspace specified as the default location for geoprocessing tool inputs and outputs." Both Contour and RasterToPolygon are supposed to respect Current Workspace. All I'm doing with EnvManager is restating the same workspace that I initialized at the top, so it's not clear to me why that works.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2020 19:35:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/workspace-environment-issue-for-arcpy-spatial/m-p/128337#M5530</guid>
      <dc:creator>VinceE</dc:creator>
      <dc:date>2020-05-20T19:35:51Z</dc:date>
    </item>
    <item>
      <title>Re: Workspace Environment Issue for ArcPy Spatial Analyst</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/workspace-environment-issue-for-arcpy-spatial/m-p/128338#M5531</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;EnvManager is definitely helpful for temporarily changing the workspace (when it works!), disabling Z or M values, changing raster cell size, etc. Glad you'll find that useful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hopefully we'll hear something from Esri, curious to see what could be happening here.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2020 19:37:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/workspace-environment-issue-for-arcpy-spatial/m-p/128338#M5531</guid>
      <dc:creator>VinceE</dc:creator>
      <dc:date>2020-05-20T19:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: Workspace Environment Issue for ArcPy Spatial Analyst</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/workspace-environment-issue-for-arcpy-spatial/m-p/128339#M5532</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm having very&amp;nbsp;a vary similar issue with a custom python toolbox in ArcGIS Pro 2.5, &lt;A href="https://gis.stackexchange.com/questions/366343/arcgis-pro-python-toolbox-env-workspace-being-forgotten-after-using-spatial"&gt;described here on stack exchange&lt;/A&gt;.&amp;nbsp;As mentioned above, there are&amp;nbsp;several workarounds, but it would be nice to get a response from ESRI staff about what is going on ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/393272"&gt;Vince Edwards&lt;/A&gt;&amp;nbsp;I believe you are correct that the spatial analyst tools are&amp;nbsp;to blame. In both of our cases the problem occurs with non-SA tools, but only AFTER using an SA tool. A couple of other observations:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) Simply&amp;nbsp;&lt;EM&gt;printing&amp;nbsp;&lt;/EM&gt;&amp;nbsp;`arcpy.env.workspace` to the console immediately before the offending GP tools (in this case contour and rasterToPolygon) fixes the issue. This is strange to me, because it shows the it env.workspace has not been somehow 'unset' - the correct value is printed and suddenly arcpy is 'reminded' of the correct location.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) This only happens in an ArcGIS Pro project - everything seems to work as expected if running a script from the python command prompt or an IDE&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jul 2020 19:14:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/workspace-environment-issue-for-arcpy-spatial/m-p/128339#M5532</guid>
      <dc:creator>NicholasKlein-Baer</dc:creator>
      <dc:date>2020-07-15T19:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: Workspace Environment Issue for ArcPy Spatial Analyst</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/workspace-environment-issue-for-arcpy-spatial/m-p/128340#M5533</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nicholas,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for sharing these workarounds/fixes and the your observations. I had the same experience when printing the workspace to verify it hadn't been "unset." At this point, I've opted to always use&amp;nbsp;my own workspace variable for outputs, or alternatively, use EnvManager, which seems to fix the issue (although is even more cumbersome than using full paths when dealing with lots of outputs).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jul 2020 22:30:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/workspace-environment-issue-for-arcpy-spatial/m-p/128340#M5533</guid>
      <dc:creator>VinceE</dc:creator>
      <dc:date>2020-07-15T22:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: Workspace Environment Issue for ArcPy Spatial Analyst</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/workspace-environment-issue-for-arcpy-spatial/m-p/1498245#M85011</link>
      <description>&lt;P&gt;Agreed! It still seems to have an issue at 3.3!!&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2024 13:16:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/workspace-environment-issue-for-arcpy-spatial/m-p/1498245#M85011</guid>
      <dc:creator>TPuett</dc:creator>
      <dc:date>2024-06-27T13:16:50Z</dc:date>
    </item>
  </channel>
</rss>

