[GRASS-dev] pygrass: append new point to map of points
Pietro
peter.zamb at gmail.com
Sat Jan 31 02:16:58 PST 2015
Soory for the delay,
On Fri, Jan 30, 2015 at 3:52 PM, Moritz Lennert
<mlennert at club.worldonline.be> wrote:
> Is it possible in pygrass to append a new point to a map of points (same for
> other features) ? Or do I have to get all the features of a map, and the new
> feature, and then write all features to a new map ?
Yes, here an example, write a new map:
{{{
>>> from grass.pygrass.vector.geometry import Point
>>> from grass.pygrass.vector import VectorTopo
>>> with VectorTopo('mypoits', mode='w') as my:
... my.write(Point(0, 10))
... my.write(Point(5, 15))
...
}}}
read an existing map:
{{{
>>> with VectorTopo('mypoits', mode='r') as my:
... for p in my:
... print(p)
...
POINT(0.000000 10.000000)
POINT(5.000000 15.000000)
}}}
Add some new point to an existing map:
{{{
>>> with VectorTopo('mypoits', mode='rw') as my:
... my.write(Point(10, 10))
... my.write(Point(15, 15))
...
}}}
and read again the modified map:
{{{
>>> with VectorTopo('mypoits', mode='r') as my:
... for p in my:
... print(p)
...
POINT(0.000000 10.000000)
POINT(5.000000 15.000000)
POINT(10.000000 10.000000)
POINT(15.000000 15.000000)
}}}
All the best
Pietro
More information about the grass-dev
mailing list