[GRASS-user] test raster or vector

Hamish hamish_nospam at yahoo.com
Wed Oct 25 20:29:48 EDT 2006


Michaël Rabotin wrote:
> a basic question for a shell script in GRASS 6.0.1
> In a part of my script, I ask the user to give the name of a map (a
> vector or a raster)
> and I want to test if the user give a raster or a vector.
> Do you know how I can proceed to do this test ?


first port of call: see the g.parser help page.
  http://grass.ibiblio.org/grass63/manuals/html63_user/g.parser.html


you might want to try
  http://grass.ibiblio.org/grass63/manuals/html63_user/g.findfile.html
  http://grass.ibiblio.org/grass63/manuals/html63_user/g.filename.html


beware the case where there is a raster and a vector of the same name!
(e.g. spearfish dataset)

MAPNAME=roads

#test for raster
g.findfile element=cell file=$MAPNAME

echo $?
0


g.findfile element=cell file=${MAPNAME}2

echo $?
1

#find vector map
g.findfile element=vector file=${MAPNAME}



# example
g.findfile element=cell file=${MAPNAME} > /dev/null
if [ $? -eq 0 ] ; then
  echo "raster [$MAPNAME] exists"
fi

g.findfile element=vector file=${MAPNAME} > /dev/null
if [ $? -eq 0 ] ; then
  echo "vector [$MAPNAME] exists"
fi


Hamish




More information about the grass-user mailing list