Reclass problem

Angus Carr apcarr at FLASH.LakeheadU.CA
Tue Apr 1 18:34:03 EST 1997


Use a random number generator to generate a random map (using head -6 to
trim the top header section of an existing map coming out of r.out.ascii
and then catting them together) of values from one to three. Use an
r.mapcalc statement to create the result map
for example, assuming a 3 x 3 map, and bash shell:

r.out.ascii oldmap | head -6 > randmap
for augh in 1 2 3 4 5 6 7 8 9 ; do random 1 3 >> randmap ; done
r.in.ascii i=randmap o=random_now_in_grass
r.mapcalc "redone=if(oldmap==21,120+randmap,oldmap)"

The product is the contents of oldmap where oldmap != 21 , else 121-123
(the three new classes).

The program random is:

================
#include <stdio.h>
#include <stdlib.h>
#ifndef RAND_MAX
#define RAND_MAX 2147483647
#endif
 
void main(int argc,char *argv[])
{
int top,bottom,range;
top=atoi(argv[2]);
bottom=atoi(argv[1]);
range=top-bottom;
if (range < 0) range = 0-range;
printf("%d ",(int) ((rand() / RAND_MAX * range ) + bottom ) );
}  

This program (completely untested) will read a pair of numbers from the
command line and spit out a random number between the two (inclusive).
You could, of course, write an analagous GRASS program. It wouldn't be
hard.

Good luck. If it doesn't work, have a few kicks at it then give me a call.

Angus Carr,
Masters of Forestry student


On Tue, 1 Apr 1997, Michael Hanratty wrote:

> Fellow GRASS user,
> 
> I have the following raster file that I'd like to reclassify.
> 
> Mapset <washita> in Location <utm14>
> GRASS 4.1 > r.cats map=lulc
> Reading lulc in washita ... 100%
> 0       no data
> 11      urbn
> 12      urbn
> 13      urbn
> 14      urbn
> 16      urbn
> 17      urbn
> 21      past:swht:hay
> 24      agrl
> 31      rnge
> 32      rngb
> 33      rnge
> 41      frsd
> 43      frst
> 53      watr
> 75
> 76
> 
> What I would like to do is to split the areas with category 21 (past:swht:hay) 
> into three categories of equal area.  For example, if category 21 covers 30 
> sq.km., I'd like to divide that area in any manner that is convenient so that I 
> have 10 sq.km. of area with category past, 10 sq.km of area with category swht, 
> and 10 sq.km. of area with category hay.  
> 
> Does anyone have a suggestion for how to do this?  I'd like a procedure that I 
> can automate so that I can apply it to a number of masked regions within a 
> raster layer.
> 
> Thanks.
> Mike
> 
> 
> 
> Michael Hanratty                           Phone: (612) 627-4590
> St. Anthony Falls Laboratory               Fax: (612) 627-4609
> Dept. of Civil Engineering
> University of Minnesota
> Mississippi River @ 3rd Ave. SE
> Minneapolis, MN 55414
> 
> 



More information about the grass-user mailing list