[GRASS-SVN] r52824 - grass/trunk/lib/python
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Aug 21 09:06:52 PDT 2012
Author: wenzeslaus
Date: 2012-08-21 09:06:50 -0700 (Tue, 21 Aug 2012)
New Revision: 52824
Modified:
grass/trunk/lib/python/vector.py
Log:
pythonlib: fixing #1522 (vector_what respects multiple layers)
Modified: grass/trunk/lib/python/vector.py
===================================================================
--- grass/trunk/lib/python/vector.py 2012-08-21 15:16:59 UTC (rev 52823)
+++ grass/trunk/lib/python/vector.py 2012-08-21 16:06:50 UTC (rev 52824)
@@ -24,6 +24,7 @@
import os
import types
+import copy
import __builtin__
from core import *
@@ -283,8 +284,17 @@
'Table': 'archsites', 'Type': 'Point', 'Id': 8}]
@endcode
- To query one vector map at more locations
+ To query one vector map with multiple layers (no additional parameters required)
@code
+ for q in grass.vector_what(map = 'some_map', coord = (596532.357143,4920486.21429), distance = 100.0):
+ print q['Map'], q['Layer'], q['Attributes']
+
+ new_bug_sites 1 {'str1': 'Beetle_site', 'GRASSRGB': '', 'cat': '80'}
+ new_bug_sites 2 {'cat': '80'}
+ @endcode
+
+ To query more vector maps at one location
+ @code
for q in grass.vector_what(map = ('archsites', 'roads'), coord = (595743, 4925281),
distance = 250):
print q['Map'], q['Attributes']
@@ -293,7 +303,7 @@
roads {'label': 'interstate', 'cat': '1'}
@endcode
- To query more vector maps at one location
+ To query one vector map at more locations
@code
for q in grass.vector_what(map = 'archsites', coord = [(595743, 4925281), (597950, 4918898)],
distance = 250):
@@ -348,6 +358,9 @@
return data
dict_attrb = None
+ dict_map = None
+ dict_layer = None
+ attr_pseudo_key = 'Attributes'
for item in ret.splitlines():
try:
key, value = __builtin__.map(lambda x: x.strip(), item.split('=', 1))
@@ -357,21 +370,42 @@
continue
if key == 'Map':
- dict_main = { 'Map' : value }
+ # attach the last one from the previous map
+ if dict_layer is not None:
+ dict_main = copy.copy(dict_map)
+ dict_main.update(dict_layer)
+ data.append(dict_main)
+ dict_map = { key : value }
+ dict_layer = None
dict_attrb = None
- data.append(dict_main)
- continue
+ 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
+ elif key == 'Key_column':
+ dict_layer[key] = value
+ dict_attrb = dict()
+ dict_layer[attr_pseudo_key] = dict_attrb
+ elif dict_attrb is not None:
+ dict_attrb[key] = value
+ elif dict_layer is not None:
+ if key == 'Category':
+ dict_layer[key] = int(value)
+ else:
+ dict_layer[key] = value
else:
- if dict_attrb is not None:
- dict_attrb[key] = value
- else:
- if key in ('Category', 'Layer', 'Id'):
- dict_main[key] = int(value)
- else:
- dict_main[key] = value
- if key == 'Key_column':
- # skip attributes
- dict_attrb = dict()
- dict_main['Attributes'] = dict_attrb
+ dict_map[key] = value
+ # TODO: there are some keys which has non-string values
+ # examples: Sq_Meters, Hectares, Acres, Sq_Miles
+ # attach the last one
+ if dict_layer is not None:
+ dict_main = copy.copy(dict_map)
+ dict_main.update(dict_layer)
+ data.append(dict_main)
+
return data
More information about the grass-commit
mailing list