[GRASS-user] points in polygon query

Maciej Sieczka tutey at o2.pl
Tue May 22 14:45:32 EDT 2007

Stefano Costa wrote:
> Il giorno lun, 21/05/2007 alle 20.41 +0200, Maciej Sieczka ha scritto:
>> Last time I checked that it was circa 20 (twenty) times faster for me.
>> Sorry no exact benchmarks.
> Hi Maciek,
> are you talking about my specific script?

No. I was talking in general. I had an issue with slow db.execute in my
v.breach script. You can download it from GRASS AddOns WIKI site. Below
is the relevant fragment for inspiration. I don't see a reason why in
your case a similar solution should not yield a similar speedup. Even
if it was "only" say 3 faster it's still worth it.

The whole big idea is to take the db.execute out of the loop, collect
all SQL commands within this loop into a text file and then feed the
file into "db.execute input=" in the end, which executes all your SQL
commands in one run.


# upload breached Z into the table

tbl=`v.db.connect -g "${OUTP}" | awk '{print $2}'`
dbs=`v.db.connect -g "${OUTP}" | awk '{print $4}'`
drv=`v.db.connect -g "${OUTP}" | awk '{print $5}'`

# upload SQL commands into txt file first = ~20 times faster db.execute

for z in `awk -v DPTH="$DPTH" '{printf "%f ",$5-DPTH}' \
$TMP.${PROG}.input`; do

 row=`expr $row + 1`
 echo "UPDATE $tbl SET z_breach=$z WHERE cat=$row;" >> $TMP.${PROG}.sql


db.execute input=$TMP.${PROG}.sql database=$dbs driver=$drv > /dev/null



More information about the grass-user mailing list