[GRASS-user] Speeding up bash script

Maciej Sieczka tutey at o2.pl
Thu Aug 28 06:03:04 EDT 2008

Wesley Roberts pisze:

> 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.


Each db.execute call is expensive (v.db.update is a wrapper for db.execute).

Remove v.db.update from the loop. Replace it with a command that
will create corresponding SQL statements, and store them in a text file.

Outside the loop pipe the file into db.execute. This will do the whole
update in one run. Should save plenty of time. There's an example in
db.execute manual.

You can also use "v.univar -g" - shell script output style. It is easier
to parse. Thus instead:

  v.univar map=b_sam_$x type=point column=dbl_5 layer=1 > temp_file
  a=`sed -n '5p' temp_file | awk '{print $2}'

you can put:

  eval `v.univar -g map=b_sam_$x type=point column=dbl_5 layer=1`

and then variable 'max' automagically stores your maximum value.


Maciej Sieczka

More information about the grass-user mailing list