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

Pietro peter.zamb at gmail.com
Wed Sep 30 02:53:10 PDT 2015


On Wed, Sep 30, 2015 at 9:51 AM, Paulo van Breugel
<p.vanbreugel at gmail.com> wrote:
>
>
> On Wed, Sep 30, 2015 at 2:02 AM, Anna Petrášová <kratochanna at gmail.com>
> wrote:
>>
>>
>>
>> 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
>>
>>
> Thanks, but that seems to write the vector back without attribute table

You have to save the changes in the database out from your cycle, with:

vectormap.table.conn.commit()

Pietro


More information about the grass-dev mailing list