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

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


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

Modified:
   grass/trunk/lib/python/pygrass/raster/abstract.py
Log:
add method to get pixel value from pair of coordinates

Modified: grass/trunk/lib/python/pygrass/raster/abstract.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/abstract.py	2012-11-23 11:45:23 UTC (rev 53975)
+++ grass/trunk/lib/python/pygrass/raster/abstract.py	2012-11-23 11:49:14 UTC (rev 53976)
@@ -23,6 +23,7 @@
 #
 import pygrass.env as env
 from pygrass.region import Region
+from pygrass.errors import must_be_open
 
 #
 # import raster classes
@@ -280,6 +281,21 @@
         self._rows = libraster.Rast_window_rows()
         self._cols = libraster.Rast_window_cols()
 
+    @must_be_open
+    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)
+        line = self.get_row(int(x))
+        return line[int(y)]
+
     def has_cats(self):
         """Return True if the raster map has categories"""
         if self.exist():



More information about the grass-commit mailing list