[GRASS-user] points in polygon query

Stefano Costa steko at iosa.it
Mon May 21 04:37:30 EDT 2007

Il giorno lun, 21/05/2007 alle 19.39 +1200, Hamish ha scritto:
> > echo "UPDATE $output SET count = $count WHERE cat = $i" | db.execute
> instead of running db.execute at every iteration in your loop, >> append
> the SQL command to a g.tempfile (end each line with a ';'), then once
> the for loops are done, run db.execute once with the input=$tempfile.
> then the script will be much much faster I think.

Thanks Hamish,
I'm going to edit the script following your advice. 

> > for i in $areas; do
> >    count=$( db.select -c points_tmp sql="select cat_area from points_tmp" | grep -c $i)
> You might want to make the ending "grep -c $i" a bit more specific,
> as you don't want to count "10,11,Site 1" in a where="cat = 1" grep count.
> As written it could lead to buggy results.
> for example:
> G63> g.copy v=bugsites,local_bugs
> G63> i=1
> G63> db.select local_bugs | grep -c $i
> 19
> G63> db.select local_bugs | grep -c "^$i|"
> 1

Newbie errors... !

> also if you save the output of db.select to a temp file you don't need
> to run the process for every step in the loop, as it doesn't change.
> Maybe a bit faster that way- move as much repeated static operations
> as possible out of loops.

Thanks again, I hope this ugly script can turn into something useful
with your help and that of all GRASS users.

Best regards,

Stefano Costa
steko at jabber.linux.it
http://www.iosa.it Archeologia e Software Libero
Io uso Debian GNU/Linux!

More information about the grass-user mailing list