[GRASS-dev] Re: [GRASSLIST:962] Re: GRASS and vector lines: how can I change the direction of digitized lines?

Hamish hamish_nospam at yahoo.com
Sun May 14 23:29:03 EDT 2006


Hi, 

some hints follow,


> I've been looking for this functionality too. Following Markus
> suggestion, I have written a script to flip directions of selected
> Grass line vectors, all done within Grass.
> 
> This is my first ehm full-blown Grass script. I will be very gratefull
> for any comments and guiding on how to improve it.
> 
> I'm especially interested in the following:
> 
> 1. Is there another way to safely create temporary vector files than I
> do (ie. use a likely unique name, check if it doesn't exist yet in the
> mapset, proceed if not, else stop and issue a warning).

you are already using g.tempfile + success tests correctly.


> 2. I use "v.clean tool=snap thresh=0.01" to re-connect the flipped and
> the remaining original lines. Is it 100% robust? No risk that some
> won't be connected?

If anything I would make thresh much smaller so that no new lines are
snapped. The coordinates should not be changed unless you did printf %f
from awk (shortens decimal precision, use %s to output full input string
instead of proccessing as a number). So snapping should be exact.


eval `g.findfile element=vector file="$INPUT"`
    if [ ! "$file" ] ; then

can be shortened, g.findfile returns 1 if the file wasn't found.
see r.blend:
http://freegis.org/cgi-bin/viewcvs.cgi/grass6/scripts/r.blend/r.blend?rev=HEAD


just leave those tests out for input= and output=, g.parser checks
that maps do/don't exist given the rules in "#% gisprompt :",
--overwrite, etc.


Call temporary maps like tmp_vflip_$$_toflip:
tmp_${PROG} makes it easy to spot orphans, $$ gives it a 1 in 32k chance
of being unique.


It is easier to read, if instead of

output=$OUTPUT"_toflip"
  you do
output=${OUTPUT}_toflip
  or
output="${OUTPUT}_toflip"


you probably want to use "sort -n" instead of "sort" so you don't get
1
13
2
20
etc.


asis=`cat $TMP.cat_asis`
asis=`echo $asis | sed 's/ /,/g'`
probably hit the limitied size cap for a shell variable? (4096 chars?)
Use a tmp file.



for a in $start_stop
do
..
done

make it easier to follow by indenting the inner part of the loop by a
few spaces.



see also v.out.ascii.db (wiki add-ons) and v.in.garmin (complex awk+tac
vector ascii format flipping to count vertices) scripts.



Hamish




More information about the grass-dev mailing list