[GRASS-SVN] r58335 - grass/trunk/lib/python/script

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Nov 29 11:53:30 PST 2013


Author: martinl
Date: 2013-11-29 11:53:29 -0800 (Fri, 29 Nov 2013)
New Revision: 58335

Modified:
   grass/trunk/lib/python/script/vector.py
Log:
pythonlib: fix vector_what() for case when one of the attributes is 'Layer'
           TODO: it would be nice if v.what would produce parsable format (eg. XML)


Modified: grass/trunk/lib/python/script/vector.py
===================================================================
--- grass/trunk/lib/python/script/vector.py	2013-11-29 17:29:49 UTC (rev 58334)
+++ grass/trunk/lib/python/script/vector.py	2013-11-29 19:53:29 UTC (rev 58335)
@@ -366,6 +366,8 @@
     if not ret:
         return data
     
+    # parse `v.what -g` output is a nightmare
+    # TODO: change `v.what -g` format or add parsable format (e.g. XML)
     dict_attrb = None
     dict_map = None
     dict_layer = None
@@ -389,13 +391,16 @@
             dict_layer = None
             dict_attrb = None
         elif key == 'Layer':
-            # attach the last the previous Layer
-            if dict_layer is not None:
-                dict_main = copy.copy(dict_map)
-                dict_main.update(dict_layer)
-                data.append(dict_main)
-            dict_layer = { key: int(value) }
-            dict_attrb = None
+            if not dict_attrb:
+                # attach the last the previous Layer
+                if dict_layer is not None:
+                    dict_main = copy.copy(dict_map)
+                    dict_main.update(dict_layer)
+                    data.append(dict_main)
+                dict_layer = { key: int(value) }
+                dict_attrb = None
+            else:
+                dict_attrb[key] = value
         elif key == 'Key_column':
             dict_layer[key] = value
             dict_attrb = dict()



More information about the grass-commit mailing list