[GRASS-user] mapcalc - formula

Martin Schweizer schweizermartin at students.unibe.ch
Mon Oct 19 07:26:52 EDT 2009


Hi

I have the following problem: I have the following formula from
http://grass.osgeo.org/gdp/raster/mapcalc-algebra.pdf on page 12.

wasser = wasser+eval(x=elev+wasser,\

if(x>(y=elev[-1,0]+wasser[-1,0]),\
-.15*if(elev>y,wasser,x-y),\
.15*if(elev[-1,0]>x,wasser[-1,0],y-x))+\

if(x>(y=elev[1,0]+wasser[1,0]),\
-.15*if(elev>y,wasser,x-y),\
.15*if(elev[1,0]>x,wasser[1,0],y-x))+\

if(x>(y=elev[0,-1]+wasser[0,-1]),\
-.15*if(elev>y,wasser,x-y),\
.15*if(elev[0,-1]>x,wasser[0,-1],y-x))+\

if(x>(y=elev[0,1]+wasser[0,1]),\
-.15*if(elev>y,wasser,x-y),\
.15*if(elev[0,1]>x,wasser[0,1],y-x))+\

if(x>(y=elev[-1,1]+wasser[-1,1]),\
-.10*if(elev>y,wasser,x-y),\
.10*if(elev[-1,1]>x,wasser[-1,1],y-x))+\

if(x>(y=elev[1,1]+wasser[1,1]),\
-.10*if(elev>y,wasser,x-y),\
.10*if(elev[1,1]>x,wasser[1,1],y-x))+\

if(x>(y=elev[1,-1]+wasser[1,-1]),\
-.10*if(elev>y,wasser,x-y),\
.10*if(elev[1,-1]>x,wasser[1,-1],y-x))+\

if(x>(y=elev[-1,-1]+wasser[-1,-1]),\
-.10*if(elev>y,wasser,x-y),\
.10*if(elev[-1,-1]>x,wasser[-1,-1],y-x)))

Now the problem is, that this formula just distribute a given portion of water over the land. So if you have a flat surface, you get values like 0,0000001... But what i want is, that the distribution of the water continues only, if the water has reached a certain level. I have a elev-raster with e range from -4 to 10000 and I would that the distribution only continue, if the water has reached the level 0. 
So, does anyone see a possiblilty, how i could do this? Could i perhaps somehow combine the formula above with the formula from r.lake the way I dont add or lose water (formula above) but only continue to distribute when a certain level is reached (formula below)?:

${seedmap} = if( ${dem}, \
if( if( isnull(${seedmap}),0,${seedmap}>0), ${wlevel}-${dem}, \
 if( \
  if(isnull(${seedmap}[-1,0]),0, ${seedmap}[-1,0]>0 && ${wlevel}>${dem}) ||\
  if(isnull(${seedmap}[-1,1]),0, ${seedmap}[-1,1]>0 && ${wlevel}>${dem}) ||\
  if(isnull(${seedmap}[0,1]), 0, ${seedmap}[0,1]>0  && ${wlevel}>${dem}) ||\
  if(isnull(${seedmap}[1,1]), 0, ${seedmap}[1,1]>0  && ${wlevel}>${dem}) ||\
  if(isnull(${seedmap}[1,0]), 0, ${seedmap}[1,0]>0  && ${wlevel}>${dem}) ||\
  if(isnull(${seedmap}[1,-1]),0, ${seedmap}[1,-1]>0 && ${wlevel}>${dem}) ||\
  if(isnull(${seedmap}[0,-1]),0, ${seedmap}[0,-1]>0 && ${wlevel}>${dem}) ||\
  if(isnull(${seedmap}[-1,-1]),0, ${seedmap}[-1,-1]>0 && ${wlevel}>${dem}),\
 ${wlevel}-${dem}, null() )))

Thanks a lot! And best regards

Martin



More information about the grass-user mailing list