<?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: How to add a path to default database in ArcPy script? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665881#M51708</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay, thanks for answer. But then how to use the output file as an input in the next step of my script? I have to tell the script where the file is located right?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 12 Nov 2015 17:16:21 GMT</pubDate>
    <dc:creator>KarolinaKorzeniowska</dc:creator>
    <dc:date>2015-11-12T17:16:21Z</dc:date>
    <item>
      <title>How to add a path to default database in ArcPy script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665874#M51701</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would like to add a path to default database in Arcpy script. The path will be a place where the results from evaluation will be saved. However, I do not want to add a full path, but a relative path, which enable to apply my script also in another computer. How to add relative path to default database?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Nov 2015 15:33:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665874#M51701</guid>
      <dc:creator>KarolinaKorzeniowska</dc:creator>
      <dc:date>2015-11-12T15:33:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a path to default database in ArcPy script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665875#M51702</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you talking about referencing your &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//001w00000002000000"&gt;current workspace&lt;/A&gt; that is set in your environment settings in ArcMap? If so then arcpy.env.workspace would correctly reference your default geodatabase.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Nov 2015 16:17:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665875#M51702</guid>
      <dc:creator>LukeSturtevant</dc:creator>
      <dc:date>2015-11-12T16:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a path to default database in ArcPy script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665876#M51703</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your answer. Yes, I am trying to reference to my default geodatabase. From your link I have found that I should use: &lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4d4d4d; font-family: 'Courier New', Courier, monospace; font-size: 12.8px;"&gt;arcpy.env.workspace = path&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;but here I also have to specify the path to the "path". How to do this? When I change the computer the script will not work, because the "path" will be different.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Nov 2015 16:28:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665876#M51703</guid>
      <dc:creator>KarolinaKorzeniowska</dc:creator>
      <dc:date>2015-11-12T16:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a path to default database in ArcPy script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665877#M51704</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could do it based on the directory the script is being run from using &lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;A href="https://docs.python.org/2/library/os.html#os.getcwd"&gt;os.getcwd()&lt;/A&gt;​&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;, then just build the rest of your directory from there. The requirement would be that you have to run the script from the same starting folder location on each computer.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Nov 2015 16:55:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665877#M51704</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-11-12T16:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a path to default database in ArcPy script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665878#M51705</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is how you would &lt;EM&gt;set&lt;/EM&gt; the workspace environment. If you just want to &lt;EM&gt;get&lt;/EM&gt; the workspace environment, switch the equation:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; path = arcpy.env.workspace
&amp;gt;&amp;gt;&amp;gt; print path # workspace location&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some other peripheral ideas would be to reference the script location:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; import sys
&amp;gt;&amp;gt;&amp;gt; print sys.argv[0] # script location&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;... or the current mxd location:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; print arcpy.mapping.MapDocument("CURRENT").filePath # current mxd location&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:08:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665878#M51705</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-12T04:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a path to default database in ArcPy script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665879#M51706</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for suggestion, but I think it is not what I am looking for. I would like to build a python toolbox which run like standard ArcGIS toolboxes - when you open the toolbox and do not specify the path then the results are automatically saved in default geodatabase.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Nov 2015 17:01:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665879#M51706</guid>
      <dc:creator>KarolinaKorzeniowska</dc:creator>
      <dc:date>2015-11-12T17:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a path to default database in ArcPy script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665880#M51707</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As Darren said, if you are running your tool from ArcMap or ArcCatalog you do not need to explicitly set arcpy.env.workspace to a path. It will automatically be set to your default geodatabase as I mentioned earlier.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Nov 2015 17:09:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665880#M51707</guid>
      <dc:creator>LukeSturtevant</dc:creator>
      <dc:date>2015-11-12T17:09:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a path to default database in ArcPy script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665881#M51708</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay, thanks for answer. But then how to use the output file as an input in the next step of my script? I have to tell the script where the file is located right?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Nov 2015 17:16:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665881#M51708</guid>
      <dc:creator>KarolinaKorzeniowska</dc:creator>
      <dc:date>2015-11-12T17:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a path to default database in ArcPy script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665882#M51709</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Its hard telling not knowing what you are trying to do exactly, but you can set the output as a variable for example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;feature = arcpy.CreateFeatureclass_management (env.workspace, "test1","POINT","","","",26919)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4d4d4d; font-family: Arial, Helvetica, sans-serif; font-size: 12.8px;"&gt;arcpy.Append_management (inputs, feature, "NO_TEST")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4d4d4d; font-family: Arial, Helvetica, sans-serif; font-size: 12.8px;"&gt;Here the new feature class is set to the variable 'feature' and then it can be referenced as feature throughout your script.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Nov 2015 17:23:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665882#M51709</guid>
      <dc:creator>LukeSturtevant</dc:creator>
      <dc:date>2015-11-12T17:23:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a path to default database in ArcPy script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665883#M51710</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to build a toolbox where at first I am evaluating Focal Statistics from DEM (raster) and then I am subtracting (Raster Calculator) both rasters. That I why I need a path to the results from my first evaluation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import arcpy module
import os
import arcpy
from arcpy import env
from arcpy.sa import *

# Set the input data
inRaster = arcpy.GetParameterAsText(0)
# Set the output data
outRaster = arcpy.GetParameterAsText(1)
# Set the path to workspace location
path = arcpy.env.workspace
print path


# Evaluate mean DEM
inRaster = "DEM.tif"
neighborhood = NbrRectangle(3, 3, "CELL")
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Execute FocalStatistics
outFocalStatistics = FocalStatistics(inRaster, neighborhood, "MEAN","")
# Save the output 
outFocalStatistics.save("DEM_mean")
#
# Subtraction
inRaster1 = Raster("DEM")
inRaster2 = Raster("DEM_mean")
# Execute Minus
outMinus = inRaster1 - inRaster2
# Save the output
outMinus.save("result")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:08:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665883#M51710</guid>
      <dc:creator>KarolinaKorzeniowska</dc:creator>
      <dc:date>2021-12-12T04:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a path to default database in ArcPy script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665884#M51711</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is an edited script. Let us know if you have any questions or if it is still not working for you. If you are planning to run this script from ArcMap and you just want to use the default geodatabase there is no reason to set path = arcpy.env.workspace unless you just want to reference it using the shorter variable name 'path' throughout your script. Otherwise all outputs that do not have a specific path will be saved to the default geodatabase.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import arcpy module&amp;nbsp; 
import os&amp;nbsp; 
import arcpy&amp;nbsp; 
from arcpy import env&amp;nbsp; 
from arcpy.sa import *

arcpy.CheckOutExtension("Spatial")
env.overwriteOutput= True
&amp;nbsp; 
# Set the input data&amp;nbsp; 
inRaster = arcpy.GetParameterAsText(0)&amp;nbsp; 
# Set the output data&amp;nbsp; 
outRaster = arcpy.GetParameterAsText(1)&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
neighborhood = NbrRectangle(3, 3, "CELL")&amp;nbsp; 
# Check out the ArcGIS Spatial Analyst extension license&amp;nbsp; 

# Execute FocalStatistics&amp;nbsp; 
outFocalStatistics = FocalStatistics(inRaster, neighborhood, "MEAN","")&amp;nbsp; 
# Save the output&amp;nbsp;&amp;nbsp; 
outFocalStatistics.save("DEM_mean")&amp;nbsp; 

# Execute Minus&amp;nbsp; 
outMinus = inRaster - outFocalStatistics&amp;nbsp; 
# Save the output&amp;nbsp; 
outMinus.save(outRaster)&amp;nbsp; &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:08:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665884#M51711</guid>
      <dc:creator>LukeSturtevant</dc:creator>
      <dc:date>2021-12-12T04:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a path to default database in ArcPy script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665885#M51712</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you. Now the script works fine. In the code I changed the line 24 from:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;ourMinus = inRaster - outFocalStatistics&lt;/PRE&gt;&lt;P&gt;to&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;inRaster2 = Raster("DEM_mean")
outMinus = inRaster - inRaster2&lt;/PRE&gt;&lt;P&gt;and it also works. I did this, because if in default database will be some other raster with the name outFocalStatictics then this raster can be take into evaluation, am I right?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have also one more question. How to delete intermediate results (DEM_mean) from default database? I have found the it can be done using the code below, but in my case it is not deleting anything.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Clean up
del outFocalStatistics&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:08:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665885#M51712</guid>
      <dc:creator>KarolinaKorzeniowska</dc:creator>
      <dc:date>2021-12-12T04:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a path to default database in ArcPy script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665886#M51713</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You do not need to change the line 24. Essentially all you did was change the variable name of the outFocalStatistics to inRaster2. The name in the geodatabase will always be "DEM_mean". However, it looks like you want to treat the "DEM_mean" as intermediate data. In that case just do not save the output of outFocalStatistics like this:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important;"&gt;&lt;SPAN class="comment" style="font-weight: inherit; font-style: inherit; color: #008200; font-size: 9pt !important;"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Execute FocalStatistics&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;outFocalStatistics = FocalStatistics(inRaster, neighborhood, "MEAN","")&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Execute Minus&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;outMinus = inRaster - outFocalStatistics&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Save the output&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;outMinus.save(outRaster) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will always generate outFocalStatistics in memory and automatically delete it. On another note if you were to save the output of outFocalStatistics and want to delete it at the end of your script you would use arcpy.Delete_management(outFocalStatistics). The del function is useful when clearing variables, lists, dictionaries, and the like, but it will not delete output results. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Nov 2015 11:51:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665886#M51713</guid>
      <dc:creator>LukeSturtevant</dc:creator>
      <dc:date>2015-11-13T11:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a path to default database in ArcPy script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665887#M51714</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, you are right. Thank you for explanation. Now I understand it better, and my toolbox works like I expected.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Nov 2015 16:20:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665887#M51714</guid>
      <dc:creator>KarolinaKorzeniowska</dc:creator>
      <dc:date>2015-11-13T16:20:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a path to default database in ArcPy script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665888#M51715</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you could also use arcpy.env.scratchGDB&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Jun 2016 16:32:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-add-a-path-to-default-database-in-arcpy/m-p/665888#M51715</guid>
      <dc:creator>stevegourley</dc:creator>
      <dc:date>2016-06-01T16:32:40Z</dc:date>
    </item>
  </channel>
</rss>

