[GRASSLIST:1525] Re: Area in multi GRID

Hamish hamish_nospam at yahoo.com
Mon Oct 20 19:18:02 EDT 2003


> I have a raster map. I have overlaid a grid of 1/2 degree x 1/2
> degree on my raster map with v.mkgrid. In order to find the
> area, number of cells and categories for a single grid, I
> changed the region settings as g.region rast=raster_map
> n=NORTH, s=SOUTH, w=WEST, e=EAST with that single grid in the
> area of interest with north, south, east, west boundary. then I
> used r.report to to find the number of pixels, categories,
> percentage and their area for a single GRID.
> Now what to do if the map has more than 200 grids and I need to
> calculate the area, number of pixels, number of categories in each
> grid ??? Manual work of doing the region settings for each grid would
> take a long time and a tedious work.


> > A way this could be done is with a bash script, e.g.:
...

I'm not sure how to do floating point math within a bash script. I'd use
matlab/octave to do this.. Python or some other scripting language might 
make this easy, or there may be a UNIX tool for floating point math.
I don't really know. For whole number math use something like 
"EAST=`expr 100+1`" or "EAST=$((100+1))" in bash.


general idea (nonfunctional):
Say for 1/2 degree boxes, starting at 100E,45N moving southeast to 120E,30N.


#script
BOX=0			# counter
SOUTH=45.0		# init for first box
WEST=100.0

g.region rast=raster_map   # (for resolution)

while($SOUTH > 30.0) ; do
   NORTH=$SOUTH		# values from last box
   SOUTH=(($NORTH - 0.5))

   while($EAST < 120.0) ; do
       BOX=$(($BOX + 1))
       WEST=$EAST
       EAST=(($WEST + 0.5))

       g.region n=$NORTH s=$SOUTH w=$WEST e=$EAST
       r.stats <options>  > box"$BOX"_"$NORTH"_"$WEST".txt
   done
done


or something like that.


Hamish




More information about the grass-user mailing list