[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

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@lists.osgeo.org On Behalf Of Stefan Blumentrath
Sent: fredag 20. april 2018 09.12
To: GRASS developers list (grass-dev@lists.osgeo.org) grass-dev@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