Error 010240 - Could not save raster dataset...

23498
20
02-27-2017 05:47 AM
NeilAyres
MVP Alum

I am trying to do some raster processing in python.

As this will become a geoprocessing service eventually, I am using env.scratchGDB for storage.

There are several links to this error in Geonet & GIS SE, but I am still stumped.

I have also followed advice from Curtis Curtis Price to also set env.workspace = env.scratchGDB to save on copying time.

This bit works :

rasBase = "rasBase" + DateTimeStamp
rasBaseTmp = arcpy.sa.CreateConstantRaster(benchElev, "FLOAT", rasCellSize)
rasBaseTmp.save(rasBase)

But a few lines on I try to do a con on a difference raster...

rasAboveTmp = Con(arcpy.Raster(rasDiff) > 0, 1)
rasAbove = "rasAbove" + DateTimeStamp
rasAboveTmp.save(rasAbove)

Which gets me this mysterious error:

Traceback (most recent call last):
 File "C:\Data\Dev\Sprint4\Scripts\Tool_270217.py", line 222, in <module>
 rasAboveTmp.save(rasAbove)
RuntimeError: ERROR 010240: Could not save raster dataset to C:\Users\nayre\OneDrive\Documents\ArcGIS\scratch.gdb\rasAbove_270217_1524 with output format FGDBR.

Most of the posts refer to trying to save a grid format raster with a filename > 10(?) characters.

But this is a raster going into the scratch fgdb?

Anybody got an idea?

ArcGIS 10.4.1, Win10 64bit

20 Replies
curtvprice
MVP Esteemed Contributor

Here's a nice example of how this works with arcpy map algebra and delayed execution of raster tools. Note all the temp rasters in this case get written to disk at some point. The temp rasters not saved are deleted when the python session ends.

>>> import os
>>> import arcpy
>>> from arcpy import env
>>> from arcpy.sa import *
>>> arcpy.CheckOutExtension("spatial")
u'CheckedOut'
>>> env.workspace = os.path.realpath(os.curdir)
>>> env.workspace
u'C:\\Users\\cprice\\Documents\\ArcGIS\\xxwk'
>>> env.scratchWorkspace = env.workspace
>>> env.exent = arcpy.Extent(0, 0, 10, 10)
>>> env.cellSize = 1
>>> t1 = CreateConstantRaster(1)
>>> os.listdir(".")
['createconsta1', 'CreateConsta1.aux.xml', 'info', 'log']
>>> t2 = t1 + 1
# Raster t2 is not created yet
>>> os.listdir(".")
['createconsta1', 'CreateConsta1.aux.xml', 'createconsta1.vat.IGSKMCCWLT103.8960.8012.sr.lock', 'info', 'log']
>>> t3 = t2 + 1
# Raster t3 is not created yet
>>> os.listdir(".")
['createconsta1', 'CreateConsta1.aux.xml', 'createconsta1.vat.IGSKMCCWLT103.8960.8012.sr.lock', 'info', 'log']
>>> t3.save("t3")
# Now both t2 and t3 have been created (raster creation triggered by save() of t3)
# Non-local operators like zonalstats on t2 would trigger execution too.
>>> os.listdir(".")
['createconsta1', 'CreateConsta1.aux.xml', 'createconsta1.vat.IGSKMCCWLT103.8960.8012.sr.lock', 'info', 'log', 'plus_ras', 'plus_ras
.aux.xml', 'plus_ras.vat.IGSKMCCWLT103.8960.8012.sr.lock', 't3', 't3.aux.xml']
>>> ^Z
# start new python session - note temp rasters are gone
py
>>> os.listdir(".")
['info', 'log', 't3', 't3.aux.xml']‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
NeilAyres
MVP Alum

Thanks Curtis,

One of the speculations was that there is a lock on something somewhere, but it is hard to imagine how this comes about.

If so then this is a bug surely. Just don't know how to re-create it so that someone at esri Redlands would believe me.

0 Kudos
NeilAyres
MVP Alum

I did try everything to write to the scratch workspace. And moved it to a new shorter location. And also tried your first suggestion using scratchFolder instead and writing a tif.

All ended the same.

However, I got together with a colleague this morn, and we managed to re-do the workflow in model builder (he knows a lot more than me about this). Same stuff, scratchGDBs or "in_memory" but it worked.

But it is bugging me that this error made my python script fail, and I don't understand why. 

0 Kudos
MarcusBrown
New Contributor II

Hi, just wanted to mention that this solved my problem. I was trying to save to file-based format, received the error 010240, truncated my output name and it worked like a charm.

0 Kudos
DanPatterson_Retired
MVP Emeritus

demo time with your simple math example

import arcpy
a = np.zeros((10,10), dtype='int')
a.fill(2)
twos = arcpy.NumPyArrayToRaster(a)
twos.save("c:/temp/twos.tif")
# bring it back in
threes = arcpy.RasterToNumPyArray("c:/temp/twos.tif") + 1
fours = threes + 1
fours__tif = arcpy.NumPyArrayToRaster(fours)
fours__tif.save("c:/temp/fours.tif")
del twos, threes, fours‍‍‍‍‍‍‍‍‍‍‍

attached twos.tif and fours.tif you can produce 3 if you want

There is no need to save anything if you don't need to until the 'math' is all done.  As for all the other file fluff, none is created but the aux and dbf etc are there if needed

0 Kudos
NeilAyres
MVP Alum

Thanks Dan...

Was looking at my elevation data after RasterToNumPy, was wondering how to filter out the areas of NoData and how to "cut" it into above and below at a certain elevation. Then of course counts of valid "cells" and summing.

0 Kudos
DanPatterson_Retired
MVP Emeritus

'a' is an array from a raster where -99 is the nodata value

'b' is the masked array representing 'a' with the mask (this can be done in one step when reading rasters using RasterToNumPyArray)

'c' is a simple query asking where b0 is greater than 5 units... making it a boolean mask array

'd' is the raster where the values are greater than 5, in this case assigning 0 to values < 5, but you can assign no data.

a = np.array([0,1,-99,3,4,5,6,-99,8,9,10,11]).reshape(3,4)
b0 = np.ma.MaskedArray(a, mask=m, fill_value=-99)
c = np.where(b0>5, 1, 0)
d = b0*c

print(("\n{}\n"*4).format(a, b0, c, d))

[[  0   1 -99   3]
 [  4   5   6 -99]
 [  8   9  10  11]]

[[0 1 -- 3]
 [4 5 6 --]
 [8 9 10 11]]

[[0 0 0 0]
 [0 0 1 0]
 [1 1 1 1]]

[[0 0 -- 0]
 [0 0 6 --]
 [8 9 10 11]]‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

of course, this can be greatly simplified into a one liner which simply queries and assigns and returns the array you want.  The next step if you are done is to NumPyToRaster array back to ArcLand if you want to see it and don't want to use MatPlotLib for viewing

EDIT

almost forgot...

np.size((d !=0)[0])
4

and

np.sum(d)
44‍‍
0 Kudos
NeilAyres
MVP Alum

A bit of feedback on this.

So, reported this error to esri-SouthAfrica and it was forwarded to Redlands.

Did get a response and some ideas to check, similar to the suggestions here.

And, of course they wanted the tool and some data to try and replicate the problem, fair enough.

So, I started to rebuild my tool from the ground up, slowly adding bits from the original.

Guess what....

It worked, no more error 010240.....

One of those great mysteries in life I suppose. A problem that I was battling with for 3 days or so, just disappeared.

So, if in doubt, start again....

Thanks to all for your input here.

JuanOrozco
Occasional Contributor

I had the exact same problem but the issue was not the path it was the raster i was trying to save. I switched it to a dummy raster that i know is fine and it worked. Having realized this i went back to check my Con() statement, found something suspicious, modified it and then i was able to save the raster.

0 Kudos
curtvprice
MVP Esteemed Contributor

Errors like this are notoriously difficult to track. Pathname or workspace issues (esp with Esri grids) are common, but also if the raster can't be saved because its content is invalid or corrupted is another (sounds like both of you ran into the second type of issue). The move at 10.5 to save temporary rasters to .tif format may help make these opaque error messages on saves less common. We can always hope.

0 Kudos