[GRASS-user] intersect vector line by vector point

Michaël Rabotin michaelrabotin at gmail.com
Mon Oct 16 04:44:23 EDT 2006


Hi everybody,
in precedent mails , I ask for split polyline vector with a point vector to
create a new polyline vector.
I wrote a little shell bash to resolve the problem (this script is not yet
finish). Be tolerant, I'm a newbie in GRASS and linux script; there are no
warning (no verification of the input layer...) in the script, I've not
finished the end. I post you this script to have any suggestion of the way I
choose to solve my problem, so take a look and If you have any ideas to
improve my script don't hesitate to post me a message


#!/bin/bash
#launch this script on GRASS
#job of this script: split polylines with a vector of points
#and create a new polylines vector
#use of GRASS Add on: v.out.ascii.db
mkdir $HOME/provseg/ #temporary datafile created
echo "enter the name of the polylines vector "
read rh
echo " "
echo "the choosen polyline vector is $rh"
#the point vector was an esri shapefile with only one column which will be
delete in the middle of the script
echo "enter the name of the points vector : "
read exut
echo "the choosen point vector is $exut"
echo " enter a name for the new polyline vector : "
read rhfin
echo "the name of the new polyline vector will be : $rhfin"
echo " "
echo "***************"
echo "add columns lcat, along, x and y to the points vector"
echo " and calcul of x y coordinates of the points vector"
echo "ALTER TABLE $exut ADD COLUMN lcat INTEGER"|db.execute
echo "ALTER TABLE $exut ADD COLUMN along DOUBLE"|db.execute
echo "ALTER TABLE $exut ADD COLUMN x DOUBLE"|db.execute
echo "ALTER TABLE $exut ADD COLUMN y DOUBLE"|db.execute
#calcul of x y coordinates of the points vector
v.to.db map=$exut type=point option=coor units=me column=x,y
echo " "
echo "***************"
echo "distance calculation beetween polyline vector and points vector"
#find the cat number of the segment where the point is on
v.distance from=$exut to=$rh from_type=point to_type=line upload=cat
column=lcat
#find the distance beetween the beginning of the segment and the point
v.distance from=$exut to=$rh from_type=point to_type=line upload=to_along
column=along
echo " "
echo "***************"
echo "export of the cat of the segments"
#segcat file with points attributs:x,y,cat of the segment
v.out.ascii.db input=$exut output=$HOME/provseg/segcat columns=lcat
#segcat2 file with only cat of the segment
cut -d"|" -f4 $HOME/provseg/segcat>$HOME/provseg/segcat2
echo " "
echo "***************"
echo "extraction of the selected segments"
#extraction from rh to rh2 of the selected segment with the list of the cat
in segcat2
v.extract input=rh output=rh2 type=line file=$HOME/provseg/segcat2
echo " "
echo "***************"
echo "export of the point of the segment"
echo "and calcul of the distance beetween these points and the beginning of
the segment; results in layer 2"
#export of these points from rh2 to rh3
v.to.points input=rh2 type=line output=rh3
echo " "
echo "***************"
echo "calcul of the x,y coordinate of these points"
echo "ALTER TABLE rh3_2 ADD COLUMN x DOUBLE"|db.execute
echo "ALTER TABLE rh3_2 ADD COLUMN y DOUBLE"|db.execute
#calcul of the x y coordinate
v.to.db map=rh3 type=point layer=2 option=coor units=me column=x,y
echo " "
echo "***************"
echo "creation of a column TYPE in the vectors points"
echo "ALTER TABLE rh3_2 ADD COLUMN type VARCHAR(10)"|db.execute
echo "ALTER TABLE $exut ADD COLUMN type VARCHAR(10)"|db.execute
#in rh3, TYPE has the valor: rh
echo "UPDATE rh3_2 SET type='rh'"|db.execute
#in $exut, TYPE has the valor: exut
echo "UPDATE $exut SET type='exut'"|db.execute
echo " "
echo "***************"
echo "export of the points attributs of rh3 and exut
#segcat3 file has points and attributs of rh3
db.select -c table=rh3_2>$HOME/provseg/segcat3
#segcat4 file has points and attributs of exut
db.select -c table=pt_exut>$HOME/provseg/segcat4
#in segcat5 file we deletes the esri shp column of exut
cut -d"|" -f1,3,4,5,6,7 $HOME/provseg/segcat4>$HOME/provseg/segcat5
#kill segcat4
rm $HOME/provseg/segcat4
echo " "
echo "***************"
echo "merge all the points of rh and exut"
#sort segcat3 file by cat ; creation of segcat30
sort -k2n -t'|' $HOME/provseg/segcat3 >$HOME/provseg/segcat30
#sort segcat5 file by cat ; cretion of segcat50
sort -k2n -t'|' $HOME/provseg/segcat5 >$HOME/provseg/segcat50
#sort an merge segcat30 and segcat50 by cat and after by distance ; creation
of segcat6
sort -m -k2n -k3g -t'|' $HOME/provseg/segcat30
$HOME/provseg/segcat50>$HOME/provseg/segcat6
#kill segcat30 and segcat50
rm $HOME/provseg/segcat30
rm $HOME/provseg/segcat50
#delete the first column (cat of the points) in segcat6 ; creation of
segcat9
cut -d"|" -f2,3,4,5,6 $HOME/provseg/segcat6>$HOME/provseg/segcat9
#kill segcat6
#the next line ar suggestions of the way I want to choose to finish
#???????????????????????????????????????
#???????????????????????????????????????
#creation of the input ascii file for the creation of the new polyline
vector"
#in the old vector file, we must delete the selected segment
#merge the new and th old polyline vector together, build topology
#kill the temporary files

Cheers
Mick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/grass-user/attachments/20061016/a6022af0/attachment.html


More information about the grass-user mailing list