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

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Oct 8 19:51:14 PDT 2016


Author: annakrat
Date: 2016-10-08 19:51:13 -0700 (Sat, 08 Oct 2016)
New Revision: 69689

Modified:
   grass/trunk/lib/python/script/vector.py
Log:
pythonlib: add layers to vector_what function

Modified: grass/trunk/lib/python/script/vector.py
===================================================================
--- grass/trunk/lib/python/script/vector.py	2016-10-09 02:17:30 UTC (rev 69688)
+++ grass/trunk/lib/python/script/vector.py	2016-10-09 02:51:13 UTC (rev 69689)
@@ -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 quering 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