classy reclassing

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

classy reclassing

Nancy Greeley
Heyo...

I have just reclassed 822 categories into 8 categories using what I would
call the, uhm, hard way.  That is, I used the reclass command and manually
changed 822 numbers.  I kept saying to myself...there has to be a better
way, there has to be a better way...

Is there a better way?

(The PI just told me he thinks it would be much better to have 14 categories...

 /*   *\
    <
    ~         )

Details: the data, in this case, is elevation data.  Each category in the
original map layer is 1 meter.

Thanks for your help (and sympathy, where appropriate).

Reply | Threaded
Open this post in threaded view
|

Re: classy reclassing

Joyce Mechling Nagle
You seem to have discovered the method I use to as I keep saying to myself:
"there has to be a better
way, there has to be a better way..."

The pi will probably want something different later.  Be thankful it is only
822 categories and not more!!!

Hey there were some questions about TEK plotters in the grassu-list
today.  You and Gregor should know the answers!

Toodles - Joyce

Reply | Threaded
Open this post in threaded view
|

Re: classy reclassing

John E. Parks
In reply to this post by Nancy Greeley
] I have just reclassed 822 categories into 8 categories using what I would
] call the, uhm, hard way.  That is, I used the reclass command and manually
] changed 822 numbers.  I kept saying to myself...there has to be a better
] way, there has to be a better way...
]
] Is there a better way?

A couple of suggestions...

1) if you're reclassing the elevation models into equal intervals, use
   r.rescale.
2) if you're not, you can run r.reclass from command line and enter rules
   for the reclass.  i.e....
   # r.reclass input=elevation output=new_elevation
   > 0 thru 5 = 0
   > 6 thru 20 = 1
   > 21 thru 45 = 2
   > 46 = 3
   > 47 thru 1000 = 4
   > end
   #

Regards,

    __                   __
   /  )      /          /  )     Research Specialist
  /   / _   /_  _      /__/      Ctr for Advanced Spatial Technologies
  (__/_(_)_/ /_/ )_   /   _      National Ctr for Resource Innovations
    /                            12 Ozark Hall, Univ. of Arkansas
   /                             Fayetteville, AR  72701
John E. Parks                    phone: (501) 575-6159
[[hidden email]] Internet    or: (501) 575-4575

Reply | Threaded
Open this post in threaded view
|

Re: classy reclassing

Greg Koerper-7
In reply to this post by Nancy Greeley

Here's a simple shell script that is helpful for streamlining the r.reclass
command when applied to continuous variables.  It labels the reclass
categories, which simplifies legend display.  It has an offset option that
allows for manipulation of negative values.  If you use the -N flag, you can
quickly ascertain how it builds reclass rules.  We've used it for post-
processing of model output of continuous variables associated with sites.

-------------------------------shell script ---------------------------------
#! /bin/sh

# reclass.sh takes a single line of input which specifies the beginning
#   range of each of a series of range intervals that are then passed to
#   r.reclass as input.  The units_abbrev is helpful in outputting a legend.
#   Use offset if the cell file data are all positive but in fact may represent
#   negative values (useful in avoiding "no data" designations for real 0
#   values).

# comments, concerns to [hidden email]

# if -N flag, raster is not created and input to r.reclass is
#  stored under given file_name

# if -c flag, next argument specifies color rules for reclassification
#  see r.colors (incompatible with -N)

USAGE="$0 [-N | -c color_rules] file units_abbrev [offset] [< input]"
RASTER="YES"
COLORS=''

if [ $# -eq 0 -o $# -gt 5 ]
then
        echo $USAGE
        exit -1
fi

# continue only if user is executing GRASS

if [ "$GISRC" = "" ]
    then
        echo "Sorry, you are not running GRASS" >&2
        exit 4
    else
        USERGRASS="$GISDBASE/$LOCATION_NAME/$MAPSET"
fi

if [ $1 = "-N" ]
then
    RASTER="NO"
    shift
    RULES=$1
elif [ $1 = "-c" ]
then
    COLORS=$2
    shift 2
fi

if [ $RASTER = "YES" ]
then
    RULES="/tmp/tmp.$$"
    FILE=$1
fi

units=$2
cat=`expr 1`
if test $3
then
        offset=`expr $3`
else
        offset=`expr 0`
fi

read cuts
echo "  OK, I'll take it from here . . ."
set -- ${cuts}
start=$1
shift

cp /dev/null $RULES

while test $1
do
        RANGE=`echo "${start} thru $1 = ${cat}  "`
        echo $RANGE`expr $start + $offset` - `expr $1 + $offset` ${units} \
         >> $RULES
        start=`expr $1 + 1`
        shift
        cat=`expr $cat + 1`
done
echo "end" >> $RULES

if [ $RASTER = "YES" ]
then [ -s $USERGRASS/colr/$FILE.rec ] && rm $USERGRASS/colr/$FILE.rec
    r.reclass input=$FILE output=$FILE.rec < $RULES
    rm $RULES
    if [ $COLORS ]
    then
        r.colors map=$FILE.rec color=rules < $COLORS
    fi
fi

----------------------------end shell script----------------------------------
greg

******************************************************************************
Greg Koerper                            Internet: [hidden email]
ManTech Environmental Technology, Inc.  UUCP:     hplabs!hp-pcd!orstcs!koerper
200 SW 35th St., JSB                    
Corvallis, OR   97333           "The 90s will make the 60s look like the 50s.
(503) 754-4490                          Just ask your kids."
 fax:  (503) 754-4338
******************************************************************************