瀏覽代碼

add method to get pixel value from pair of coordinates

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@53976 15284696-431f-4ddb-bdfa-cd5b030d7da7
Luca Delucchi 12 年之前
父節點
當前提交
10b5ef26aa
共有 1 個文件被更改,包括 16 次插入0 次删除
  1. 16 0
      lib/python/pygrass/raster/abstract.py

+ 16 - 0
lib/python/pygrass/raster/abstract.py

@@ -23,6 +23,7 @@ import grass.lib.raster as libraster
 #
 import pygrass.env as env
 from pygrass.region import Region
+from pygrass.errors import must_be_open
 
 #
 # import raster classes
@@ -280,6 +281,21 @@ class RasterAbstractBase(object):
         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():