It works great....thanks Stefan! On Mon, Aug 29, 2016 at 1:23 PM, Blumentrath, Stefan < [email protected]> wrote:
> Hei Alassane, > Can't you just do: > > db.execute sql="UPDATE parcel SET pchng=int((0.25*c_number/par_sqf)*100)" > > Cheers, > Stefan > ________________________________________ > Von: grass-user [[email protected]] im Auftrag von > alassane toure [[email protected]] > Gesendet: Montag, 29. August 2016 20:25 > An: GRASS user list > Betreff: [GRASS-user] Fwd: vector attribute calculation in grass python > > Dear Moritz & group, > I am a newbi in python programming. Following Moritz's instructions i > added the followings.. > > par_sqf=[] > c_number=[] > pchng=[] > > but pchng stayed NULL for all rows (see below)! > [Inline image 2] > Any suggestions how to resolve this? > > Regards, > Alassane > ---------- Forwarded message ---------- > From: alassane toure <[email protected]<mailto:[email protected]>> > Date: Mon, Aug 29, 2016 at 9:27 AM > Subject: vector attribute calculation in grass python > To: GRASS user list <[email protected]<mailto: > [email protected]>> > > > Group, > I am in the process of developing a python/grass code to calculate an > attribute value based on other attributes. The following error comes up: > > NameError: name 'par_sqf' is not defined > > > Here is the code... > > # some predefined variables > ########################### > import os > import sys > import subprocess > import shutil > import binascii > import tempfile > import shutil > > import gdal > from gdalconst import * > ... > ... > grass.run_command('v.rast.stats',map='parcel', > raster='constr_clean1',method='number',column_prefix='c') > > grass.run_command('v.db.addcolumn', map='parcel', columns='par_sqf double > precision') > grass.run_command('v.to.db', map='parcel', option='area', > columns='par_sqf', unit='feet') > grass.run_command('v.db.addcolumn',map='parcel',columns='pchng int') > > grass.read_command('v.db.select',map='parcel',columns='c_number') > grass.read_command('v.db.select',map='parcel',columns='par_sqf') > pchng = range(len(par_sqf)) > for i in range(len(par_sqf)): > pchng[i]=+int((0.25*c_number[i]/par_sqf[i])*100) > > for i in range(len(par_sqf)): > query="UPDATE parcel SET pchng=" + str(pchng[i]) + " WHERE cat = " + > str(i+1) > grass.write_command("db.execute", stdin = query) > > ... > ... > > Your insight is appreciated. > > Alassane > > > >
_______________________________________________ grass-user mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/grass-user
