Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

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 created a python script where I use Con (Spatial Analyst). Till now I passed the where clause value as value>1000 and it worked fine for me. But recently I found some raster on which Con statement does not work and says that the expression is not valid or something like that. Now I put space before and after > sign and the expression is now value > 1000. The weird thing is the script works fine now.

Con does not work when con expression is value>1000, for raster files that are big in size, but works fine when con expression is value > 1000, for my case, it was 50MB. Only putting two spaces solves the problem

Question: I go through Con (Spatial Analyst) documentation. I do not find anything that can explain why is this happening. Can anybody explain Why is this weird thing happening?

share|improve this question
up vote 5 down vote accepted

Many tools will fail if the there are no spaces around the operands. It is just good practice. Here are several other links dealing with Con and

Try to select entry grids and operands rather than typing them in if you are using the raster calculator. Also, keep a text file of statements that you might use regularly so that the correct syntax is on hand. Good luck.

share|improve this answer
actually I wrote a python script, I am not using raster calculator. As it is a python script, and in python there should not be any difference if there is a space or not. So, I thought it is weird. As a programmer, I just want to know the reason behind it. – Emi Mar 11 '13 at 21:19
Emi, Python is merely passing arguments to the SA commands on to an internal interpreter. In my experience the parsing (and even the lexical analysis) of expressions in that interpreter have never worked right, and it appears someone at ESRI knows it, because the syntax keeps changing--but seems never to be fixed (or even clearly documented). )-:. Dan is correct about "good practice": you have to play around and develop methods to help the poor interpreter out as much as you possibly can, by judicious insertion of space and other delimiters. – whuber Mar 11 '13 at 21:22
@whuber I got the "good practice" matter and now following this. As you say the matter of parsing, I think, in that case, raster file size should not make any difference. As I said, without space con expression creates error only when the raster file size is big. It works fine for small size raster data. So, I don't think it is a parsing problem... – Emi Mar 12 '13 at 5:19
Well, this is a mystery: your question still asserts that adding whitespace to the command changes the result. No matter what else may be going on, that's definitely a parsing problem. There also may be a problem related to raster size. Having both problems present could be confusing. Could you do any research to isolate or rule out one of these factors? For instance, are you absolutely sure that the version without whitespace actually works for small rasters? – whuber Mar 12 '13 at 15:48

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.