1

I have three rasters:

  • Raster1: resolution 25x25, floating point. Value of "1" when it is true, value of -9999 when it is false (only this two values)
  • Raster2: resolution 25x25, floating point. Only integer values from 194 to 1738
  • Raster3: resolution 25x25, floating point. Decimal values are stored too, from -2544,81 to 941,66

All the rasters have the same CRS and are in TIFF format.

What I want to do is to create a fourth raster like this:

If Raster1 =1, then Raster2 (true statement), else Raster3 (false statement)

I tried this in ArcGis 10.3 Raster Calculator:

Con("Raster1" == 1,"Raster2","Raster3")

But I get this error:

Con(Raster(r"Raster1") == 1,Raster(r"Raster2"),Raster(r"Raster3"))
ERROR 000539: Error running expression: rcexec() 
Traceback (most recent call last):
File "<expression>", line 1, in <module>
File "<string>", line 8, in rcexec
RuntimeError: ERROR 010240: Could not save raster dataset to F:\folder\step13 with output format GRID.

Failed to execute (RasterCalculator).

I tried the same thing using Python:

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "F:/folder"
Ras1 = Raster("Raster1")
Ras2 = Raster("Raster2")
Ras3 = Raster("Raster3")
outCon = Con((Ras1==1),Ras2, Ras3)
outCon.save = ("F:/folder/out")

But I get this error:

RuntimeError: ERROR 000875: Output raster: C:\xxx\xxx\Documents\ArcGIS\Default.gdb\ifthe_ras's workspace is an invalid output workspace.

I'm stuck. I cannot understand what's wrong with my raster calculations.

6
  • Try saving it as F:\folder\step13.tif.
    – HDunn
    Commented Aug 3, 2017 at 10:29
  • @HDunn using the backslashes and adding the .tif results in the same error as above (modifying it in the Python code)
    – Vale
    Commented Aug 3, 2017 at 10:29
  • 1
    @Vale - Not tested but for the QGIS Raster Calculator, try (('Raster1@1' = 1) * 'Raster2@1') + (('Raster1@1' != 1) * 'Raster3@1')
    – Joseph
    Commented Aug 3, 2017 at 10:35
  • @joseph it worked at 90% now I have to understand what went wrong
    – Vale
    Commented Aug 3, 2017 at 10:47
  • Does the name of the output raster exceed 13 characters? Esri GRID format can accept up to 13 characters file name.
    – ahmadhanb
    Commented Aug 3, 2017 at 11:12

1 Answer 1

2

I used the same formula as yours and it worked without any problem:

I used ERDAS Imagine Format (.img) for my input and output raster calculation to avoid the limitation of 13 characters in ESRI GRID format, so I can give a name longer than 13 characters.

enter image description here

AS you can see above the RasterCalc which is the output is already calculated and loaded in the available layers to use in the future.

Here is the input formula:

Con("Elev.img" == 1,"Soil_CC.img","Soil_PP.img")

So I think the problem - based on the message you received - is related to the name of the output file which might be exceeding the 13 characters. to avoid that add an extension such as .img or .tif in the output file name.

3
  • The name of the output doesn't exceed 13 characters, but the input rasters yes. I'm gonna try to reduce the input files names
    – Vale
    Commented Aug 3, 2017 at 12:05
  • The problem was the name of the INPUT files, not the output one. And forcing the output with the .tif extension worked. So what have I done: renamed the input rasters to have less than 13 characters and forced the output to be a .tif file
    – Vale
    Commented Aug 3, 2017 at 12:13
  • Glad it worked :)
    – ahmadhanb
    Commented Aug 3, 2017 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.