[GRASS-dev] How to write areas with category in pygrass

Stefan Blumentrath Stefan.Blumentrath at nina.no
Fri Apr 20 00:12:02 PDT 2018


Dear devs,

After searching the pygrass documentation for examples on how to write areas to a vector map and trying different things without success, I am currently struggling with adding the category to the area.

Anyone, who can give me a hint on how add categories to a pygrass geometry, esp. area?

The following Python code shows how I write the area (maybe it is supposed to be done differently?). Result is an area written, but without category and thus not usable at that point:

import grass.script as grass
from grass.pygrass.vector import VectorTopo
from grass.pygrass.vector.geometry import Boundary
from grass.pygrass.vector.geometry import Centroid
from grass.pygrass.vector.geometry import Point

# Create area
area = Point(x=100, y=100).buffer(50)
vect_name = 'test1'

# Create vector map
vect = VectorTopo(vect_name)
vect.open(mode='w')
vect.write(Boundary(points=area[0].to_list()))
# , c_cats=int(cat), set_cats=True
cent = Centroid(x=area[1].x, y=area[1].y)
vect.write(cent)
vect.close(build=True)

# Check if cat is present
grass.read_command('v.category', input= vect_name, option='report')


Thanks for any hints in advance!

Cheers
Stefan

P.S.: Adding a category to the centroid does not help...
P.S.: BTW. pygrass documentation says area.buffer(50) is supposed to return an Area() object [1]. However, it returns a tuple with a line (boundary) and a point (centroid), like Area().buffer(50) is supposed to [2].

1: https://grass.osgeo.org/grass74/manuals/libpython/pygrass.vector.html#pygrass.vector.geometry.Point.buffer
2: https://grass.osgeo.org/grass74/manuals/libpython/pygrass.vector.html#pygrass.vector.geometry.Area.buffer


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20180420/a9b6038e/attachment.html>


More information about the grass-dev mailing list