Select to view content in your preferred language

Use Raster Calculator to Modify DEM Elevations based on a Mask

5176
7
Jump to solution
09-14-2015 01:32 PM
PeterVersteeg
Occasional Contributor II

Hallo,

i know its allmost the same question as "Use Raster Calculator to Modify DEM Elevations based on Vector Layer​but i am trying to build a model but i am stuck.

model.png

my first model, and i got that to work has this expression:

Con(IsNull("%Output_raster%"),float(%Double%), "%Output_raster%"). but this sets a value.

what I now want is to subtract a value from the DEM using this model.

can sameone help me with the right expressing.

Thank you and Greeting Peter

0 Kudos
1 Solution

Accepted Solutions
DarrenWiens2
MVP Honored Contributor

Do you need to decide whether to subtract or set the value based on the pixel position (different parts of the raster would be subtracted or set), or do you want to decide for the whole model (on one run you subtract all that meet a condition, and on the next you set all that meet a condition)?

edit: it sounds like you want to apply your choice whether to subtract or set for the whole model. You can do this by adding a new variable (boolean or integer or some other flag) and nesting Con() statements:

Con(newVariable = 1, Con(IsNull("%Mask_raster%"),"%Input_raster%", ("%Input_raster%" -float(%Double%))), Con(IsNull("%Mask_raster%"),"%Input_raster%", ("%Input_raster%"  == float(%Double%))))

...which translates to: if the value of newVariable = 1, do the subtract statement, else do the set statement. You could do this with a boolean checkbox, too.

View solution in original post

7 Replies
DarrenWiens2
MVP Honored Contributor

Con is confusing, but hopefully this will help.

Con(first, second, third) translates to: for each pixel, if the first thing is true, return the second thing. If the first thing is not true, return the third thing.

I'm not sure I completely understand what you want to do, but if I'm right that you want to subtract a value (or raster) if it falls within a mask, and use the original value if not, then you should use an expression like:

Con(IsNull("mask"), "original", ("original" - some number or raster))

This expression translates to: check each pixel. If it is not in the mask (i.e. is null), use the original raster value. If the pixel is in the mask, subtract some value (or raster) from the original raster. Of course, change "some value or raster", to a value or raster.

PeterVersteeg
Occasional Contributor II

Thank you Darren for this clear explanation. Now I get it

This model is for burning my water into a DEM.

This is my new model

model2.png

The expression i use now is:

Con(IsNull("%Mask_raster%"),"%Input_raster%", ("%Input_raster%" -float(%Double%)))

And it works great. BUT I can only use it to subtract a value. I could think about a use for this model when I want to simply set a value. The expression would look like:

Con(IsNull("%Mask_raster%"),"%Input_raster%", ("%Input_raster%"  == float(%Double%)))

Is there a way to choose between – (subtract) and == (set value) in a model?

again thank you Darren

NeilAyres
MVP Alum

Just return the double thus :

Con(IsNull("%Mask_raster%"),"%Input_raster%", (float(%Double%)))

PeterVersteeg
Occasional Contributor II

sorry you did not understand me. your expression only sets a value. now i cannot subtract a value from my DEM with this expression.

i could make 2 models but is there a way to do both in 1 model?

gr Peter

0 Kudos
DarrenWiens2
MVP Honored Contributor

Do you need to decide whether to subtract or set the value based on the pixel position (different parts of the raster would be subtracted or set), or do you want to decide for the whole model (on one run you subtract all that meet a condition, and on the next you set all that meet a condition)?

edit: it sounds like you want to apply your choice whether to subtract or set for the whole model. You can do this by adding a new variable (boolean or integer or some other flag) and nesting Con() statements:

Con(newVariable = 1, Con(IsNull("%Mask_raster%"),"%Input_raster%", ("%Input_raster%" -float(%Double%))), Con(IsNull("%Mask_raster%"),"%Input_raster%", ("%Input_raster%"  == float(%Double%))))

...which translates to: if the value of newVariable = 1, do the subtract statement, else do the set statement. You could do this with a boolean checkbox, too.

PeterVersteeg
Occasional Contributor II

He Darren,

your right this is what i want with this model. i understand the expression but setting the new variable is not working.

i would like to use the boolean chack box. it is in my model as a precondition for the raster calculator. this do's not work. i did not change your expression. i think i need to set the boolean but do not know were or how.

thank you again for the help and the explanation. that the tools is not working is all on me

greetings Peter

0 Kudos
curtvprice
MVP Esteemed Contributor

Darren, don't forget double equals:  ==

Also if you have a boolean model variable named CheckBox you can recast it to integer.

Con( int("%CheckBox%") == 1,
    Con(IsNull("Mask_raster")
        "Input_raster", 
        ("Input_raster" - float(%Double%))), 
    Con(IsNull("Mask_raster"),
        "Input_raster",
        float(%Double%)))