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

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


OK, my bad. I had a mistake in the following code...
So for the record:
All fine if centroid category is written:
tmp_vect.write(cent, cat=12)

Cheers
Stefan


From: grass-dev <grass-dev-bounces at lists.osgeo.org> On Behalf Of Stefan Blumentrath
Sent: fredag 20. april 2018 09.12
To: GRASS developers list (grass-dev at lists.osgeo.org) <grass-dev at lists.osgeo.org>
Subject: [GRASS-dev] How to write areas with category in pygrass

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/f282de4e/attachment.html>


More information about the grass-dev mailing list