[GRASS-SVN] r70206 - grass/branches/releasebranch_7_2/lib/python/script

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jan 2 09:23:58 PST 2017


Author: annakrat
Date: 2017-01-02 09:23:58 -0800 (Mon, 02 Jan 2017)
New Revision: 70206

Modified:
   grass/branches/releasebranch_7_2/lib/python/script/vector.py
Log:
pythonlib: add layers to vector_what function (merge from trunk, r69689)

Modified: grass/branches/releasebranch_7_2/lib/python/script/vector.py
===================================================================
--- grass/branches/releasebranch_7_2/lib/python/script/vector.py	2017-01-02 17:00:07 UTC (rev 70205)
+++ grass/branches/releasebranch_7_2/lib/python/script/vector.py	2017-01-02 17:23:58 UTC (rev 70206)
@@ -269,7 +269,7 @@
 orderedDict = None
 
 
-def vector_what(map, coord, distance=0.0, ttype=None, encoding=None, skip_attributes=False):
+def vector_what(map, coord, distance=0.0, ttype=None, encoding=None, skip_attributes=False, layer=None):
     """Query vector map at given locations
 
     To query one vector map at one location
@@ -327,6 +327,8 @@
                   area, face)
     :param encoding: attributes encoding
     :param skip_attributes: True to skip querying attributes
+    :param layer: layer number or list of layers (one for each vector),
+                  if None, all layers (-1) are used
 
     :return: parsed list
     """
@@ -339,7 +341,17 @@
     else:
         map_list = map
 
-    layer_list = ['-1'] * len(map_list)
+    if layer:
+        if isinstance(layer, (tuple, list)):
+            layer_list = [str(l) for l in layer]
+        else:
+            layer_list = [str(layer)]
+        if len(layer_list) != len(map_list):
+            raise ScriptError(_("Number of given vector maps ({m}) "
+                                "differs from number of layers ({l})").format(m=len(map_list),
+                                                                              l=len(layer_list)))
+    else:
+        layer_list = ['-1'] * len(map_list)
 
     coord_list = list()
     if isinstance(coord, tuple):



More information about the grass-commit mailing list