[GRASS-user] test raster or vector

Hi Everybody
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 ?

Thanks a lot

Mick

Michaël Rabotin wrote:

Hi Everybody
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 ?

http://grass.itc.it/grass62/manuals/html62_user/g.parser.html

and

http://grass.itc.it/grass62/source/SUBMITTING_SCRIPTS

for more tips about script writing.

Moritz

Michaël Rabotin wrote:

Hi Everybody
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.

You can't distunguish between raster and vector by name, they can have
the same name. ???

Maciek

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

Thanks a lot for your responses
In the same way, is it a method to know for a vector map if it is a point, a line or a polygon vector ?
because in a script I’ve to do an overlay but this command doesn’t work for point vector (so I’ve to use v.select) but before to use one of these commands I’ve to know the type of geometry of my vector

Cheers

Mick

2006/10/26, Hamish < hamish_nospam@yahoo.com>:

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

Michaël Rabotin wrote:

Thanks a lot for your responses
In the same way, is it a method to know for a vector map if it is a
point, a
line or a polygon vector ?
because in a script I've to do an overlay but this command doesn't work for
point vector (so I've to use v.select) but before to use one of these
commands I've to know the type of geometry of my vector

In GRASS you can have different geometries stored in one vector map.

One way to see whether there are points in your vector map is to parse
the v.info output - in GRASS 6.3 CVS Jachym has added a -t flag for a
nicely parsable, terse output.

Maciek