<br><br><div class="gmail_quote">Dear friends,<br><br>Some days back , I had problems with a script used to correct river network.<br>With help from a database expert and friend, the script worked perfectly for me.<br>With thought that it may help, correct script is posted below:<br>
<br></div>elcat=4907;<br>echo "delete from gis_schema.cat_temp;" > file.sql;<br>db.execute input=file.sql;<br>echo "delete from gis_schema.cat_temp_done;" > file.sql;<br>db.execute input=file.sql;<br>
while [ $elcat ]<br>do<br>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;`<br>
for i in $cats<br> do<br> echo $cats;<br> v.edit map=riy4@work layer=1 tool=flip cats=$i;<br> sl=`echo "select start_long from gis_schema.riy4 where cat=$i;" | db.select -c;`<br> slat=`echo "select start_lat from gis_schema.riy4 where cat=$i;" | db.select -c;`<br>
el=`echo "select end_long from gis_schema.riy4 where cat=$i;" | db.select -c;`<br> elat=`echo "select end_lat from gis_schema.riy4 where cat=$i;" | db.select -c;`<br> v.db.update map=riy4@work layer=1 column=start_long value=$el where="cat=$i";<br>
v.db.update map=riy4@work layer=1 column=start_lat value=$elat where="cat=$i";<br> v.db.update map=riy4@work layer=1 column=end_long value=$sl where="cat=$i";<br> v.db.update map=riy4@work layer=1 column=end_lat value=$slat where="cat=$i";<br>
echo " $i loop1"<br> done<br>echo " This value $elcat will be used to calculate cats_to_write" ;<br>echo "insert into gis_schema.cat_temp_done (cat) values($elcat);" > file.sql;<br>
db.execute input=file.sql;<br>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;`<br>
echo $cats_to_write;<br>echo "delete from gis_schema.cat_temp where cat= $elcat;" > file.sql;<br>db.execute input=file.sql; <br>echo " After populating cats_to_write this value $elcat is deleted in loop2"<br>
for k in $cats_to_write<br>do<br>echo "insert into gis_schema.cat_temp (cat) values($k);" > file.sql;<br>db.execute input=file.sql; <br>done<br>echo " These values of cats_to_write $k are written in loop2"<br>
elcat=`echo "select cat from gis_schema.cat_temp limit 1;" | db.select -c;`<br>echo "from database for next loop $elcat";<br>done<br><br>Note:<br>elcat means end line category.<br>And, please create database links and tables appropriately as mentioned above.<br>