Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am experiencing a painful problem in the middle of a Python script I am writing. When I get to a Map Algebra function, I have tried two different options and both return a different error.

At first I wrote:

facteur_Pente = Con((surf_Drainee > 12)  &  (surf_Drainee <= 80)  &  (pente_Rclass <= 24),pente_Rclass + 1, Con((surf_Drainee > 80)  &  (pente_Rclass < 24),pente_Rclass + 2,Con((surf_Drainee > 80)  &  (pente_Rclass == 24),pente_Rclass + 1,pente_Rclass)))

The error I get from this is: "TypeError: cannot concatenate 'str' and 'int' objects"

This seems normal, as I have strings (surf_Drainee, pente_Rclass) so I convert the values to str using the following:

facteur_Pente = Con(("surf_Drainee" > str(12))  &  ("surf_Drainee" <= str(80))  &  ("pente_Rclass" <= str(24)),"pente_Rclass" + str(1), Con(("surf_Drainee" > str(80))  &  ("pente_Rclass" < str(24)),"pente_Rclass" + str(2),Con(("surf_Drainee" > str(80))  &  ("pente_Rclass" == str(24)),"pente_Rclass" + str(1),"pente_Rclass")))

The problem is that it doesn't work, and produces the following error: "RuntimeError: ERROR 000732: Input Raster: Dataset pente_Rclass1 does not exist or is not supported."

I don't even have a pente_Rclass1 in my script!

Does anybody know how I could fix this problem in order to continue my script?

Regards,

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

My initial thought is that you must have assigned the variable pente_Rclass to a string representation of a raster instead of a raster object. This would cause your first error. See below:

pente_Rclass = "myRasterName"

represents a string... if you are using this in arcpy methods, it will automatically assume that this string is the name of a dataset in your defined workspace, but it will NOT allow you perform map algebra without further information. Try defining pente_Rclass as a Raster object if you are in ArcMap 10 or 10.1:

pente_Rclass = arcpy.Raster("myRasterName")

Now pente_Rclass is a raster object and can be used in map algebra calculations.

On your second attempt, you are merely merging two strings (the string "pente_Rclass" and the string representation of the number "1") which gives you "pente_Rclass1". That dataset doesn't exist, thus the error.

It might be helpful if you edit your question to include more of your script, specifically where the relevant variables are being assigned.

NOTE: I specifically pointed out pente_Rclass because that's where you are getting the first error, however all of your raster variables should be raster objects. If each of your variables are just string representations, the script will still run your boolean checks (surf_Drainee > 12, etc), as strings can be compared to numbers in Python, but it is not what you are intending to do.

share|improve this answer
    
Thank you very much for you answer, and especially your explanations! I spend the day trying to figure out what was wrong. I am new to Python scripting and some things are a headache, but I am enjoying the learning process. As you said, I was defining my local variables as Variable = "Variable". I got the operation to work by adding arcpy.Raster() to my rasters in the first part of the code written. However, strangely, the result of the operation does not show up in my file GDB like the other results further up and down. –  Maxim L Dec 12 '12 at 22:41
1  
Yes, I'm sorry I should have mentioned that when you create a raster object using variable = arcpy.Raster("myRaster") it creates the object in memory. To save the resulting raster, make sure you are assigning the Con result to a variable: resultRaster = Con(parameters) and then make sure you add this line: resultRaster.save("resultRasterName") –  egdetti Dec 12 '12 at 23:19
add comment

Your Answer

 
discard

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.