<div dir="ltr"><div><div>Dear Moritz & group,<br></div>I am a newbi in python programming. Following Moritz's instructions i added the followings..<br><br>par_sqf=[]<br>c_number=[]<br>pchng=[]<br><br></div>but pchng stayed NULL for all rows (see below)!<br><div><img tabindex="0" class="" alt="Inline image 2" src="cid:ii_156d769921b1983f" height="154" width="412"><br></div><div>Any suggestions how to resolve this?<br><br></div><div>Regards,<br></div>Alassane<div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">alassane toure</b> <span dir="ltr"><<a href="mailto:atourej@gmail.com">atourej@gmail.com</a>></span><br>Date: Mon, Aug 29, 2016 at 9:27 AM<br>Subject: vector attribute calculation in grass python<br>To: GRASS user list <<a href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a>><br><br><br><div dir="ltr"><div><div><div><div>Group,<br></div>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:<br><br>NameError: name 'par_sqf' is not defined<br><br><br></div>Here is the code...<br><br># some predefined variables<br>###########################<br>import os<br>import sys <br>import subprocess<br>import shutil<br>import binascii<br>import tempfile<br>import shutil <br><br>import gdal<br>from gdalconst import *<br>...<br>...<br>grass.run_command('v.rast.<wbr>stats',map='parcel', raster='constr_clean1',method=<wbr>'number',column_prefix='c')<br><br>grass.run_command('v.db.<wbr>addcolumn', map='parcel', columns='par_sqf double precision') <br>grass.run_command('v.to.db', map='parcel', option='area', columns='par_sqf', unit='feet') <br>grass.run_command('v.db.<wbr>addcolumn',map='parcel',<wbr>columns='pchng int')<br><br>grass.read_command('v.db.<wbr>select',map='parcel',columns='<wbr>c_number')<br>grass.read_command('v.db.<wbr>select',map='parcel',columns='<wbr>par_sqf')<br>pchng = range(len(par_sqf))<br>for i in range(len(par_sqf)):<br> pchng[i]=+int((0.25*c_number[<wbr>i]/par_sqf[i])*100)<br><br>for i in range(len(par_sqf)):<br> query="UPDATE parcel SET pchng=" + str(pchng[i]) + " WHERE cat = " + str(i+1)<br> grass.write_command("db.<wbr>execute", stdin = query)<br><br>...<br>...<br><br></div>Your insight is appreciated.<span class=""><font color="#888888"><br><br></font></span></div><span class=""><font color="#888888">Alassane<br><div><div><br><br></div></div></font></span></div>
</div><br></div>