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

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

On Monday 05 June 2006 14:11, Jonathan Aguero wrote:

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!

1. Determine some relationship between vector points and the data you wish to
populate a column with

2. run the SQL:
update mytable set mycolumn = myvalue where myexpression = something

--
Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
530.754.7341

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@geo.uni-augsburg.de
Web: www.geo.uni-augsburg.de/lehrstuehle/phygeo
-----------------------------------------------------------

Use v.db.update (in the database menu)

Michael
__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

From: Jonathan Aguero <jua130@psu.edu>
Date: Mon, 5 Jun 2006 17:11:37 -0400
To: <grassuser@grass.itc.it>
Subject: [GRASS-user] Update of vector table through selections in the map

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

First thanks to Dylan Beaudette, Andreas Philipp, and Michael Barton for
their answers but I guess I didn't explain myself clearly, maybe some more
detail can help.
I have a point map representing the intersections on centerline roads
segments derived from the roads segment map (lines) through a several step
process. Some of this intersections represent at-grade road intersections
such as stop controlled intersections or signalized intersections while some
others represent the on and off ramps in an interchange. I need to classify
the elements in these two categories, intersections and interchanges. The
only way to really distinguish between these two types is by visual
inspection of the segments map and corresponding intersections map. So I was
looking for a way of selecting several points though out the mouse click on
the screen and then assigning a value of the attribute for all the selected
points at the same time. This cannot be accomplished by database commands
like v.db.update or update/where.

Jonathan Aguero Valverde

-----Original Message-----
From: Michael Barton [mailto:Michael.Barton@asu.edu]
Sent: Tuesday, June 06, 2006 12:31 AM
To: Jonathan Aguero; grassuser@grass.itc.it
Subject: Re: [GRASS-user] Update of vector table through selections in the
map

Use v.db.update (in the database menu)

Michael
__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

From: Jonathan Aguero <jua130@psu.edu>
Date: Mon, 5 Jun 2006 17:11:37 -0400
To: <grassuser@grass.itc.it>
Subject: [GRASS-user] Update of vector table through selections in the map

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

Hi Jonathan,

I think I understand your task. It is relatively close to mine (quickly assign
height attributes to a huge set of vector lines manually), today I worked
more on that script "v.digatt" (attached if it works), it is exactly doing
(if not completely buggy) what you want, if I'm right: define a attribute
value (say "1" for intersections) and assign that to all points you click at
in the following, then define the attribute value of "2" for interchanges and
click on other points to assign "2" to their records in the table in one
step for all of them and so on. The script was tested only for lines, but it
works fine for that and I tied to make it usable also for points.
The selection is done by v.what.vect (extracting the category numbers of all
objects you have clicked into a list) and the update is done with v.db.update
for all collected objects (=category numbers in the list) in one step.
Please try it and tell whether it works for you or not.
Cheers,
Andreas

Am Thursday 08 June 2006 22:08 schrieb Jonathan Aguero:

First thanks to Dylan Beaudette, Andreas Philipp, and Michael Barton for
their answers but I guess I didn't explain myself clearly, maybe some more
detail can help.
I have a point map representing the intersections on centerline roads
segments derived from the roads segment map (lines) through a several step
process. Some of this intersections represent at-grade road intersections
such as stop controlled intersections or signalized intersections while
some others represent the on and off ramps in an interchange. I need to
classify the elements in these two categories, intersections and
interchanges. The only way to really distinguish between these two types is
by visual inspection of the segments map and corresponding intersections
map. So I was looking for a way of selecting several points though out the
mouse click on the screen and then assigning a value of the attribute for
all the selected points at the same time. This cannot be accomplished by
database commands like v.db.update or update/where.

Jonathan Aguero Valverde

-----Original Message-----
From: Michael Barton [mailto:Michael.Barton@asu.edu]
Sent: Tuesday, June 06, 2006 12:31 AM
To: Jonathan Aguero; grassuser@grass.itc.it
Subject: Re: [GRASS-user] Update of vector table through selections in the
map

Use v.db.update (in the database menu)

Michael
__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

From: Jonathan Aguero <jua130@psu.edu>
Date: Mon, 5 Jun 2006 17:11:37 -0400
To: <grassuser@grass.itc.it>
Subject: [GRASS-user] Update of vector table through selections in the map

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

_______________________________________________
grassuser mailing list
grassuser@grass.itc.it
http://grass.itc.it/mailman/listinfo/grassuser

(attachments)

v.digatt (6.02 KB)

Jonathan,
I forgot some explanations and warnings, which are necessary to run this crude
script (v.digatt):
work on a copy of your map since it is not tested and no good argument
verification is done at the present state yet.
If you start with
"v.digatt input=map1 output=map2 type=point col=sect ctype=INT"
all objects having no attribute in column "sect" are displayed in random
colors and thicker, all objects already assigned to an attribute are shown
with colors from blue to red (this is designed for numeric attributes and
lines, but should work on points too, though has to be redesigned for points,
areas an VARCHAR attributes). After a few checks you can zoom within your
display to a region where you have points to work at. If you finished zooming
(right click), you have to type in an attribute value and afterwards click on
all objects that should get this value. I you have finished (right click) in
this zoom region all assignments should be done by updating the table. The
updated map will be shown and you can move your working window by zooming
again, and so on until you say "q" for "quit" instead of typing in a
attribute value. Hope that works, I will work more on it in order to make it
more save an self explaining, e.g. an appropriate help function, check
arguments and so on, but may be someone can code it in C within v.digit??? It
is really an important function for many applications it seems. BTW (speaking
to the list now) is it intended that r.to.vect omits to register the
extracted vector objects and assigns no category numbers? This causes much
trouble for subsequent processing.
Cheers,
Andreas

Am Thursday 08 June 2006 22:08 schrieb Jonathan Aguero:

First thanks to Dylan Beaudette, Andreas Philipp, and Michael Barton for
their answers but I guess I didn't explain myself clearly, maybe some more
detail can help.
I have a point map representing the intersections on centerline roads
segments derived from the roads segment map (lines) through a several step
process. Some of this intersections represent at-grade road intersections
such as stop controlled intersections or signalized intersections while
some others represent the on and off ramps in an interchange. I need to
classify the elements in these two categories, intersections and
interchanges. The only way to really distinguish between these two types is
by visual inspection of the segments map and corresponding intersections
map. So I was looking for a way of selecting several points though out the
mouse click on the screen and then assigning a value of the attribute for
all the selected points at the same time. This cannot be accomplished by
database commands like v.db.update or update/where.

Jonathan Aguero Valverde

-----Original Message-----
From: Michael Barton [mailto:Michael.Barton@asu.edu]
Sent: Tuesday, June 06, 2006 12:31 AM
To: Jonathan Aguero; grassuser@grass.itc.it
Subject: Re: [GRASS-user] Update of vector table through selections in the
map

Use v.db.update (in the database menu)

Michael
__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

From: Jonathan Aguero <jua130@psu.edu>
Date: Mon, 5 Jun 2006 17:11:37 -0400
To: <grassuser@grass.itc.it>
Subject: [GRASS-user] Update of vector table through selections in the map

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

_______________________________________________
grassuser mailing list
grassuser@grass.itc.it
http://grass.itc.it/mailman/listinfo/grassuser