[GRASS-user] Speeding up bash script

Wesley Roberts wroberts at csir.co.za
Thu Aug 28 05:24:27 EDT 2008

Dear Grass'ers

I have written a bash script to extract the maximum LiDAR height value within a predefined sample site (Vector with 314 sample locations each 10m squared). The script is below. Essentially I use v.extract to select one of my 314 sample sites (Flight_sample2). This temporary vector is then used to select all LiDAR points falling within its boundaries using v.select. Following this I use v.univar to calculate summary statistics of the points selected which is then written to temp_file. sed and awk are then used to extract the maximum height value which is then used to update (v.db.update) the original flight sample file. The script does exactly what it is suppose to do and I am chuffed with the result, however, it does take an enormous amount of time. For my largest area, over 200 samples it took almost two whole days (running non-stop) to complete the task. I may need to calculate additional summary statistics at a later date and would like to speed up the operation.

Can anyone suggest a faster way to do this? I am a 'noob' when it comes to bash scripts and programming in general so any additional help would be greatly appreciated. Additionally, I am using the dbf driver.

Many thanks


while [ $x -le 284 ]
	v.extract input=Flight_sample2 at Work output=sam_$x type=area layer=1 new=-1 where=SAM=$x --overwrite
	v.select ainput=AreaThreeCanopy_ROI at Work atype=point alayer=1 binput=sam_$x btype=area blayer=1 output=b_sam_$x operator=overlap --overwrite
	v.univar map=b_sam_$x type=point column=dbl_5 layer=1 > temp_file
	a=`sed -n '5p' temp_file | awk '{print $2}'`
	echo "$x"
	echo "Maximum Lidar point height for this sample location sam_$x is: $a"
	v.db.update map=Flight_sample2 layer=1 column=mx_LR value=$a where=SAM=$x
	g.remove vect=b_sam_$x,sam_$x
	echo "Sample $x from area One has now been processed"
	x=$(( $x + 1 ))


This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. 
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.  MailScanner thanks Transtec Computers for their support.

More information about the grass-user mailing list