[GRASS-user] Re: Building topologically correct stream network

Jarek Jasiewicz jarekj at amu.edu.pl
Tue Jul 21 15:02:36 EDT 2009



Markus Metz pisze:
> Hi Jarek
>
> Jarek Jasiewicz wrote:
>> Hi
>>
>> maybe this will help:
>>
>> http://gis.vsb.cz/GIS_Ostrava/GIS_Ova_2009/sbornik/Lists/Papers/060.pdf
>
> What were the limitations of the GRASS raster-to-vector conversion 
> tools you encountered? 
that problems are shown on fig 4)

1) streams directions are not correct (are random) because we have no 
information about its directions in raster file
2) there are problems if streamlines toutch each other like


> It's not clear to me from Fig. 3, but I would like to understand the 
> problem, and I hope you can explain it in a bit more detail.
In fact I use script to convert Terrain Analysis System data to Grass 
topological data. I attached it here (note it is not GRASS script with 
full error handling). Sorry for polish comment but I have not time to 
translate it. If you need more information how it works contact me off list.

Jarek

BTW I'm about to finish regular grass modue for calculating Strahler 
Stream order and Shreeve Stream Magnitude. I hope I publish it for 
testing in next few days. Any help appreciated.
>
> Thanks a lot,
>
> Markus M
-------------- next part --------------
#!/bin/bash

zlewnia=`eval g.gisenv get=MAPSET`
cieki='cieki_'$zlewnia
vertex='vertex_'$zlewnia

vector='index_vector'
links='index' #unikalne numery strumieni
class='class' #klasy punktów/odcinków (arc/nodes)
strahler='strahler' #plik z strahler stream order
shrevee='sreeve' #plik z strahler stream order
main='main'

#hierarchia zlewni
zlewnia_elem='elem'
z1='w1'
z2='w2'
z3='w3'
z4='w4'
z5='w5'
z6='w6'

#parametry morfometryczne strumieni
elev='elev'
elev2main='elev2main'
slope='slope'
planc='planc'
profc='profc'
maxic='maxic'
diff5='diff5'
diff9='diff9'
diff15='diff15'


#######         Koniec definicji       ###

db.connect driver=pg database='rzeki_mgr'
g.mremove -f rast=tmp* vect=tmp* &2>/dev/null #usuÅ„ tempy jeżeli istniejÄ

g.remove -f vect=$cieki &2>/dev/null #usuń wynikowy plik jeśżeli istnieje
echo 'DROP table tmp_streams'|db.execute &2>/dev/null #usuń tabelę tmp_streams jeżeli istnieje
echo 'DROP table tmp_streams_param'|db.execute &2>/dev/null #usuń tabelę tmp_streams jeżeli istnieje
#echo 'DROP table tmp_katy'|db.execute &2>/dev/null #usuń tabelę tmp_streams jeżeli istnieje
echo 'DROP table tmp_join'|db.execute &2>/dev/null #usuń tabelę tmp_streams jeżeli istnieje

####określenie regionu analizy
g.region rast=$class #ustaw region względem pliku class 

####### procedura wygenerowania punktów z mapy

# najpierw sprawdzamy, czy plik ma kategorie jeżeli nie kończymy
tp=`eval v.category -g input=$vector type=line option=report`>/dev/null 
if [ -z $tp ]
then
echo "wektor nie ma kategorii. Przewiduję problemy, więc kończę"
exit 1
fi

v.to.points -n input=$vector output=tmp_point type=point,line llayer=1 dmax=100
v.db.addcol map=tmp_point layer=2 'columns=rzad INTEGER, magn INTEGER, link INTEGER, is_main INTEGER, zlewnia_elem INTEGER, z1 INTEGER, z2 INTEGER, z3 INTEGER, z4 INTEGER, z5 INTEGER, z6 INTEGER' 

#probkowanie rastrow
v.what.rast vector=tmp_point raster=$links layer=2 column=link
v.what.rast vector=tmp_point raster=$strahler layer=2 column=rzad
v.what.rast vector=tmp_point raster=$shrevee layer=2 column=magn
v.what.rast  vector=tmp_point raster=$main layer=2 column=is_main
echo 'zlewnia_elem'
v.what.rast  vector=tmp_point raster=$zlewnia_elem layer=2 column=zlewnia_elem
v.what.rast  vector=tmp_point raster=$z1 layer=2 column=z1
v.what.rast  vector=tmp_point raster=$z2 layer=2 column=z2
v.what.rast  vector=tmp_point raster=$z3 layer=2 column=z3
v.what.rast  vector=tmp_point raster=$z4 layer=2 column=z4
v.what.rast  vector=tmp_point raster=$z5 layer=2 column=z5
v.what.rast  vector=tmp_point raster=$z6 layer=2 column=z6 





#tworzenie tabeli zawierajÄ
cej uśrednione parametry morfometryczne strumieni
v.to.points -i input=$vector output=$vertex type=line dmax=20 
v.db.addcol map=$vertex layer=2 'columns=elev REAL, elev2main REAL, elev2stream REAL, slope REAL, planc REAL, profc REAL, maxic REAL, diff5 REAL, diff9 REAL, diff15 REAL'

#probkowanie dużej tabeli. Tabela vertex zostaje zachowana ze względu na przydatność do innych celów
v.what.rast vector=$vertex raster=$elev layer=2 column=elev
v.what.rast vector=$vertex raster=$elev2main layer=2 column=elev2main
v.what.rast vector=$vertex raster=$slope layer=2 column=slope
v.what.rast vector=$vertex raster=$planc layer=2 column=planc
v.what.rast vector=$vertex raster=$profc layer=2 column=profc
v.what.rast vector=$vertex raster=$maxic layer=2 column=maxic
v.what.rast vector=$vertex raster=$diff5 layer=2 column=diff5
v.what.rast vector=$vertex raster=$diff9 layer=2 column=diff9
v.what.rast vector=$vertex raster=$diff15 layer=2 column=diff15



echo 'CREATE TABLE tmp_streams_param AS SELECT lcat AS lcat, avg(elev) AS rzedna, avg(elev2main) AS elev2mean, avg(slope) AS slope, avg(planc) AS planc, avg(profc) AS profc, avg(maxic) AS maxic, avg(diff5) AS diff5, avg(diff9) AS diff9, avg(diff15) AS diff15 FROM '$vertex'_2 GROUP BY lcat'|db.execute


#utworzenie tabeli zawierajÄ
cej STAHLER STEAM ORDER oraz LINK wektora (tylko postgreSQL lub SQLite!)

echo 'CREATE TABLE tmp_streams AS SELECT p0.lcat as cat, p0.rzad, p0.magn as magn, p0.link as link, p1.link AS link_to, p0.is_main as main, p1.is_main as contrib, p0.zlewnia_elem as zlewnia_elem, p0.z1 AS z1, p0.z2 AS z2, p0.z3 AS z3, p0.z4 AS z4, p0.z5 AS z5, p0.z6 AS z6 FROM (SELECT lcat, link, is_main FROM tmp_point_2 WHERE along>0) p1 INNER JOIN (SELECT lcat, link, rzad, magn, is_main, zlewnia_elem, z1, z2, z3, z4, z5, z6  FROM tmp_point_2 WHERE along=0) p0 ON p0.lcat=p1.lcat'|db.execute


#PolÄ
czenie tabel
echo 'CREATE TABLE tmp_join AS SELECT * FROM tmp_streams c INNER JOIN tmp_streams_param p ON c.cat=p.lcat'|db.execute


g.copy vect=$vector,tmp_join
v.db.connect -o map=tmp_join table=tmp_join driver=pg database='rzeki_mgr' key=cat layer=1 

v.db.addcol map=tmp_join layer=1 'columns=dlugosc REAL'
v.to.db map=tmp_join type=line option=length columns=dlugosc 

g.copy vect=tmp_join,$cieki
g.mremove -f rast=tmp* vect=tmp* 
echo 'DROP table tmp_streams'|db.execute &2>/dev/null 
echo 'DROP table tmp_streams_param'|db.execute &2>/dev/null 
#echo 'DROP table tmp_katy'|db.execute &2>/dev/null 

echo 'DROP table tmp_join'|db.execute &2>/dev/null #usuń tabelę tmp_join jeżeli istnieje


More information about the grass-user mailing list