<< GRASS-Kurs Skript zur Standortanalyse >>

#!/bin/sh
#---------------------------------------------------
# Exemplarische Standortanalyse im Shellskript
#---------------------------------------------------

d.mon start=x0
d.mon start=x1

function display_result 
{
  d.mon select=x0
  d.erase
  d.rast -o $1
  d.mon select=x1
  d.erase
  $2
  echo "press any key to continue"
  read $ch
}

function replace_nulls
{
  r.mapcalc replace_tmp="if(isnull($1), $2, $1)"
  g.remove rast=$1
  echo $1, $2
  g.rename rast=replace_tmp,$1
}

echo "---------------------------------------------------"
echo "Klassifizieren der Hangneigung"
echo "---------------------------------------------------"

echo "1 thru 2 = 1 sehr gut" > tmp_rules 
echo "3 thru 5 = 2 gut" >> tmp_rules
echo "6 thru 10 = 3 mittel" >> tmp_rules   
echo "11 thru 90 = 4 schlecht" >> tmp_rules   
cat tmp_rules
r.reclass i=slope o=slope_class < tmp_rules

data="slope_class"

replace_nulls $data 4

display_result $data "d.legend $data lines=4"


echo "---------------------------------------------------"
echo "Klassifizieren der Bodentiefe"
echo "---------------------------------------------------"

echo "1 2 3 = 4 schlecht" > tmp_rules
echo "0 4 = 1 gut" >> tmp_rules
cat tmp_rules

r.mapcalc soil=soil.br.depth

r.reclass i=soil o=soil.br.depth_class < tmp_rules


data="soil.br.depth_class"

replace_nulls $data 4

r.colors map=soil.br.depth_class color=rules << EOF
  4 red
  1 green
EOF

display_result $data "d.legend $data lines=4"


echo "---------------------------------------------------"
echo "Klassifizieren der Bodenart"
echo "---------------------------------------------------"

echo "1 thru 7 13 thru 16 = 1 geeigneter Untergrund" > tmp_rules
echo "8 thru 12 = 2 ungeeigneter Untergrund" >> tmp_rules
cat tmp_rules

r.mapcalc tex=texture

r.reclass i=tex o=tex_class < tmp_rules



data="tex_class"

replace_nulls $data 2
r.colors map=tex_class color=rules << EOF
  1 green
  2 red
EOF

display_result $data "d.legend $data lines=10"


echo "---------------------------------------------------"
echo "Die Fluesse: Pufferbildung, Klassifizierung        "
echo "---------------------------------------------------"
 
r.buffer i=streams o=streams_buff dist=100,300,600
echo "0 4 = 1 geeignet" > tmp_rules
echo "3 = 2 weniger gut geeignet" >> tmp_rules
echo "1 2 = 100 nicht geeignet" >> tmp_rules
cat tmp_rules

r.reclass i=streams_buff o=streams_class < tmp_rules


data="streams_class"

replace_nulls $data 1
r.colors map=streams_class color=rules << EOF
  1 green
  2 yellow
  100 red
EOF

display_result $data "r.report $data units=me"


echo "---------------------------------------------------"
echo "Die Strassen: Pufferbildung, Klassifizierung       "
echo "---------------------------------------------------"

r.report roads units=me
echo "1 2 3 = 1 (beruecksichtigte Straßen)" > tmp_rules
r.reclass i=roads o=roads_class.tmp < tmp_rules
r.report roads_class.tmp units=me

r.buffer i=roads_class.tmp o=roads_buff dist=100,300,600
echo "1 2 = 1 sehr gute Verkehrsanbindung" > tmp_rules
echo "3 = 2 gute Verkehrsanbindung" >> tmp_rules
echo "0 4 = 3 schlechte Verkehrsanbindung" >> tmp_rules
r.reclass i=roads_buff o=roads_class < tmp_rules

data="roads_class"

replace_nulls $data 3

display_result $data "d.legend $data lines=3"


echo "---------------------------------------------------"
echo " Landnutzung: Pufferbildung, Klassifizierung       "
echo "---------------------------------------------------"

echo "1 2 3 4 5 = 1" > tmp_rules
r.reclass i=landuse o=landuse_class.tmp < tmp_rules
r.report landuse_class.tmp

r.buffer i=landuse_class.tmp o=landuse_buff dist=1000,2000,4000 < tmp_rules
echo "1 2 = 100 schlecht" > tmp_rules
echo "3 = 3 mittel" >> tmp_rules
echo "0 4 = 1 gut" >> tmp_rules

r.reclass i=landuse_buff o=landuse_class < tmp_rules


data="landuse_class" 

replace_nulls $data 1
r.colors map=landuse_class color=rules << EOF
  1 green
  3 yellow
  100 red
EOF

display_result $data "r.report $data units=me"

echo "---------------------------------------------------"
echo " Reliefvariation: Nachbarschaftsanalyse            "
echo "---------------------------------------------------"
 
r.neighbors i=elevation.dem o=elev.min method=minimum size=11 
r.neighbors i=elevation.dem o=elev.max method=maximum size=11 
r.mapcalc elev.relief="elev.max-elev.min"
r.colors map=elev.relief color=gyr 

data="elev.relief"
display_result $data "d.histogram $data" 


echo "---------------------------------------------------"
echo " Reliefvariation: Klassifizierung                  "
echo "---------------------------------------------------"

echo "0 thru 10 = 1 sehr geringe Reliefvariation" > tmp_rules
echo "11 thru 20 = 2 geringe Reliefvariation" >> tmp_rules  
echo "21 thru 30 = 3 hoehere Reliefvariation" >> tmp_rules 
echo "31 thru 300 = 100 starke Reliefvariation" >> tmp_rules

r.reclass i=elev.relief o=elev.relief_class < tmp_rules
r.colors map=elev.relief_class color=rules << EOF
  1 green
  2 yellow
  3 brown
  100 red
EOF

data="elev.relief_class"
display_result $data "r.report $data units=me" 


echo "---------------------------------------------------"
echo " Rasterarithmetik: Addition der Raster             "
echo "---------------------------------------------------"

r1="slope_class"
r2="tex_class"
r3="soil.br.depth_class"
r4="streams_class"
r5="roads_class"
r6="landuse_class"
r7="elev.relief_class"

echo "r.mapcalc deponie=\"$r1 + $r2 + $r3 + $r4 + $r5 + $r6 + $r7\""
r.mapcalc deponie="$r1 + $r2 + $r3 + $r4 + $r5 + $r6 + $r7"  

data="deponie"
display_result $data "r.report $data units=me" 


echo "---------------------------------------------------"
echo " Eingrenzen guenstiger Standorte, Schwellenwert    "
echo "---------------------------------------------------"

r.mapcalc deponie.lt17="if(deponie < 17, 1, 2)"

data="deponie.lt17"
display_result $data "r.report $data" 

echo "---------------------------------------------------"
echo " Unterdruecken von Kleinstflaechen, Objektbildung  "
echo "---------------------------------------------------"

r.neighbors i=deponie.lt17 o=deponie.lt17.m si=11 meth=mode 

r.mapcalc deponie.lt17.m="if(deponie.lt17.m == 1)"
r.clump i=deponie.lt17.m o=deponie.lt17.m.obj

data="deponie.lt17.m.obj"
display_result $data "r.report $data units=me" 

d.mon select=x0
d.vect streams color=blue
d.vect roads color=black

echo "---------------------------------------------------"
echo " Aufraeumen, Loeschen der Zwischenergebnisse       "
echo "---------------------------------------------------"

g.remove rast=$r1,$r2,$r3,$r4,$r5,$r6,$r7 
g.remove rast=deponie,deponie.lt17,deponie.lt17.m
g.remove rast=elev.max,elev.min,elev.relief
g.remove rast=landuse_class.tmp,landuse_buff,roads_buff,streams_buff

g.rename rast=deponie.lt17.m.obj,deponie

echo "---------------------------------------------------"
echo " Thank you for using $0, your result map: deponie  " 
echo "---------------------------------------------------"

Das Skript depo3 kann vom Server heruntergeladen und in einem Editor angepasst werden:
Mit rechter Maustaste den Link anklicken und "Ziel speichern unter" wählen.
Die automatisch vorgeschlagene Dateiendung .htm entfernen.

<< GRASS-Kurs Skript zur Standortanalyse >>