Hi Markus,

On 29 October 2014 09:15, Markus Metz <markus.metz.gisw...@gmail.com> wrote:

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

I test your patch and it works. I improved a little bit it (attached
the new patch).
Do you apply it?

> Markus M

-- 
ciao
Luca

http://gis.cri.fmach.it/delucchi/
www.lucadelu.org
Index: rlisetup/functions.py
===================================================================
--- rlisetup/functions.py	(revision 62484)
+++ rlisetup/functions.py	(working copy)
@@ -81,14 +81,27 @@
     """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)
 
 
+def obtainCategories(vector):
+    """This function check if the vector is multilayer and return a list only
+    for the single categories"""
+    vect_cats = []
+    vc = grass.read_command('v.category', input=vector,
+                            option='print', type='centroid')
+    for lc in vc.splitlines():
+        for cat in lc.split('/'):
+            vect_cats.append(int(cat))
+
+    return sorted(set(vect_cats))
+
+
 def obtainAreaVector(outrast):
     """Create the string for configuration file"""
     reg = grass.region()
@@ -108,7 +121,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))
Index: rlisetup/wizard.py
===================================================================
--- rlisetup/wizard.py	(revision 62484)
+++ rlisetup/wizard.py	(working copy)
@@ -33,7 +33,8 @@
 from rlisetup.sampling_frame import RLiSetupMapPanel
 from grass.script import core as grass
 from grass.script import raster as grast
-from functions import SamplingType, sampleAreaVector, convertFeature, obtainAreaVector
+from functions import SamplingType, sampleAreaVector, convertFeature
+from functions import obtainAreaVector, obtainCategories
 from core.gcmd import GError, GMessage, RunCommand
 
 
@@ -194,21 +195,21 @@
             self.SF_W = newreg['w']  # set env(SF_W) $w
 
             self.SF_Y = abs(round(self.gregion['n'] - newreg['n']) / newreg['nsres'])
-#		 set env(SF_Y) [expr abs(round(($s_n - $n) / $nres)) ]
+#         set env(SF_Y) [expr abs(round(($s_n - $n) / $nres)) ]
             self.SF_X = abs(round(self.gregion['w'] - newreg['w']) / newreg['ewres'])
-#		 set env(SF_X) [expr abs(round(($s_w - $w) / $sres)) ]
+#         set env(SF_X) [expr abs(round(($s_w - $w) / $sres)) ]
             self.SF_RL = abs(round(newreg['n'] - newreg['s']) / newreg['nsres'])
-#		 set env(SF_RL) [expr abs(round(($n - $s) / $nres)) ]
+#         set env(SF_RL) [expr abs(round(($n - $s) / $nres)) ]
             self.SF_CL = abs(round(newreg['e'] - newreg['w']) / newreg['ewres'])
-#		 set env(SF_CL) [expr abs(round(($e - $w) / $sres)) ]
+#         set env(SF_CL) [expr abs(round(($e - $w) / $sres)) ]
             self.per_x = float(self.SF_X) / float(self.rasterinfo['cols'])
-#		 double($env(SF_X)) / double($cols)
+#         double($env(SF_X)) / double($cols)
             self.per_y = float(self.SF_Y) / float(self.rasterinfo['rows'])
-#	       double($env(SF_Y)) / double($rows)
+#           double($env(SF_Y)) / double($rows)
             self.per_rl = float(self.SF_RL) / float(self.rasterinfo['rows'])
-#		 double($env(SF_RL)) / double($rows)
+#         double($env(SF_RL)) / double($rows)
             self.per_cl = float(self.SF_CL) / float(self.rasterinfo['cols'])
-#		 double($env(SF_CL)) / double($cols)
+#         double($env(SF_CL)) / double($cols)
             fil.write("SAMPLINGFRAME %r|%r|%r|%r\n" % (self.per_x, self.per_y,
                                                        self.per_rl, self.per_cl))
 
@@ -882,9 +883,9 @@
         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 = obtainCategories(self.parent.startpage.vect)
+
         self._progressDlg = wx.ProgressDialog(title=_("Analysing vector"),
                                               message="Analysing vector",
                                               maximum=len(vect_cats),
@@ -1504,10 +1505,8 @@
 
         self.rast = self.parent.startpage.rast
         self.vect = self.parent.startpage.vect
-        self.vect_cats = sorted(set(grass.parse_command('v.category',
-                                                        input=self.vect,
-                                                        type='centroid',
-                                                        option='print').keys()))
+        self.vect_cats = obtainCategories(self.vect)
+
         self.areanum = len(self.vect_cats)
         if self.areanum == 0:
             GError(parent=self, message=_("The polygon seems to have 0 areas"))
_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Reply via email to