[GRASS-user] Trying to correct river network

Pankaj Kr Sharma pkscwc at gmail.com
Wed Nov 2 01:30:21 EDT 2011


Dear friends,

Some days back , I had problems with a script used to correct river network.
With help from a database expert and friend, the script worked perfectly
for me.
With thought that it may help, correct script is posted below:

elcat=4907;
echo "delete  from  gis_schema.cat_temp;" > file.sql;
db.execute input=file.sql;
echo "delete  from  gis_schema.cat_temp_done;" > file.sql;
db.execute input=file.sql;
while [ $elcat ]
do
cats=`echo "select cat from gis_schema.riy4 where start_long=(select
start_long from gis_schema.riy4 where cat=$elcat) and start_lat=(select
start_lat from gis_schema.riy4 where cat=$elcat) and cat <> $elcat; " |
db.select -c;`
    for i in $cats
    do
    echo $cats;
    v.edit  map=riy4 at work layer=1 tool=flip cats=$i;
    sl=`echo "select start_long from gis_schema.riy4 where cat=$i;" |
db.select -c;`
    slat=`echo "select start_lat from gis_schema.riy4 where cat=$i;" |
db.select -c;`
    el=`echo "select end_long from gis_schema.riy4 where cat=$i;" |
db.select -c;`
    elat=`echo "select end_lat from gis_schema.riy4 where cat=$i;" |
db.select -c;`
    v.db.update  map=riy4 at work layer=1 column=start_long value=$el
where="cat=$i";
    v.db.update  map=riy4 at work layer=1 column=start_lat value=$elat
where="cat=$i";
    v.db.update  map=riy4 at work layer=1 column=end_long value=$sl
where="cat=$i";
    v.db.update  map=riy4 at work layer=1 column=end_lat value=$slat
where="cat=$i";
    echo " $i loop1"
    done
echo " This value $elcat will be used to calculate cats_to_write" ;
echo "insert into gis_schema.cat_temp_done (cat) values($elcat);" >
file.sql;
db.execute input=file.sql;
cats_to_write=`echo "select cat from gis_schema.riy4 where end_long=(select
start_long from gis_schema.riy4 where cat=$elcat) and end_lat=(select
start_lat from gis_schema.riy4 where cat=$elcat)  and cat not in (select
cat from gis_schema.cat_temp_done); " | db.select -c;`
echo $cats_to_write;
echo "delete  from  gis_schema.cat_temp where cat= $elcat;" > file.sql;
db.execute input=file.sql;
echo " After populating cats_to_write this value $elcat is deleted in loop2"
for k in $cats_to_write
do
echo "insert into gis_schema.cat_temp (cat) values($k);" > file.sql;
db.execute input=file.sql;
done
echo " These values of cats_to_write $k are written in loop2"
elcat=`echo "select  cat from gis_schema.cat_temp limit 1;" | db.select -c;`
echo "from database for next loop $elcat";
done

Note:
elcat means end line category.
And, please create database links and tables appropriately as mentioned
above.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/grass-user/attachments/20111102/0fbb9be5/attachment.html


More information about the grass-user mailing list