[GRASS-user] calculate values of an attribute table column

-------- Original-Nachricht --------
Datum: Tue, 21 Oct 2008 11:37:07 +0200
Von: "Stefanie Obmann" <stef_ob@gmx.at>
An: grass-user-owner@lists.osgeo.org
Betreff: calculate values of an attribute table column

Dear GRASS users,

I'm working with a vector map with an attribute table. I'm using the GRASS tools with QGIS.
I added a new column to my table and I don't know why my 'start editing' buttons aren't activ.
I'd like to get those new values by calculating the difference of 2 other existing columns.

Do you know any solution for that?

Further I thought about doing the calculation within the GRASS shell but I don't know what tool I should use and how. for example the db.execute, but I couldn't find any calculation possibility in it.

thanks,
stef
--
GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein: http://www.shortview.de/wasistshortview.php?mc=sv_ext_mf@gmx

--
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger

You could use v.db.update:
http://grass.osgeo.org/grass64/manuals/html64_user/v.db.update.html
In the qcolumn filed you can insert a formula

As fas as I know, when using dbf tables you can't do calculations on
multiple fields (for a single column you can insert formulas inside
qcolumn in v.db.update). Practical solutions I usually adopt:

1 - open the vector dbf with OpenOfficeCalc, and do what I want... If
you use OOCalc, remember to copy the results in a column as "real"
numbers, detached from the formulas they were created from, otherwise
GRASS can't use those values...
2 - connect you vector to a different db like PostGIS or Sqlite. They
both support more comples queries in db.execute

Giovanni

Dear GRASS users,

I'm working with a vector map with an attribute table. I'm using the GRASS tools with QGIS.
I added a new column to my table and I don't know why my 'start editing' buttons aren't activ.
I'd like to get those new values by calculating the difference of 2 other existing columns.

Do you know any solution for that?

Further I thought about doing the calculation within the GRASS shell but I don't know what tool I should use and how. for example the db.execute, but I couldn't find any calculation possibility in it.

thanks,
stef
--
GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein: http://www.shortview.de/wasistshortview.php?mc=sv_ext_mf@gmx

--
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

On 21/10/08 13:23, G. Allegri wrote:

You could use v.db.update:
http://grass.osgeo.org/grass64/manuals/html64_user/v.db.update.html
In the qcolumn filed you can insert a formula

As fas as I know, when using dbf tables you can't do calculations on
multiple fields (for a single column you can insert formulas inside
qcolumn in v.db.update).

You can add, substract and multiply columns, but there seems to be a bug for division. Will file a report.

2 - connect you vector to a different db like PostGIS or Sqlite. They
both support more comples queries in db.execute

I think that this is the general advise.

Moritz

On 21/10/08 14:23, Moritz Lennert wrote:

On 21/10/08 13:23, G. Allegri wrote:

You could use v.db.update:
http://grass.osgeo.org/grass64/manuals/html64_user/v.db.update.html
In the qcolumn filed you can insert a formula

As fas as I know, when using dbf tables you can't do calculations on
multiple fields (for a single column you can insert formulas inside
qcolumn in v.db.update).

You can add, substract and multiply columns, but there seems to be a bug for division. Will file a report.

Sorry, I take that back: division works, but the error you get in case of a division by 0 is a bit cryptic:

"ERREUR:This should not happen: got a wrong expression structure after
        parsing.
dbmi: Protocol error"

IIUC how the code is written, the "this should not happen" is not really precise. It will happen whenever you attempt a division by 0 or something similar...

Maybe it just needs a more user-friendly formulation.

Moritz

Are you sure Moritz that in qcolumn you can use multiple columns? If
it's true I've always excluded it because of a bug in my Grass! :slight_smile:

2008/10/21 Moritz Lennert <mlennert@club.worldonline.be>:

On 21/10/08 14:23, Moritz Lennert wrote:

On 21/10/08 13:23, G. Allegri wrote:

You could use v.db.update:
http://grass.osgeo.org/grass64/manuals/html64_user/v.db.update.html
In the qcolumn filed you can insert a formula

As fas as I know, when using dbf tables you can't do calculations on
multiple fields (for a single column you can insert formulas inside
qcolumn in v.db.update).

You can add, substract and multiply columns, but there seems to be a bug
for division. Will file a report.

Sorry, I take that back: division works, but the error you get in case of a
division by 0 is a bit cryptic:

"ERREUR:This should not happen: got a wrong expression structure after
      parsing.
dbmi: Protocol error"

IIUC how the code is written, the "this should not happen" is not really
precise. It will happen whenever you attempt a division by 0 or something
similar...

Maybe it just needs a more user-friendly formulation.

Moritz

On 21/10/08 14:37, G. Allegri wrote:

Are you sure Moritz that in qcolumn you can use multiple columns? If
it's true I've always excluded it because of a bug in my Grass! :slight_smile:

I only have grass7 installed at the moment, but there it works (using the North Carolina demo data):

g.copy vect=censusblk_swwake,myblocks
v.db.addcol myblocks col='result double precision'
v.db.update myblocks col=result qcol='P65_OLDER/TOTAL_POP' where="TOTAL_POP>0"
v.db.select myblocks col=P65_OLDER,TOTAL_POP,result

Moritz