[GRASS-dev] Write array to (point) attribute table

Anna Petrášová kratochanna at gmail.com
Tue Sep 29 17:02:40 PDT 2015


On Tue, Sep 29, 2015 at 6:09 PM, Paulo van Breugel <p.vanbreugel at gmail.com>
wrote:

> This must be a very basic question, but I can't find an easy/direct way to
> do this. In python, if I have an array with values with a length equal to
> the number of rows in an attribute table of a (point) vector layer, how can
> I write those values to a new column in that attribute table. I can of
> course first create the column, but than how to update that column with the
> values in the array?
>

it should be pretty easy to do with pygrass, unfortunately there is no
example on assigning attributes in the official documentation [1],  but it
should be pretty easy, something like that (not tested):

with VectorTopo('myvector', mode='w') as vectormap:
    for feature in vectormap:
        feature.attrs['mycolumn'] = value


Anna

[1]
https://grass.osgeo.org/grass70/manuals/libpython/pygrass_vector.html#working-with-vector-objects

>
> Cheers,
>
> Paulo
>
> _______________________________________________
> grass-dev mailing list
> grass-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20150929/cd4071a7/attachment.html>


More information about the grass-dev mailing list