[GRASS-user] points in polygon query
hamish_nospam at yahoo.com
Mon May 21 03:39:38 EDT 2007
Stefano Costa wrote:
> Scrive Dylan Beaudette <dylan.beaudette at gmail.com>:
> > This sounds like a form of quadrat counting
> Last night I wrote this script that does the job. Quite slow, but
> works. http://grass.gdf-hannover.de/wiki/V.count.points
> 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.
> 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.
G63> g.copy v=bugsites,local_bugs
G63> db.select local_bugs | grep -c $i
G63> db.select local_bugs | grep -c "^$i|"
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.
More information about the grass-user