[GRASS-SVN] r36858 - grass/trunk/display/d.rast.arrow

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Apr 22 03:43:10 EDT 2009


Author: hcho
Date: 2009-04-22 03:43:10 -0400 (Wed, 22 Apr 2009)
New Revision: 36858

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

Modified: grass/trunk/display/d.rast.arrow/main.c
===================================================================
--- grass/trunk/display/d.rast.arrow/main.c	2009-04-22 06:04:13 UTC (rev 36857)
+++ grass/trunk/display/d.rast.arrow/main.c	2009-04-22 07:43:10 UTC (rev 36858)
@@ -85,7 +85,10 @@
     struct GModule *module;
     struct Option *opt1, *opt2, *opt3, *opt4, *opt5,
 	*opt6, *opt7, *opt8, *opt9;
+    struct Flag *align;
 
+    double t, b, l, r;
+
     G_gisinit(argv[0]);
 
     module = G_define_module();
@@ -165,7 +168,11 @@
     opt8->answer = "1.0";
     opt8->description = _("Scale factor for arrows (magnitude map)");
 
+    align = G_define_flag();
+    align->key = 'a';
+    align->description = _("Align grids with raster cells");
 
+
     /* Check command line */
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
@@ -221,10 +228,45 @@
     /* Read in the map window associated with window */
     G_get_window(&window);
 
-    nrows = window.rows;
-    ncols = window.cols;
+    if (align->answer) {
+	struct Cell_head head, wind;
 
-    D_set_src(0, nrows, 0, ncols);
+	if (G_get_cellhd(layer_name, "", &head) < 0)
+	    G_fatal_error(_("Unable to read header of raster map <%s>"), layer_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;
+    }
+
+    D_set_src(t, b, l, r);
     D_update_conversions();
 
     /* figure out arrow scaling if using a magnitude map */



More information about the grass-commit mailing list