Hi everybody<br>A few weeks ago, a discussion abour how to break a vector line by a vector point was beginned.<br>I create a script in shell to solve this issue in grass 6.0.1. You need the add on v.append and v.out.ascii.db
 to launch this script (add on avalaible on <a href="http://grass.gdf-hannover.de/wiki/GRASS_AddOns">http://grass.gdf-hannover.de/wiki/GRASS_AddOns</a>)<br>You choose a vector line and a vector point (the points need to be on the line to cut the lines) and the script create a new intersected vector line
<br>Any comments or suggestions are welcome.<br><br>Cheers <br><br>Mick<br><br>&nbsp;#!/bin/bash<br>#break a vector line by a vector point and create a new vector line<br>#need the Add On v.out.ascii.db and v.append<br>#the different vectors do not have the columns x,y,along,lcat and type
<br>#because this script create these columns and there are no securities for<br>#checking their presence <br>#in line 179 of this script, we delete an esri column because we worked with esri<br>#vector imported in grass format
<br><br>if&nbsp; [ -z &quot;$GISBASE&quot; ]<br>then<br>&nbsp;&nbsp;&nbsp; echo &quot;&quot;<br>&nbsp;&nbsp;&nbsp; echo &quot;You must be in GRASS to launch this script&quot;<br>&nbsp;&nbsp;&nbsp; echo &quot;&quot;<br>&nbsp;&nbsp;&nbsp; exit 1<br>fi<br>eval `g.gisenv`<br>: ${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?}
<br>#verification of the presence of v.out.ascii.db<br>if [ ! -e &quot;/usr/lib/grass/scripts/v.out.ascii.db&quot; ] ; then<br>&nbsp;&nbsp;&nbsp; echo &quot;You need the Add on v.out.ascii.db&quot;<br>&nbsp;&nbsp;&nbsp; echo &quot; Segmentation process exit&quot;
<br>&nbsp;&nbsp;&nbsp; exit<br>fi<br><br><br>#verification of the presence of v.append<br>if [ ! -e &quot;/usr/lib/grass/scripts/v.append&quot; ] ; then<br>&nbsp;&nbsp;&nbsp; echo &quot;You need the Add on v.append&nbsp; &quot;<br>&nbsp;&nbsp;&nbsp; echo &quot; Segmentation process exit&quot;
<br>&nbsp;&nbsp;&nbsp; exit<br>fi<br><br># ask the mapset where the user want to work<br>while test ! $Seg_mapset<br>&nbsp;&nbsp;&nbsp;&nbsp; do<br>&nbsp;&nbsp;&nbsp;&nbsp; echo&nbsp; -n &quot; Name of the mapset for the work : &quot;<br>&nbsp;&nbsp;&nbsp;&nbsp; read Seg_mapset<br>&nbsp;&nbsp;&nbsp;&nbsp; done<br><br>while test ! -d &quot;$GISDBASE/$LOCATION_NAME/$Seg_mapset&quot; 
<br>do<br>&nbsp;&nbsp;&nbsp; echo &quot;&quot;<br>&nbsp;&nbsp;&nbsp; echo &quot; the mapset $Seg_mapset doesn't exist!&quot;<br>&nbsp;&nbsp;&nbsp; echo &quot;&quot;<br>&nbsp;&nbsp;&nbsp; echo &quot; Choose an another name&quot;<br>&nbsp;&nbsp;&nbsp; read Seg_mapset<br>done<br><br>g.gisenv set=&quot;MAPSET=$Seg_mapset&quot;
<br>echo &quot; We work now in the mapset $Seg_mapset&quot;<br>echo &quot;&quot;<br><br><br>echo &quot;enter the name of the vector line: &quot;<br>read rh<br>#we verify the presence of this vector<br>g.findfile element=vector file=&quot;${rh}&quot; &gt; /dev/null
<br>&nbsp;&nbsp;&nbsp; if [ $? -ne 0 ] ; then<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; echo &quot;The object $rh doesn't exist !!&quot;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; echo &quot;Segmentation process exit&quot;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; exit<br>&nbsp;&nbsp;&nbsp; fi<br># we verify the type (line) of this vector<br><a href="http://v.info">
v.info</a> map=$rh | grep &quot;lines:&quot; | cut -c30 &gt; /tmp/line<br>lines=`cat /tmp/line`<br>&nbsp;&nbsp;&nbsp; if [ &quot;$lines&quot; = &quot;0&quot; ] ; then<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; echo &quot;The Object $rh doesn't have any lines !!&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; echo &quot;Segmentation process exit&quot;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; exit<br>&nbsp;&nbsp;&nbsp; fi<br><br><br>echo &quot; &quot;<br>echo &quot;The vector line choosen is $rh&quot;<br>echo &quot;&quot;<br>echo &quot;enter the name of the points vector : &quot;
<br>read exut<br>#we verify the presence of this vector<br>g.findfile element=vector file=&quot;${exut}&quot; &gt; /dev/null<br>&nbsp;&nbsp;&nbsp; if [ $? -ne 0 ] ; then<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; echo &quot;The Object $exut doesn't exist !!&quot;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; echo &quot;Segmentation process exit&quot;
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; exit<br>&nbsp;&nbsp;&nbsp; fi<br># we verify the type (point) of this vector<br><a href="http://v.info">v.info</a> map=$exut | grep &quot;points:&quot; | cut -c30 &gt; /tmp/pt<br>pts=`cat /tmp/pt`<br>&nbsp;&nbsp;&nbsp; if [ &quot;$pts&quot; = &quot;0&quot; ] ; then
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; echo &quot;The Object $exut doesn't have any points!!&quot;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; echo &quot;Segmentation process exit&quot;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; exit<br>&nbsp;&nbsp;&nbsp; fi<br>rm /tmp/line<br>rm /tmp/pt<br><br>echo &quot;The vector point choosen is $exut&quot;
<br>echo &quot;&quot;<br>echo &quot;enter a name for the new vector line: &quot;<br><br>while test ! $rhfin<br>&nbsp;&nbsp;&nbsp;&nbsp; do<br>&nbsp;&nbsp;&nbsp;&nbsp; echo&nbsp; -n &quot;Enter the name: &quot;<br>&nbsp;&nbsp;&nbsp;&nbsp; read rhfin<br>&nbsp;&nbsp;&nbsp;&nbsp; done<br><br>while test -d &quot;$GISDBASE/$LOCATION_NAME/$MAPSET/vector/$rhfin&quot; 
<br>do<br>&nbsp;&nbsp;&nbsp; echo &quot;&quot;<br>&nbsp;&nbsp;&nbsp; echo &quot; The Object $rhfin already&nbsp;exist&quot;<br>&nbsp;&nbsp;&nbsp; echo &quot;&quot;<br>&nbsp;&nbsp;&nbsp; echo &quot; Choose an another name&quot;<br>&nbsp;&nbsp;&nbsp; read rhfin<br>done<br><br><br><br>echo &quot;the name for the new vector line is $rhfin&quot;
<br>echo &quot; &quot;<br>echo &quot;***************&quot;<br>echo &quot;add the columns lcat,along,x and y in the vector points&quot;<br>echo &quot;and calcul of the x,y coordinate of these points&quot;<br>echo &quot;ALTER TABLE $exut ADD COLUMN lcat INTEGER&quot;|db.execute
<br>echo &quot;ALTER TABLE $exut ADD COLUMN along DOUBLE&quot;|db.execute<br>echo &quot;ALTER TABLE $exut ADD COLUMN x DOUBLE&quot;|db.execute<br>echo &quot;ALTER TABLE $exut ADD COLUMN y DOUBLE&quot;|db.execute<br><br>v.to.db
 map=$exut type=point option=coor units=me column=x,y<br><br>echo &quot; &quot;<br>echo &quot;***************&quot;<br>echo &quot;calcul of the distance between vector line and vector point&quot;<br>#allow to calculate the cat of the line where the point is
<br>v.distance from=$exut to=$rh from_type=point to_type=line upload=cat column=lcat<br>#allow to find the distance entre the beginning of the line and the point<br>v.distance from=$exut to=$rh from_type=point to_type=line upload=to_along column=along
<br><br>echo &quot; &quot;<br>echo &quot;***************&quot;<br>echo &quot;export of the cat of the selected lines&quot;<br><br>v.out.ascii.db input=$exut output=/tmp/segcat columns=lcat<br><br>cut -d&quot;|&quot; -f4 /tmp/segcat&gt;/tmp/segcat2
<br><br>echo &quot; &quot;<br>echo &quot;***************&quot;<br>echo &quot;extract of the selected lines&quot;<br><br>v.extract input=rh output=rh2 type=line file=/tmp/segcat2<br><br>echo &quot; &quot;<br>echo &quot;***************&quot;
<br>echo &quot;export of the points of the selected lines&quot;<br>echo &quot;and calcul of the distance between the beginning of the line and the point, result in layer 2&quot;<br>v.to.points input=rh2 type=line output=rh3
<br><br>echo &quot; &quot;<br>echo &quot;***************&quot;<br>echo &quot;calcul of the x,y coordinate of the points&quot;<br>echo &quot;ALTER TABLE rh3_2 ADD COLUMN x DOUBLE&quot;|db.execute<br>echo &quot;ALTER TABLE rh3_2 ADD COLUMN y DOUBLE&quot;|db.execute
<br>v.to.db map=rh3 type=point layer=2 option=coor units=me column=x,y<br><br>echo &quot; &quot;<br>echo &quot;***************&quot;<br>echo &quot;creation of the column type&quot;<br>echo &quot;ALTER TABLE rh3_2 ADD COLUMN type VARCHAR(10)&quot;|db.execute
<br>echo &quot;ALTER TABLE $exut ADD COLUMN type VARCHAR(10)&quot;|db.execute<br>echo &quot;UPDATE rh3_2 SET type='rh'&quot;|db.execute<br>echo &quot;UPDATE $exut SET type='exut'&quot;|db.execute<br><br>echo &quot; &quot;
<br>echo &quot;***************&quot;<br>echo &quot;export the attributes of the points of&nbsp; lines and of the points&quot;<br>#segcat3: fichier contenant points et attributs des segments rh3<br>db.select -c table=rh3_2&gt;/tmp/segcat3
<br>db.select -c table=$exut&gt;/tmp/segcat4<br>echo &quot;we suppress an esri column &quot;<br>cut -d&quot;|&quot; -f1,3,4,5,6,7 /tmp/segcat4&gt;/tmp/segcat5<br><br><br>echo &quot; &quot;<br>echo &quot;***************&quot;
<br>echo &quot;sum of all the points&quot;<br><br>sort -k2n -t'|' /tmp/segcat3 &gt;/tmp/segcat30<br><br>sort -k2n -t'|' /tmp/segcat5 &gt;/tmp/segcat50<br><br>sort -m -k2n -k3g -t'|' /tmp/segcat30 /tmp/segcat50&gt;/tmp/segcat6
<br><br>cut -d&quot;|&quot; -f2 /tmp/segcat6&gt;/tmp/segcat7<br>uniq /tmp/segcat7&gt;/tmp/segcat8<br><br><br>cut -d&quot;|&quot; -f2,3,4,5,6 /tmp/segcat6&gt;/tmp/segcat9<br><br><br>echo &quot; &quot;<br>echo &quot;***************&quot;
<br>echo &quot;creation of the ascii input file for the creation of the new vector line&quot;<br><br>&nbsp;for k in `cat /tmp/segcat8`;do<br>&nbsp;&nbsp;&nbsp; grep &quot;^$k&quot; /tmp/segcat9 &gt; /tmp/segcat10_&quot;$k&quot;<br>&nbsp;&nbsp;&nbsp; grep -n exut$ /tmp/segcat10_&quot;$k&quot; |cut -d&quot;:&quot; -f1 &gt; /tmp/segcat11_&quot;$k&quot;
<br>&nbsp;&nbsp;&nbsp; typeset -i nb<br>&nbsp;&nbsp;&nbsp; nb=`cat /tmp/segcat11_&quot;$k&quot;`<br>&nbsp;&nbsp;&nbsp; head -&quot;$nb&quot; /tmp/segcat10_&quot;$k&quot; &gt; /tmp/segcat20_&quot;$k&quot;<br>&nbsp;&nbsp;&nbsp; echo &quot;`cat /tmp/segcat10_&quot;$k&quot;`&quot; | wc -l &gt; /tmp/segcat13_&quot;$k&quot;
<br>&nbsp;&nbsp;&nbsp; typeset -i nbexut<br>&nbsp;&nbsp;&nbsp; nbexut=`cat /tmp/segcat13_&quot;$k&quot;`<br>&nbsp;&nbsp;&nbsp; typeset -i nb2<br>&nbsp;&nbsp;&nbsp; nb2=`cat /tmp/segcat13_&quot;$k&quot;`-`cat /tmp/segcat11_&quot;$k&quot;`+1<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; tail -&quot;$nb2&quot; /tmp/segcat10_&quot;$k&quot; &gt; /tmp/segcat21_&quot;$k&quot;
<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; touch /tmp/import_&quot;$k&quot;<br>&nbsp;&nbsp;&nbsp; echo &quot;`cat /tmp/segcat20_&quot;$k&quot;`&quot; | wc -l &gt; /tmp/segcat30_&quot;$k&quot;<br>&nbsp;&nbsp;&nbsp; nb20=`cat /tmp/segcat30_&quot;$k&quot;`<br>&nbsp;&nbsp;&nbsp; echo &quot;`cat /tmp/segcat21_&quot;$k&quot;`&quot; | wc -l &gt; /tmp/segcat31_&quot;$k&quot;
<br>&nbsp;&nbsp;&nbsp; nb21=`cat /tmp/segcat31_&quot;$k&quot;`<br><br>&nbsp;&nbsp;&nbsp; cut -d'|' -f3,4 /tmp/segcat20_&quot;$k&quot; | awk -F'|' '{OFS=&quot; &quot;;$1=$1;print &quot; &quot;$0}' &gt; /tmp/segcat40_&quot;$k&quot;<br>&nbsp;&nbsp;&nbsp; cut -d'|' -f3,4 /tmp/segcat21_&quot;$k&quot; | awk -F'|' '{OFS=&quot; &quot;;$1=$1;print &quot; &quot;$0}' &gt; /tmp/segcat41_&quot;$k&quot;
<br>&nbsp;&nbsp;&nbsp; echo &quot;L&nbsp; &quot;$nb20&quot; 1&quot; &gt;&gt;/tmp/import_&quot;$k&quot; <br>&nbsp;&nbsp;&nbsp; echo &quot;`cat /tmp/segcat40_&quot;$k&quot;`&quot; &gt;&gt;/tmp/import_&quot;$k&quot; <br>&nbsp;&nbsp;&nbsp; echo &quot; 1 1&quot;&gt;&gt;/tmp/import_&quot;$k&quot;
<br>&nbsp;&nbsp;&nbsp; echo &quot;L&nbsp; &quot;$nb21&quot; 1&quot; &gt;&gt;/tmp/import_&quot;$k&quot; <br>&nbsp;&nbsp;&nbsp; echo &quot;`cat /tmp/segcat41_&quot;$k&quot;`&quot; &gt;&gt;/tmp/import_&quot;$k&quot; <br>&nbsp;&nbsp;&nbsp; echo &quot; 1 2&quot;&gt;&gt;/tmp/import_&quot;$k&quot;
<br><br>&nbsp;done<br>#the file import will be the fileascii input<br>touch /tmp/import<br>&nbsp;&nbsp;&nbsp; echo &quot;ORGANIZATION:&quot; &gt;&gt;/tmp/import<br>&nbsp;&nbsp;&nbsp; echo &quot;DIGIT DATE:&quot; &gt;&gt;/tmp/import<br>&nbsp;&nbsp;&nbsp; echo &quot;DIGIT NAME:&quot; &gt;&gt;/tmp/import
<br>&nbsp;&nbsp;&nbsp; echo &quot;MAP NAME:&quot; &gt;&gt;/tmp/import<br>&nbsp;&nbsp;&nbsp; echo &quot;MAP DATE:&quot; &gt;&gt;/tmp/import<br>&nbsp;&nbsp;&nbsp; echo &quot;MAP SCALE:&quot; &gt;&gt;/tmp/import<br>&nbsp;&nbsp;&nbsp; echo &quot;OTHER INFO:&quot; &gt;&gt;/tmp/import<br>
&nbsp;&nbsp;&nbsp; echo &quot;ZONE:&quot; &gt;&gt;/tmp/import<br>&nbsp;&nbsp;&nbsp; echo &quot;MAP THRESH:&quot; &gt;&gt;/tmp/import<br>&nbsp;&nbsp;&nbsp; echo &quot;VERTI:&quot; &gt;&gt;/tmp/import <br>&nbsp;&nbsp;&nbsp; for k in `cat /tmp/segcat8`;do<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; echo &quot;`cat /tmp/import_&quot;$k&quot;`&quot; &gt;&gt;/tmp/import
<br>&nbsp;&nbsp;&nbsp; done<br>&nbsp;rm /tmp/import_*<br>&nbsp;<br><br>echo &quot; &quot;<br>echo &quot;***************&quot;<br>echo &quot;creation of the vector line $rhfin &quot;<br><br>v.in.ascii input=/tmp/import output=&quot;$rh&quot;_tmp format=standard 
<br>v.category input=$rh option=print &gt; /tmp/cattot<br>sort -k1n /tmp/segcat8 &gt; /tmp/segcat8s<br>diff /tmp/cattot /tmp/segcat8s &gt; /tmp/cattot2<br>grep -v &quot;,&quot; /tmp/cattot2 &gt; /tmp/cattot3<br>cut -d&quot; &quot; -f2 /tmp/cattot3 &gt; /tmp/cattot4
<br>v.extract input=$rh output=ext_$rh type=line file=/tmp/cattot4<br><br>rm /tmp/import<br>rm /tmp/cattot*<br><br><br><br>echo &quot;`cat /tmp/segcat8s`&quot;| awk -F'|' '{ORS=&quot;) or (cat=&quot;;$1=$1;print $0}' &gt; /tmp/segwhere
<br>awk '{print NF}' /tmp/segwhere &gt; /tmp/segwherenb<br>typeset -i nbwhere<br>nbwhere=`cat /tmp/segwherenb`-2<br>cut -d&quot; &quot; -f1-&quot;$nbwhere&quot; /tmp/segwhere &gt; /tmp/segwhere2<br><br>db.copy from_driver=dbf from_database=&quot;$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/&quot; from_table=&quot;$rh&quot; to_driver=dbf to_database=&quot;$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/&quot; to_table=&quot;$rh&quot;_tmp where=&quot;(cat=`cat /tmp/segwhere2`&quot;
<br>v.db.connect map=&quot;$rh&quot;_tmp driver=dbf database=&quot;$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/&quot; table=&quot;$rh&quot;_tmp key=cat layer=1<br><br>v.category input=&quot;$rh&quot;_tmp output=&quot;$rh&quot;_tmp2 type=line option=del
<br>v.category input=&quot;$rh&quot;_tmp2 output=&quot;$rh&quot;_tmp3 type=line option=add<br>#utilisation du module v.append pour merger les deux rĂ&copy;seaux <br>v.append vect1=&quot;$rh&quot;_tmp3 vect2=ext_$rh vmerged=$rhfin vtype=line vlayer=1
<br><br>rm /tmp/seg*<br>g.remove vect=rh3,rh2,ext_$rh,&quot;$rh&quot;_tmp,&quot;$rh&quot;_tmp2,&quot;$rh&quot;_tmp3<br>echo &quot; &quot;<br>echo &quot;***************&quot;<br>echo &quot;Segmentation process end&quot;<br>
<br>