[GRASS-SVN] r67874 - in grass/trunk: gui/wxpython/gui_core gui/wxpython/mapdisp gui/wxpython/mapswipe lib/python/script lib/python/script/testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Feb 18 01:26:05 PST 2016
Author: lucadelu
Date: 2016-02-18 01:26:05 -0800 (Thu, 18 Feb 2016)
New Revision: 67874
Added:
grass/trunk/lib/python/script/testsuite/test_raster.py
Modified:
grass/trunk/gui/wxpython/gui_core/query.py
grass/trunk/gui/wxpython/mapdisp/frame.py
grass/trunk/gui/wxpython/mapswipe/frame.py
grass/trunk/lib/python/script/raster.py
Log:
python script: fixed raster_what function to work with or without localized labels [#2912], added also tests
Modified: grass/trunk/gui/wxpython/gui_core/query.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/query.py 2016-02-18 09:19:53 UTC (rev 67873)
+++ grass/trunk/gui/wxpython/gui_core/query.py 2016-02-18 09:26:05 UTC (rev 67874)
@@ -249,7 +249,8 @@
from grass.script import vector as gvect
from grass.script import raster as grast
testdata1 = grast.raster_what(map = ('elevation_shade at PERMANENT','landclass96'),
- coord = [(638509.051416,224742.348346)])
+ coord = [(638509.051416,224742.348346)],
+ localized=True)
testdata2 = gvect.vector_what(map=('firestations','bridges'),
coord=(633177.897487,221352.921257), distance=10)
Modified: grass/trunk/gui/wxpython/mapdisp/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/frame.py 2016-02-18 09:19:53 UTC (rev 67873)
+++ grass/trunk/gui/wxpython/mapdisp/frame.py 2016-02-18 09:26:05 UTC (rev 67874)
@@ -903,7 +903,8 @@
rastQuery = []
vectQuery = []
if rast:
- rastQuery = grass.raster_what(map=rast, coord=(east, north))
+ rastQuery = grass.raster_what(map=rast, coord=(east, north),
+ localized=True)
if vect:
encoding = UserSettings.Get(group='atm', key='encoding', subkey='value')
try:
Modified: grass/trunk/gui/wxpython/mapswipe/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapswipe/frame.py 2016-02-18 09:19:53 UTC (rev 67873)
+++ grass/trunk/gui/wxpython/mapswipe/frame.py 2016-02-18 09:26:05 UTC (rev 67874)
@@ -642,11 +642,13 @@
result = []
if rasters[0]:
- result.extend(grass.raster_what(map=rasters[0], coord=(east, north)))
+ result.extend(grass.raster_what(map=rasters[0], coord=(east, north),
+ localized=True))
if vectors[0]:
result.extend(grass.vector_what(map=vectors[0], coord=(east, north), distance=qdist))
if rasters[1]:
- result.extend(grass.raster_what(map=rasters[1], coord=(east, north)))
+ result.extend(grass.raster_what(map=rasters[1], coord=(east, north),
+ localized=True))
if vectors[1]:
result.extend(grass.vector_what(map=vectors[1], coord=(east, north), distance=qdist))
Modified: grass/trunk/lib/python/script/raster.py
===================================================================
--- grass/trunk/lib/python/script/raster.py 2016-02-18 09:19:53 UTC (rev 67873)
+++ grass/trunk/lib/python/script/raster.py 2016-02-18 09:26:05 UTC (rev 67874)
@@ -150,7 +150,7 @@
return p
-def raster_what(map, coord, env=None):
+def raster_what(map, coord, env=None, localized=False):
"""Interface to r.what
>>> raster_what('elevation', [[640000, 228000]])
@@ -188,7 +188,10 @@
if not ret:
return data
- labels = (_("value"), _("label"), _("color"))
+ if localized:
+ labels = (_("value"), _("label"), _("color"))
+ else:
+ labels = ('value', 'label', 'color')
for item in ret.splitlines():
line = item.split(sep)[3:]
for i, map_name in enumerate(map_list):
Added: grass/trunk/lib/python/script/testsuite/test_raster.py
===================================================================
--- grass/trunk/lib/python/script/testsuite/test_raster.py (rev 0)
+++ grass/trunk/lib/python/script/testsuite/test_raster.py 2016-02-18 09:26:05 UTC (rev 67874)
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Thu Feb 18 09:42:23 2016
+
+ at author: lucadelu
+"""
+
+from grass.gunittest.case import TestCase
+from grass.gunittest.main import test
+
+import grass.script as gscript
+
+
+class TestRaster(TestCase):
+ """Test raster functions"""
+
+ raster = 'testrasterscript'
+ region = gscript.region()
+ coords = (region['e'] - 1, region['n'] - 1)
+
+ @classmethod
+ def setUpClass(cls):
+ cls.runModule("r.mapcalc", expression="testrasterscript = 100",
+ overwrite=True)
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.runModule("g.remove", type='raster', name='testrasterscript',
+ flags='f')
+
+ def test_raster_what(self):
+ res = gscript.raster_what(self.raster, [self.coords])[0]
+ self.assertEquals(int(res[self.raster]['value']), 100)
+
+ res = gscript.raster_what(self.raster, [self.coords],
+ localized=True)[0]
+ self.assertEquals(int(res[self.raster][_('value')]), 100)
+
+ def test_raster_info(self):
+ res = gscript.raster_info(self.raster)
+ self.assertEquals(str(res['cols']), str(self.region['cols']))
+ self.assertEquals(str(res['north']), str(self.region['n']))
+
+if __name__ == '__main__':
+ test()
More information about the grass-commit
mailing list