[GRASS-SVN] r53970 - grass/trunk/lib/python/pygrass/raster
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Nov 22 03:31:11 PST 2012
Author: zarch
Date: 2012-11-22 03:31:11 -0800 (Thu, 22 Nov 2012)
New Revision: 53970
Modified:
grass/trunk/lib/python/pygrass/raster/__init__.py
Log:
Add two functions to convert (north, east) into (row, col) and back
Modified: grass/trunk/lib/python/pygrass/raster/__init__.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/__init__.py 2012-11-22 10:29:12 UTC (rev 53969)
+++ grass/trunk/lib/python/pygrass/raster/__init__.py 2012-11-22 11:31:11 UTC (rev 53970)
@@ -36,6 +36,35 @@
from category import Category
from history import History
+
+def coor2pixel((north, east), region):
+ """Convert coordinates into a pixel row and col ::
+
+ >>> from pygrass import Region
+ >>> reg = Region()
+ >>> coor2pixel((reg.north, reg.west), reg)
+ (0.0, 0.0)
+ >>> coor2pixel((reg.south, reg.east), reg) == (reg.rows, reg.cols)
+ True
+ """
+ return (libraster.Rast_northing_to_row(north, region.c_region),
+ libraster.Rast_easting_to_col(east, region.c_region))
+
+
+def pixel2coor((row, col), region):
+ """Convert row and col of a pixel into a coordinates ::
+
+ >>> from pygrass import Region
+ >>> reg = Region()
+ >>> pixel2coor((0, 0), reg) == (reg.north, reg.west)
+ True
+ >>> pixel2coor((reg.rows, reg.cols), reg) == (reg.south, reg.east)
+ True
+ """
+ return (libraster.Rast_row_to_northing(row, region.c_region),
+ libraster.Rast_col_to_easting(col, region.c_region))
+
+
class RasterRow(RasterAbstractBase):
"""Raster_row_access": Inherits: "Raster_abstract_base" and implements
the default row access of the Rast library.
More information about the grass-commit
mailing list