[GRASS-user] vector attribute calculation in grass python

Moritz Lennert mlennert at club.worldonline.be
Mon Aug 29 08:32:02 PDT 2016


On 29/08/16 17:27, alassane toure wrote:
> 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))

It seems that you are trying to get the length of a variable par_sqf 
that is not defined in the code.

Moritz


More information about the grass-user mailing list