[GRASS-SVN] r53977 - grass/trunk/lib/python/pygrass/raster

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Nov 23 03:52:49 PST 2012


Author: lucadelu
Date: 2012-11-23 03:52:49 -0800 (Fri, 23 Nov 2012)
New Revision: 53977

Modified:
   grass/trunk/lib/python/pygrass/raster/__init__.py
Log:
rewrite method to get pixel value from pair of coordinates for RasterNumpy

Modified: grass/trunk/lib/python/pygrass/raster/__init__.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/__init__.py	2012-11-23 11:49:14 UTC (rev 53976)
+++ grass/trunk/lib/python/pygrass/raster/__init__.py	2012-11-23 11:52:49 UTC (rev 53977)
@@ -24,6 +24,7 @@
 #
 from pygrass.errors import OpenError, must_be_open
 from pygrass.region import Region
+import pygrass.env as env
 
 #
 # import raster classes
@@ -650,7 +651,20 @@
         grasscore.try_remove(self.filename)
         self._fd = None
 
+    def get_value(self, point, region=None):
+        """This method returns the pixel value of a given pair of coordinates:
 
+        Parameters
+        ------------
+
+        point = pair of coordinates in tuple object
+        """
+        if not region:
+            region = Region()
+        x, y = env.coor2pixel(point.coords(), region)
+        return self[x][y]
+
+
 def random_map_only_columns(mapname, mtype, overwrite=True, factor=100):
     region = Region()
     random_map = RasterRow(mapname)



More information about the grass-commit mailing list