Zonal Statistics Error 010240: Could not save raster dataset with output format GRID

4080
7
Jump to solution
05-15-2013 07:04 AM
GrantWest
New Contributor
I wrote simple python code to do zonal statistics. My zonal input is a shapefile with a grid of equal-sized polygons. My input values are a raster of groundwater surface. Here is my code:

# Import arcpy module
import arcpy

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")

#import system modules
from arcpy import env
from arcpy.sa import *

#set environment workspace
env.workspace = "C://Users/gwest/Documents/Projects_Current/Kovacs"

#set output workspace
outWorkspace = "C://Users/gwest/Documents/Projects_Current/Kovacs/Zonal_Statistics"

#define variables
inZoneData = "farm_sa_privCopy.shp"
zoneField = "TARGET_FID"
inValueRaster = "ft_sat_nn"

# Process: Zonal Statistics
outZonalStatistics = ZonalStatistics (inZoneData, zoneField, inValueRaster, "MEAN", "DATA")

outZonalStatistics.save(outWorkspace + 'FT_SAT')



Here is what returned:

Getting data ..
Writing Output ...
Traceback (most recent call last):
  File "C:\Users\gwest\Documents\Python Scripts\Zonal Stats Python Script.py", line 32, in <module>
    outZonalStatistics.save(outWorkspace + 'FT_SAT')
RuntimeError: ERROR 010240: Could not save raster dataset to C:\Users\gwest\Documents\Projects_Current\Kovacs\ZonalSt_farm1 with output format GRID.


I've read several threads on similar errors, and the answers seems to be across the board and unrelated. Not sure how I should attack this. Help is appreciated. Thanks.

Grant
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ChrisSnyder
Regular Contributor III
All you should need is something like this:

outZonalStatistics.save(outWorkspace + '\\FT_SAT')


BTW: ESRI grids need a <= 13 character name

View solution in original post

7 Replies
markdenil
Occasional Contributor III
if
outWorkspace = "C://Users/gwest/Documents/Projects_Current/Kovacs/Zonal_Statistics"
and
outZonalStatistics.save(outWorkspace + 'FT_SAT')
then you say you want the output file to be named:
'C://Users/gwest/Documents/Projects_Current/Kovacs/Zonal_StatisticsFT_SAT'

That is a very long file name for a GRID.
GRIDS have always liked 8 character names, and while they seem less senstive now, they still don't like excessivley long names.

did you intend to use
.../Zonal_Statistics/FT_SAT'
as your output?
0 Kudos
GrantWest
New Contributor
Yes, '/Zonal_Statistics/FT_SAT' was my intended output.  I am still learning to apply Python.  Should I just drop the outWorkspace in my outZonalStatistics.save()?  I tried that and got the same error as before.
0 Kudos
ChrisSnyder
Regular Contributor III
All you should need is something like this:

outZonalStatistics.save(outWorkspace + '\\FT_SAT')


BTW: ESRI grids need a <= 13 character name
GrantWest
New Contributor
Perfect, Thanks.  That worked.
0 Kudos
JamesCrandall
MVP Frequent Contributor
Glad to hear this is resolved and just as an fyi....

I noticed your output location is C:\ drive --- have you attempted write to a network location yet?  You might run into new problems, in which case you might try to set your output to a File Geodatabase --- this has resolved much of our issues from a similar implementation.
0 Kudos
curtvprice
MVP Esteemed Contributor
outZonalStatistics.save(outWorkspace + '\\FT_SAT')


or, save yourself some work and take advantage of the env.workspace setting

# set output workspace
outWorkspace = "C:/Users/gwest/Documents/Projects_Current/Kovacs/Zonal_Statistics"
...
env.workspace = outWorkspace
outZonalStatistics.save("FT_SAT")


By the way, it's best practice when doing raster processing to have the scratchWorkspace and workspace be the same location; that way when you do a "raster.save()" it just renames the temporary raster to your output raster (assuming its the same format). This can save a lot of effort if your rasters are large in size.
curtvprice
MVP Esteemed Contributor
outZonalStatistics.save(outWorkspace + '\\FT_SAT')


or, save yourself some work and take advantage of the env.workspace setting

# set output workspace
outWorkspace = "C:/Users/gwest/Documents/Projects_Current/Kovacs/Zonal_Statistics"
...
env.workspace = outWorkspace
outZonalStatistics.save("FT_SAT")


By the way, it's best practice when doing raster processing to have the scratchWorkspace and workspace be the same location; that way when you do a "raster.save()" it just renames the temporary raster to your output raster (assuming its the same format). This can save a lot of effort if your rasters are large in size.
0 Kudos