Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a problem when using the con() argument.

What I want to do is to remap all raster of a raster file ("Red_SL") cells with values larger than 40 to the new value 5. All other values should be replaced by another raster file called "remap2". "remap" 2 contains only 4 definite values (1,2,3,4), and "Red SL" has continuous values between 0 and 90.

My syntax is the following:

import arcpy
from import *

arcpy.env.overwriteOutput = True
arcpy.env.workspace = r"D:\\Projekt\\Testprojekt\\Daten\\Ergebnisse\\"
remaped2 = "remaped2.img"
slope = "Red_SL"

CF= Con((slope < 40), 5, remaped2)"Red_SL_Neigung_int.tif")

now the problem is: I do not get an error message but the produced file is nonsense! Python is somehow not able to recognize the slope value in: CF= Con((slope < 40), 5, total) This means it doesent matter what value I give python (here I set it to 40, but I will get the exact same result if I give values of 1 or 3000), the result will always be the a new file which is exactly the same as "remaped2". Python therefore thinks all values are below 40 (or whatever number I give), which is not true.

The exact opposite happens if I change the "<" to ">" (CF= Con((slope > 40), 5, total)). Now I will get i new file, which has only 5 in every raster cell. Here again the value whch I type in (instead of 40) does not matter, any value between 1 and 3000 will produce the exact same result. I double checked, but the file "Red_SL" has all values between 0 and 90, therfore the result I get from python is nonsense.

I already tried (without sucess): -Change "Red_SL" from floating to integer -try differend formats (tif, grid, img) for "Red_SL" - replace comma in floating raster with points (german vs. englisch delimiters)

Can anyone see what is wrong with my use of the Con arguement?

share|improve this question
As you have put an r in front of the string for the workspace you do not need to use \\ use a single \. – Hornbydd Jul 30 '14 at 13:40
Thank you. I removed the doubleslashes but it has no effect on the the problem. Anyway, good to know! – Christophmang Jul 30 '14 at 13:42
Yes you are right. I am sorry but this was just o fault of myself which happened wehn I copied the syntax into the forum (I have tried so many ways that I had to rechange some stuff). However, I changed it in the posted syntax as well as on my computer but still the same results – Christophmang Jul 30 '14 at 13:50

You need to create raster objects when working with many of the spatial analyst tools, including Con (Spatial Analyst). Try the following changes:

import arcpy
from import *

arcpy.env.overwriteOutput = True
arcpy.env.workspace = r"D:\Projekt\Testprojekt\Daten\Ergebnisse"
remaped2 = Raster("remaped2.img")
slope = Raster("Red_SL")

CF= Con((slope < 40), 5, remaped2)"Red_SL_Neigung_int.tif")
share|improve this answer
Thats the solution! Thanks a lot for your help everything works fine now!! – Christophmang Jul 30 '14 at 13:58
@Christophmang if this is a solution for you, you should tick it as correct. – Hornbydd Jul 30 '14 at 15:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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