GRASS Wish List

Malcolm Williamson malcolm at cast.uark.edu
Thu Sep 9 10:58:28 EDT 1993


P. Martijn van Leusen writes:
> 
> To Craig Anderson's wish list I would like to add:
> 
(lines deleted)
> 	g.remove/g.rename - should issue a warning before removing
> or renaming `parents' of reclassified maps.
> 

Here is a temporary solution to the removal problem, in the form of a shell
script that I wrote. It checks for reclasses in *all* mapsets under a Location,
regardless of the search path, so be aware that it can be slow if you have 
*lots* of raster map layers. It also gives the option of printing (using lp)
the list of reclassified maps based on a named 'parent' map; you may need to 
edit this to suit your particular system.

-----------------------------------------------------------------------------

:
#
#                  ****** r.remove.sh *******
#
# Written by Malcolm Williamson
#
# @(#) r.remove.sh: Checks for reclasses before removing a raster map layer.
# Last revision: 3/24/93

if [ "$GISRC" = "" ] ; then
  echo "This command must be run from GRASS!"
  echo ""
  exit 1
fi
name=""
if [ $# = 0 ]; then 
 g.ask type=old prompt="Enter name of raster file to be removed." element=cell \
  desc=raster unixfile=/tmp/$$
 . /tmp/$$
 rm -f /tmp/$$
 if [ "$name" = "" ]; then
   exit 0
  else
   realname="$name"
 fi
 else
  name=$*
  for item in $name
   do
    if [ ! -f $LOCATION/cell/$item ]; then 
      echo "Raster file $item not found in mapset $MAPSET"
     else 
      realname="$realname $item"
    fi
   done
fi
mapsets=`ls $LOCATION/..`
for mapname in $realname ; do
 reclass=""
 clear
 echo "Checking for reclasses of $mapname..."
 echo ""
 for mapset in $mapsets ; do
  if [ -d $LOCATION/../$mapset/cellhd ] ; then
   rasters=`ls $LOCATION/../$mapset/cellhd`
  else
   continue
  fi
  for raster in $rasters; do
   pmap=`cat $LOCATION/../$mapset/cellhd/$raster | grep $mapname`
   if [ "$pmap" != "" ] ; then
    pmapset=`cat $LOCATION/../$mapset/cellhd/$raster | grep $MAPSET`
    if [ "$pmapset" != "" ] ; then
     reclass="$reclass $raster@$mapset"
    fi
   fi
  done
 done
 if [ "$reclass" != "" ] ; then
  echo ""
  echo "	**********WARNING************"
  echo ""
  echo "The following raster map layers are reclasses of $mapname:"
  echo ""
  for map in $reclass ; do
   echo "$map"
  done
  echo ""
  echo "If you remove $mapname, these reclasses will be useless."
  echo ""
  echo -n "Do you really want to remove $mapname? y/n (n): "
  read ans
  if [ "$ans" = "y" ] || [ "$ans" = "Y" ] ; then
   echo ""
   echo "Do you want a printout of the reclasses map layers that"
   echo -n "will be effected? y/n (n): "
   read ans2
   if [ "$ans2" = "y" ] || [ "$ans2" = "Y" ] ; then
    echo "Reclassed map layers based on $mapname in $MAPSET:" > /tmp/printfile
    for map in $reclass ; do
     echo "$map" >> /tmp/printfile
    done
    lp /tmp/printfile
    sleep 3
    rm /tmp/printfile
   fi
  else
   continue
  fi
 fi
echo ""
g.remove $mapname
done
exit 0

-----------------------------------------------------------------------------

-- 
Malcolm D. Williamson - Research Assistant       E-mail: malcolm at cast.uark.edu
Center for Advanced Spatial Technologies      Telephone: (501) 575-6159
Ozark Rm. 12                                        Fax: (501) 575-3846 
University of Arkansas              
Fayetteville, AR 72701



More information about the grass-dev mailing list