Error saving raster

5426
3
12-05-2013 05:36 AM
helgesmebye
New Contributor
I have spent to much time in trying to solve a <raster>.save(filename) problem, and getting quite desperate.  Any help is highly apreciated!

The code is like this
....
...
outM = Ln(meanAggregate)
outM.save("c:/temp/rastertest.gdb/xx")
....

I get the error:
ERROR 010240: Could not save raster dataset to c:\temp\rastertest.gdb\xx with output format FGDBR.

The strange thing is that if I do debugging in PyCharm and have a breakpoint on the saveline, it saves without any problem when I step trough the code.
If I remove the Ln function and just do a 

....
outM = meanAggregate
outM.save("c:/temp/rastertest.gdb/xx")
....

it saves fine also (also when not debugging).


I have a lot of other rasters in the same python script that saves fine without any problem.

This is really a showstopper and I am getting quite desperate.


Thanks,
-helge
Tags (2)
0 Kudos
3 Replies
ShaunWalbridge
Esri Regular Contributor
Try saving the output to another location, or even another drive to see if the same behavior persists. I've seen something like this before, and it turned out to be a permissions issue, though it was with a profile directory, and not C:/temp. If it works in another GDB in a different location, then it's worth seeing if we can create a reproducible issue. Here's the more detailed description of the error:

Description
The output raster dataset could not be created in the specified format. There may already exist an output raster with the same name and format. Certain raster formats have limitations on the range of values that are supported. For example, the GIF format only supports a value range of 0 to 255, which would be a problem if the output raster would have a range of -10 to 365.

Solution
Check that a raster with the same name and format does not already exist in the output location. Also, check the Help for the technical specifications of raster dataset formats to make sure that the expected range of values in the output is compatible with the specified format.


So, I'd try saving to a different location, and failing that, try writing the output out to another driver -- like a GeoTIFF file. If that works, you should be able to then copy the raster into the FGDB.
0 Kudos
JoleenFeltz
New Contributor

Hi,

I am having the same problem when writing GeoTiff files.  The files can be saved when I am running in debug mode, but not when running the code outside of debug.  I can also save the intermediate file by displaying first in ArcDesktop 10.5 and then exporting to a file.  I am calculating the difference between two input (geotiff) Rasters, the results are in type "Double."  I have checked to make sure there is not a file of the same name already in existence.  I have also tested whether or not using a different geodatabase path makes a difference, it does not.  I have check to see if I could just save it to a folder, I cannot.  The code is as follows (current_datestr example: 201909101900):

    output_file = "T2min_{}".format(current_datestr)
    output_file = os.path.join(output_workspace, output_file)
    output_file = "{}.tif".format(os.path.splitext(output_file)[0])

    if arcpy.Exists(output_file):
        arcpy.Delete_management(output_file)

    current_raster = Raster(current_raster)
    previous_raster = Raster(previous_raster)

    # set noData appropriately before subtraction:
    arcpy.SetRasterProperties_management(current_raster, nodata="1 -3")
    accum = current_raster - previous_raster
    output_con = arcpy.sa.Con(accum > 0, accum)

    output_con.save(output_file)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Thanks for your help.

Joleen

0 Kudos
JoleenFeltz
New Contributor

I think the problem was that I set the nodata value for the current_raster, but forgot to set it for the previous_raster.  In addition, I should have calculated accumulation amounts by setting Null values to zero before subtracting.  

from arcpy.sa import *

current_raster = Raster(current_raster_name)
previous_raster = Raster(previous_raster_name)

current = SetNull(current_raster, current_raster, "VALUE < 0")
previous = SetNull(previous_raster, previous_raster, "VALUE < 0")

current_raster = Con(IsNull(current), 0, current)
previous_raster = Con(IsNull(previous), 0, previous)

accum = current_raster - previous_raster
out_con = Con(accum > 0, accum)

out_con.save(output_file)
0 Kudos