1

I am receiving the following error when trying to run the following code:

import arcpy

from arcpy import env

from arcpy.sa import *

arcpy.CheckOutExtension = "Spatial"

env.workspace = r"C:\final_mosaic_files\for_python"

Z3 = Raster("mos_zb3")

Z4 = Raster("mos_zb4")

PC2 = Raster("pca_finb2")

outCon = Con(Z4 < -0.9274,2, Con(Z3 <-0.6223,2, Con(PC2 > 1.13,2, Con(Z3 <-0.05342,2,1))))

outCon.save(r"C:\classifications\actual_real_deal\CART")

The error is:

RuntimeError: ERROR 010240: Could not save raster dataset to C:\Users\User\Documents\Mo with output format GRID.

I have tried changing the destination folder, and the file does not currently exist in the directory, and the values of the raster are within GRID parameters for the type of format. The input rasters are mosaics of z-score values of 12 landsat images delineating coastal marsh in the northeast. The cell size is 30X30m, using WGS1984 coordinate system, no projection system. I have tried running the script with .tif file format instead of GRID, which does not work, throwing another error (file Z3 does not exist or is not supported). I have also tried running the script with other, smaller GRID files, which throws the same error 010240.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Mo Correll
  • 107
  • 12
  • 1
    Perhaps this link from the ESRI Knowledge Base, may shed some light: Error: ERROR 010240: Could not save raster dataset to... – Get Spatial Nov 05 '13 at 21:06
  • 3
    have you tried forward slashes? outCon.save("C:/classifications/actual_real_deal/CART") – mwil Nov 05 '13 at 21:15
  • @Get Spatial - my raster is not from NLCD. I have also tried checking the destination folder, and there was no raster produced, as the error indicates. – Mo Correll Nov 05 '13 at 21:22
  • @mwil - forward slashes do not work, unfortunately. – Mo Correll Nov 05 '13 at 21:24
  • That code will not work without unquoted "r", forward slashes or double backslashes on both pathnames. For same reason as in previous question. Once these are fixed we can look at the next error. – PolyGeo Nov 05 '13 at 21:31
  • @PolyGeo - you're right, the text has been edited in the original question. – Mo Correll Nov 05 '13 at 21:33
  • It would seem that though your raster is not from the NLCD, the same error is being triggered. For that reason, the workaround they have provided, may work in your case as well. – Get Spatial Nov 05 '13 at 21:36
  • Could it be that the name of PC2 is 9 characters long (with a limit of 8)? I just had this very problem and I think that might have been my issue. – Chad Cooper Nov 05 '13 at 21:43
  • @Chad Cooper - I think the limit for GRID characters for a single raster is 13, multiple band is 8, thank you though! – Mo Correll Nov 05 '13 at 22:03
  • @GetSpatial - the work around does not work with my file, unfortunately. – Mo Correll Nov 05 '13 at 22:03
  • Were you able to get through any part of the process of the work-around? Barring this, let's go back to basics. Information about the rasters you are using, source, projection, cell size. Have you tried converting them to a different format and then running this operation? Are you able to run this operation on any other rasters? – Get Spatial Nov 05 '13 at 22:22
  • Another option, which is sometimes useful in a situation like this, is to call ESRI Support. Also, are you able to update to the most recent version of ArcGIS? It is possible that the error is actually being caused by a different problem that has been resolved in 10.2 – Get Spatial Nov 05 '13 at 22:29
  • @Get Spatial - I was able to get through the entire workaround, but when I input the new rasters into the code, the same error occurred. I'll add info about the files to the original post. – Mo Correll Nov 05 '13 at 22:29
  • @GetSpatial - I've also updated the original post with what other files and formats I have tried. – Mo Correll Nov 05 '13 at 23:02
  • 1
    sometimes my raster output goofs if i haven't set: arcpy.env.snapRaster = snapraster-path and arcpy.env.extent = "MAXOF". not sure if that will help with this error and i can't currently test. can you troubleshoot by checking that you are able to create each of your con statements as individual rasters? – mwil Nov 06 '13 at 15:22

1 Answers1

1

You need to change your %Temp% directory, it's trying to save the temporary result of the Con operation to your user folder (C:\Users\User\Documents\Mo Correll\ArcGis\) where is something like xx001258 and tripping over the space in your user name.

Make a folder on your 'c' root called MoTemp or something like that and set your temp and tmp environment variables to point there.

The isssue is not with the outCon.save(r"...) but before that.

Michael Stimson
  • 25,566
  • 2
  • 35
  • 74