[GRASS-SVN] r36859 - grass/trunk/display/d.rast.num

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Apr 22 03:54:37 EDT 2009


Author: hcho
Date: 2009-04-22 03:54:36 -0400 (Wed, 22 Apr 2009)
New Revision: 36859

Modified:
   grass/trunk/display/d.rast.num/main.c
Log:
Added -a flag to align grids with raster cells

Modified: grass/trunk/display/d.rast.num/main.c
===================================================================
--- grass/trunk/display/d.rast.num/main.c	2009-04-22 07:43:10 UTC (rev 36858)
+++ grass/trunk/display/d.rast.num/main.c	2009-04-22 07:54:36 UTC (rev 36859)
@@ -60,8 +60,9 @@
     struct Colors colors;
     struct GModule *module;
     struct Option *opt1, *opt2, *opt3, *prec;
-    struct Flag *text_color;
+    struct Flag *text_color, *align;
     RASTER_MAP_TYPE map_type, inmap_type;
+    double t, b, l, r;
 
     /* Initialize the GIS calls */
     G_gisinit(argv[0]);
@@ -101,6 +102,10 @@
     prec->description =
 	_("Number of significant digits (floating point only)");
 
+    align = G_define_flag();
+    align->key = 'a';
+    align->description = _("Align grids with raster cells");
+
     text_color = G_define_flag();
     text_color->key = 'f';
     text_color->description = _("Get text color from cell color value");
@@ -133,9 +138,44 @@
 
     G_get_window(&window);
 
-    nrows = window.rows;
-    ncols = window.cols;
+    if (align->answer) {
+	struct Cell_head head, wind;
 
+	if (G_get_cellhd(map_name, "", &head) < 0)
+	    G_fatal_error(_("Unable to read header of raster map <%s>"), map_name);
+
+	G_copy(&wind, &head, sizeof(struct Cell_head));
+
+	/* expand window extent by one head resolution */
+	wind.west = head.west + head.ew_res * ((int)((window.west - head.west) / head.ew_res) - (window.west < head.west));
+	wind.east = head.east + head.ew_res * ((int)((window.east - head.east) / head.ew_res) + (window.west > head.west));
+	wind.south = head.south + head.ns_res * ((int)((window.south - head.south) / head.ns_res) - (window.south < head.south));
+	wind.north = head.north + head.ns_res * ((int)((window.north - head.north) / head.ns_res) + (window.north > head.north));
+
+	wind.ew_res = head.ew_res;
+	wind.ns_res = head.ns_res;
+	wind.rows = (wind.north - wind.south) / wind.ns_res;
+	wind.cols = (wind.east - wind.west) / wind.ew_res;
+
+	G_set_window(&wind);
+
+	nrows = wind.rows;
+	ncols = wind.cols;
+
+	t = (wind.north - window.north) * nrows / (wind.north - wind.south);
+	b = t + (window.north - window.south) * nrows / (wind.north - wind.south);
+	l = (window.west - wind.west) * ncols / (wind.east - wind.west);
+	r = l + (window.east - window.west) * ncols / (wind.east - wind.west);
+    } else {
+        nrows = window.rows;
+        ncols = window.cols;
+
+	t = 0;
+	b = nrows;
+	l = 0;
+	r = ncols;
+    }
+
     /* number of rows and cols in window */
 
     if ((nrows > 75) || (ncols > 75)) {
@@ -158,7 +198,7 @@
     if (R_open_driver() != 0)
 	G_fatal_error(_("No graphics device selected"));
 
-    D_setup2(0, 0, 0, nrows, 0, ncols);
+    D_setup2(0, 0, t, b, l, r);
 
     D_ns = fabs(D_get_u_to_d_yconv());
     D_ew = fabs(D_get_u_to_d_xconv());



More information about the grass-commit mailing list