[GRASSLIST:425] Re: a huge matrix ?

Glynn Clements glynn.clements at virgin.net
Wed Jun 18 02:37:50 EDT 2003


orkun wrote:


> > OK, so: each line is a rule; for each pixel you scan the list of rules
> > to find the first match, then output the associated result. Right?
> > 
> > The most straightforward approach (although not particularly
> > efficient), would be to use an iterative approach, i.e.
> > 
> > 	n=0
> > 	last='null()'
> > 	while read a1 a2 a3 a4 a5 a6 a7 a8 ; do
> > 		result=pr2.pass$n
> > 		r.mapcalc "$result = if (f28geo5==$a1 && f28slpcat==$a2 && f28concavity==$a3 && n_facing==$a4 && road_bas==$a5 &&str_buf==$a6 && f28f4==$a7, $a8, $last)"
> > 		last=$result
> > 	done < rules.txt
> > 
> > where rules.txt looks like:
> > 
> > 	21 6 1 1 1 1 0 701.22
> > 	 7 4 2 1 1 2 1 702.06
> > 	...

> Firstly I intend to try your iterative way.
> In that,  doesn't n have any increament ?
> something like n=n+1 in the loop.

Yes; I had missed out a line; in bash, you can use:

	n=$((n + 1))

In shells which don't have built-in arithmetic, you can use "expr",
e.g.

	n=`expr $n + 1`

> If so,Doesn't  it mean creating a new map - totally 10500 map-  in every 
> iteration

Yes. However, you only need to keep the last map; the rest can be
removed, e.g.

	if [ $n -ge 2 ] ; then
		g.remove rast=pr2.pass$((n - 2))
	fi

-- 
Glynn Clements <glynn.clements at virgin.net>




More information about the grass-user mailing list