On Wed, Oct 29, 2014 at 8:44 AM, Luca Delucchi <[email protected]> wrote:
> On 28 October 2014 20:40, Markus Metz <[email protected]> wrote:
>
>>
>> So the question is how to handle multiple categories per feature and
>> layer instead of multiple layers per vector?
>>
>
> yes
>
>> Would it be so difficult to enable g.gui.rlisetup to handle these cases?
>>
>
> Yes, it should but we was looking for a generic method

The generic method is v.category option=print
>
>>> In order to
>>> avoid that it dies with ugly messages we want to catch such situations
>>> and exit with a proper error message...
>>
>> Alternatively, g.gui.rlisetup and the r.li.* logic could be changed to
>> accept such situations.
>>
>
> I think that r.li.* should work, the problem right now is in
> g.gui.rlisetup because "/" is a character not allowed for the name of
> new vectors.
> g.gui.rlisetup creates a new vector for any selected features and it
> add the cat as suffix for the name of the new vectors

Please try the attached patch for gui/wxpython/rlisetup.

Markus M
Index: gui/wxpython/rlisetup/wizard.py
===================================================================
--- gui/wxpython/rlisetup/wizard.py	(revision 62470)
+++ gui/wxpython/rlisetup/wizard.py	(working copy)
@@ -882,9 +882,25 @@
         self.sizer.Hide(self.regionBox)
         self.sizer.Hide(self.areaPanel)
         self.SetNext(self.parent.summarypage)
-        vect_cats = sorted(set(grass.parse_command('v.category', input=self.parent.startpage.vect,
-                                                   option='print',
-                                                   type='centroid').keys()))
+        #vect_cats = sorted(set(grass.parse_command('v.category', input=self.parent.startpage.vect,
+        #                                          option='print',
+        #                                           type='centroid').keys()))
+
+	vect_cats = []
+	vc = grass.read_command('v.category', input=self.parent.startpage.vect,
+			        option='print', type='centroid')
+	for lc in vc.splitlines():
+	    for cat in lc.split('/'):
+		vect_cats.append(int(cat))
+
+	vect_cats.sort()
+	last = vect_cats[-1]
+	for i in range(len(vect_cats)-2, -1, -1):
+	    if last == vect_cats[i]:
+		del vect_cats[i]
+	    else:
+		last = vect_cats[i]
+
         self._progressDlg = wx.ProgressDialog(title=_("Analysing vector"),
                                               message="Analysing vector",
                                               maximum=len(vect_cats),
Index: gui/wxpython/rlisetup/functions.py
===================================================================
--- gui/wxpython/rlisetup/functions.py	(revision 62470)
+++ gui/wxpython/rlisetup/functions.py	(working copy)
@@ -81,10 +81,10 @@
     """Convert a single feature to a raster"""
     tmp_vect = "tmp_{rast}".format(rast=outrast)
     grass.run_command('v.extract', input=vect, output=tmp_vect, cats=cat,
-                      overwrite=True, quiet=True)
+                      flags='d', overwrite=True, quiet=True)
     grass.run_command('g.region', vect=tmp_vect, align=origrast)
-    grass.run_command('v.to.rast', input=vect, output=outrast, use='cat',
-                      cats=cat, overwrite=True, quiet=True)
+    grass.run_command('v.to.rast', input=tmp_vect, output=outrast, use='val',
+                      value=cat, overwrite=True, quiet=True)
     grass.run_command('g.remove', flags='f', type='vect',
                       name=tmp_vect, quiet=True)
 
@@ -108,7 +108,7 @@
         GError(message=_("The polygon seems to have 0 areas"))
         return None
     for n in range(areanum):
-        cat = vect_cats[n]
+        cat = str(vect_cats[n])
         rast_name = "{name}_{cat}".format(name=vect.split('@')[0], cat=cat)
         convertFeature(vect, rast_name, cat, rast)
         output.append(obtainAreaVector(rast_name))
_______________________________________________
grass-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-dev

Reply via email to