<?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: use a for loop to interpolate points and then extract interpolation with a bounda in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/use-a-for-loop-to-interpolate-points-and-then/m-p/11768#M955</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think the save should work - if you use the right syntax. .save() is a method, the single argument is an output path for the raster to be saved to.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;outkrig.save=(outkrigsave)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;should be&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;outkrig.save(outkrigsave)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 18 Mar 2014 03:07:45 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2014-03-18T03:07:45Z</dc:date>
    <item>
      <title>use a for loop to interpolate points and then extract interpolation with a boundary</title>
      <link>https://community.esri.com/t5/python-questions/use-a-for-loop-to-interpolate-points-and-then/m-p/11767#M954</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm looking to get some input into interpolating multiple point feature classes using a for loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Whenever I specify to run only 1 feature class in the for loop, the script completes.&amp;nbsp; BUT, when I specify all feature classes, it loops through each step with the first feature class fine and when moving to the next feature class, I get an error saying "workspace or data source is read only" and "The operation was attempted on an empty geometry" or "no spatial reference exists" at the interpolation step.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I noticed that for each interpolation and extraction that works on a single feature class, a new raster grid is saved in my env.workspace path using default naming parameters, as well as in the savepaths that I have defined myself.&amp;nbsp; Is it possible that the reason why I get the "workspace is read only" error is due to python reading the default file that is saved to my workspace automatically?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've also tried using the ".save" function to store the new raster grids, which you will see are commented out because they did not work.&amp;nbsp; As an alternative I used the Copy Raster tool to save the output raster grids to new geodatabases.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import arcpy
from arcpy import env
from arcpy.sa import *

#Set up environmental workspace
env.workspace = "C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\SGaugeTest.gdb"

#Set up save path
#clipsavepath = "C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\S_Gauge_Clips.gdb"

krigsavepath = "C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\Krig_Test.gdb"

Extractsavepath = "C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\Krig_Mask_Test.gdb"

# Define constant variables
BasinBound = "C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\S_Gauges.gdb\S_BasinBoundary"


# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")


fcs=arcpy.ListFeatureClasses("a*")
print "Listing feature classes"

for fc in fcs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print (fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #outclip = clipsavepath + "/" + fc + "_" + "clip"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outkrigsave = krigsavepath + "/" + fc + "_" + "krig"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outmasksave = Extractsavepath + "/" + fc + "_" + "krigmask"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zfield = "Wlevel"

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Clip gauge data with basin boundary
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #print 'clipping gauge data'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #arcpy.Clip_analysis(fc,BasinBound,outclip)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Run kriging Interpolate
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'interpolating gauge data'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outkrig = Kriging(fc,zfield, KrigingModelOrdinary ("Spherical",0.0008333333333),0.0008333333333)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #outkrig.save=(outkrigsave)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Copy krig to gdb
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'copying interpolation grid to new gdb'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyRaster_management(outkrig,outkrigsave)


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Extract krig interpolation by the corresponding basin mask
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'extracting interpolation with basin mask'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outmask = ExtractByMask(outkrig,BasinBound)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #outmask.save = (outmasksave)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Copy krig to gdb
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'copying interpolation grid to new gdb'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyRaster_management(outmask,outmasksave)


&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # If an error occurred print the message to the screen
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()

print 'Script is complete!!'

&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is a copy of the error messages&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
*** Remote Interpreter Reinitialized&amp;nbsp; ***
&amp;gt;&amp;gt;&amp;gt; 
Listing feature classes
a734184
interpolating gauge data
copying interpolation grid to new gdb
extracting interpolation with basin mask
copying interpolation grid to new gdb
a734072
interpolating clipped gauge data
Executing: Kriging C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\S_Gauges.gdb\a734072 Wlevel C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\S_Gauges\S_Gauges.gdb\Kriging_a7345 "Spherical 0.000833" 0.0008333333333 "VARIABLE 12" #
Start Time: Mon Mar 17 15:44:56 2014
ERROR 999999: Error executing function.
Workspace or data source is read only.
Workspace or data source is read only.
No spatial reference exists.
ERROR 010029: Unable to create the raster __1000000.
Failed to execute (Kriging).
Failed at Mon Mar 17 15:44:56 2014 (Elapsed Time: 0.00 seconds)
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for taking the time to read through this.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Mar 2014 18:54:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-a-for-loop-to-interpolate-points-and-then/m-p/11767#M954</guid>
      <dc:creator>BenSciance</dc:creator>
      <dc:date>2014-03-17T18:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: use a for loop to interpolate points and then extract interpolation with a bounda</title>
      <link>https://community.esri.com/t5/python-questions/use-a-for-loop-to-interpolate-points-and-then/m-p/11768#M955</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think the save should work - if you use the right syntax. .save() is a method, the single argument is an output path for the raster to be saved to.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;outkrig.save=(outkrigsave)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;should be&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;outkrig.save(outkrigsave)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Mar 2014 03:07:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-a-for-loop-to-interpolate-points-and-then/m-p/11768#M955</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-03-18T03:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: use a for loop to interpolate points and then extract interpolation with a bounda</title>
      <link>https://community.esri.com/t5/python-questions/use-a-for-loop-to-interpolate-points-and-then/m-p/11769#M956</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You might want to include a&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
env.overwriteOutput = True
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;as well at the beginning of your script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Good luck,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Neil&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:30:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-a-for-loop-to-interpolate-points-and-then/m-p/11769#M956</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2021-12-10T20:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: use a for loop to interpolate points and then extract interpolation with a bounda</title>
      <link>https://community.esri.com/t5/python-questions/use-a-for-loop-to-interpolate-points-and-then/m-p/11770#M957</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Neil and Curtis.&amp;nbsp; I made the edits you both suggested and the loop completed with no errors.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Mar 2014 12:38:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-a-for-loop-to-interpolate-points-and-then/m-p/11770#M957</guid>
      <dc:creator>BenSciance</dc:creator>
      <dc:date>2014-03-18T12:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: use a for loop to interpolate points and then extract interpolation with a bounda</title>
      <link>https://community.esri.com/t5/python-questions/use-a-for-loop-to-interpolate-points-and-then/m-p/11771#M958</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've returned back to this script to use it again and unfortunately the same error message as before keeps occurring.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
extracting a732847 
Executing: ExtractByMask C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\SW_Gauges\krig4MinDiff.gdb/SW_a732847 by C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\SW_Gauges\SW_Gauges.gdb\SW_BasinBoundaryC:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\SW_Gauges\SW_Gauges.gdb\SW_BasinBoundary C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\SW_Gauges\SW_Gauges.gdb\Extract_SW_a2
Start Time: Thu Apr 03 13:23:31 2014
ERROR 999999: Error executing function.
Workspace or data source is read only.
Workspace or data source is read only.
The operation was attempted on an empty geometry.
ERROR 010302: Unable to create the output raster: C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\SW_Gauges\SW_Gauges.gdb\Extract_SW_a2
ERROR 010067: Error in executing grid expression.
Failed to execute (ExtractByMask).
Failed at Thu Apr 03 13:23:32 2014 (Elapsed Time: 1.00 seconds)
script complete
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the code with the suggestions you have made:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
from arcpy import env
from arcpy.sa import*

arcpy.env.workspace=r"C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\SW_Gauges\SW_Gauges.gdb"

env.overwriteOutput=True
arcpy.env.overwriteOutput=True

# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")

krigpath= "C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\SW_Gauges\krig4MinDiff.gdb"
maskpath= "C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Minimize_DEM_Analysis\Mask4MinDiff.gdb"

print 'listing feature classes'
fcs=arcpy.ListFeatureClasses("a732847*")
bounds="C:\Users\mbs7038\Documents\New_Landsat_Imagery\For_Area_Calc\Gauges_For_AccuracyAssessment\SW_Gauges\SW_Gauges.gdb\SW_BasinBoundary"

print 'beginning fc for loop'
for fc in fcs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print fc
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zfield = "Wlevel"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; savekrig = krigpath +"/" + "SW_" + fc
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; savemask = maskpath +"/" + "SW_" + fc

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print ('kriging {0}'.format(fc))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outKrig=arcpy.sa.Kriging(fc,zfield,KrigingModelOrdinary ("Spherical",0.0008333333333),0.0008333333333)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outKrig.save(savekrig)


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print ('extracting {0} by {1}').format(fc,bounds)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outMask=arcpy.sa.ExtractByMask(savekrig,bounds)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outMask.save(savemask)

&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()

print 'script complete'
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any other possible ideas as to why I keep getting these errors?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm stumped as to why the computer attempts to use the grids that are saved by default ("Extract_SW_a2" in the error code block) for the functions in the loop when I specifically call for the grid that was just saved (savekrig).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All grids that I call for in the loop have defined coordinate systems and are not opened in arcmap, arccatalog, or any other program....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think the default grids that get created and used in the functions are what's causing these errors.&amp;nbsp; But Why?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:30:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-a-for-loop-to-interpolate-points-and-then/m-p/11771#M958</guid>
      <dc:creator>BenSciance</dc:creator>
      <dc:date>2021-12-10T20:30:09Z</dc:date>
    </item>
  </channel>
</rss>

