<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.EmailStyle18
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="NO-BOK" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-GB" style="color:#1F497D">OK, my bad. I had a mistake in the following code…<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:#1F497D">So for the record:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:#1F497D">All fine if centroid category is written:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:#1F497D">tmp_vect.write(cent, cat=12)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:#1F497D">Cheers<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:#1F497D">Stefan<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="mso-fareast-language:NO-BOK">From:</span></b><span lang="EN-US" style="mso-fareast-language:NO-BOK"> grass-dev <grass-dev-bounces@lists.osgeo.org>
<b>On Behalf Of </b>Stefan Blumentrath<br>
<b>Sent:</b> fredag 20. april 2018 09.12<br>
<b>To:</b> GRASS developers list (grass-dev@lists.osgeo.org) <grass-dev@lists.osgeo.org><br>
<b>Subject:</b> [GRASS-dev] How to write areas with category in pygrass<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-GB">Dear devs,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">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.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Anyone, who can give me a hint on how add categories to a pygrass geometry, esp. area?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">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:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">import grass.script as grass<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">from grass.pygrass.vector import VectorTopo<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">from grass.pygrass.vector.geometry import Boundary<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">from grass.pygrass.vector.geometry import Centroid<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">from grass.pygrass.vector.geometry import Point<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"># Create area<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">area = Point(x=100, y=100).buffer(50)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">vect_name = 'test1'<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"># Create vector map<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">vect = VectorTopo(vect_name)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">vect.open(mode='w')<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">vect.write(Boundary(points=area[0].to_list()))<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"># , c_cats=int(cat), set_cats=True<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">cent = Centroid(x=area[1].x, y=area[1].y)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">vect.write(cent)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">vect.close(build=True)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"># Check if cat is present<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">grass.read_command('v.category', input= vect_name, option='report')<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Thanks for any hints in advance!<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Cheers<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Stefan<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">P.S.: Adding a category to the centroid does not help…<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">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].<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">1: <a href="https://grass.osgeo.org/grass74/manuals/libpython/pygrass.vector.html#pygrass.vector.geometry.Point.buffer">
https://grass.osgeo.org/grass74/manuals/libpython/pygrass.vector.html#pygrass.vector.geometry.Point.buffer</a><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">2: <a href="https://grass.osgeo.org/grass74/manuals/libpython/pygrass.vector.html#pygrass.vector.geometry.Area.buffer">
https://grass.osgeo.org/grass74/manuals/libpython/pygrass.vector.html#pygrass.vector.geometry.Area.buffer</a><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
</div>
</body>
</html>