[GRASS-user] Update of vector table through selections in the map

Andreas Philipp andreas.philipp at geo.uni-augsburg.de
Mon Jun 5 19:14:13 EDT 2006


Hi,

if you are using GRASS6.1 the v.db.update command might help also, e.g.:

v.db.update map=$map column=$col value=$label where="$wherestring"
where e.g.:
col="hgt"
label="505.0"
wherestring="cat=1 OR cat=3 OR cat=4"

Using a list of categories concatenated by "OR" in the where statement is much 
faster than running v.db.update for each category separately.

I'm using this within a script to assign values (here height) to a column of a 
vector map of height contour lines (generated by r.to.vect, v.category, 
v.db.addtable and v.db.addcol) and manually assign values to objects selected 
with d.what.vect with the mouse simultaneously.
For anyone interested in the unfinished script (no warranty, just meant as a 
example) it is attached below.

Cheers, 
Andreas



v.digatt:
-------------------------------------------------------------
#!/bin/sh
  

# CHECK FOR GRASS6.1 (v.db.* commands)
if test "`echo $GISBASE | grep 6.1`" = ""; then
 echo "You must be in GRASS GIS 6.1 to run this program." >&2
 exit 1
fi

# CHECK ARGUMENTS
ctype=DOUBLE
while [ $# -ge 1 ] ; do
   case "$1" in
   map=*) map=`echo "$1" | sed 's/map=//g'` 2>&1 > /dev/null # map name
   ;;
   col=*) col=`echo "$1" | sed 's/col=//g'` 2>&1 > /dev/null # column name to 
#update
   ;;
   ctype=*) ctype=`echo "$1" | sed 's/ctype=//g'` 2>&1 > /dev/null # DOUBLE, 
# INT, VARCHAR, etc.
   ;;
   *) echo unknow argument $1, exit! ; exit 1
   esac
   shift  
done

# ADD TABLE COLUMN IF NECESSARY
if test "`v.db.connect -c map=$map | grep $col`" = "" ; then
  echo vector attribute column \"$col\" not found in table, should it be 
added? \(y/n\):
  read a
  if test $a = "y" ; then
     v.db.addcol map=$map columns=\"$col $ctype\"
  else
     exit 1
  fi
fi  

# THE MAIN OPERATION LOOP
goon=1
while [ $goon -eq 1 ] ; do
  
# DISPLAY THE VECTOR MAP
d.erase
d.vect.thematic map=$map type=line column=$col themetype=graduated_colors 
themecalc=interval colorscheme=blue-red where="${col}>0$
d.vect -c map=$map width=2 where="${col} IS NULL"

# ALLOW ZOOMING
echo
echo 
echo '>>>>>>>>>' use mouse to zoom:
echo '>>>>>>>>>' left button:   zoom in
echo '>>>>>>>>>' middle button: zoom out
echo '>>>>>>>>>' right button: quit zoom
d.zoom  >/dev/null 2>/dev/null
      
# GET THE LABEL = VALUE FOR $COL
oldlabel=$label
echo enter label name \(\"enter\" to use \"$oldlabel\", \"q\"=quit\):
read label
case "$label" in
        q) exit
          ;;
        "") label=$oldlabel
          ;;
esac
    
# COLLECT CAT NUMBERS
echo '>>>>>>>>>' use left mouse button to assign label "${label}" to objects, 
right button to finish
catlist=`d.what.vect -t -f map=$map 2>/dev/null | grep 'cat :'`

# UPDATE THE CAT NUMBERS WITH LABEL IN COL
echo
echo
echo '>>>>>>>>>' updating, please wait ...
catlist=`echo $catlist | sed 's|cat :||g'`
#echo objectlist = $catlist
wherestring=''
for cat in $catlist ; do
if [ ! "$wherestring" ] ; then
  wherestring="cat=$cat"
else
  wherestring="${wherestring} OR cat=$cat"
fi
done
#echo $wherestring
v.db.update map=$map column=$col value=$label where="$wherestring"

done

exit 0
-----------------------------------------------------------------------------------------




Am Monday 05 June 2006 23:11 schrieb Jonathan Aguero:
> Dear List,
>
> I am trying to update the value of several records in a vector table
> simultaneously. The elements to be updated need to be selected in the map.
> I know you can update the values one by one with v.digit or using
> qgis/GRASS but I want to update several each time, something like the
> "calculate values" in the table using ARC-GIS.
>
> PD: I am using pgsql for the tables.
>
> Any idea is welcome, thanks!
>
>
>
> Jonathan Aguero Valverde
>
> Research Assistant and Ph.D. Candidate
>
> Pennsylvania State University
>
> The Pennsylvania Transportation Institute
>
> 201 Transportation Research Building
>
> University Park, PA 16802
>
> www.personal.psu.edu/jua130

-- 
-----------------------------------------------------------
Dr. Andreas Philipp
Institute of Geography
University of Augsburg
Universitaetsstrasse 10
D - 86135 Augsburg
Germany

Phone:   ++49/821/598-2266
Fax:     ++49/821/598-2264
Email:   andreas.philipp at geo.uni-augsburg.de
Web:     www.geo.uni-augsburg.de/lehrstuehle/phygeo
-----------------------------------------------------------




More information about the grass-user mailing list