Просмотр исходного кода

display map data units, if known

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@60106 15284696-431f-4ddb-bdfa-cd5b030d7da7
Hamish Bowman 11 лет назад
Родитель
Сommit
ac8677705b
2 измененных файлов с 35 добавлено и 10 удалено
  1. 3 0
      display/d.legend/d.legend.html
  2. 32 10
      display/d.legend/main.c

+ 3 - 0
display/d.legend/d.legend.html

@@ -70,6 +70,9 @@ side the smoothed gradient legend, note that the statistics are calculated
 on the <i>current computational region</i> settings set by <em>g.region</em>.
 The default <b>range</b> however covers the entire natural bounds of the input map.
 If the histogram appears empty, check your region settings.
+<p>
+If the raster map's <i>units</i> metadata has been set with the
+<em>r.support</em> module then it will be displayed along side the legend.
 
 
 <h2>SEE ALSO</h2>

+ 32 - 10
display/d.legend/main.c

@@ -40,22 +40,18 @@ int main(int argc, char **argv)
     char buff[512];
     char *map_name;
     int maptype;
-    int black;
+    int black, white, color;
     int cats_num;
-    int color;
     int cur_dot_row;
     int do_cats;
     int dots_per_line;
-    int thin;
     int i, j, k;
-    int lines, steps;
+    int thin, lines, steps;
     int fp;
     double t, b, l, r;
     int hide_catnum, hide_catstr, hide_nodata, do_smooth;
     char *cstr;
-    int white;
-    double x_box[5];
-    double y_box[5];
+    double x_box[5], y_box[5];
     struct Categories cats;
     struct Colors colors;
     struct GModule *module;
@@ -79,6 +75,7 @@ int main(int argc, char **argv)
     double *catlist, maxCat;
     int catlistCount, use_catlist;
     double fontsize;
+    char *units;
 
 
     /* Initialize the GIS calls */
@@ -88,7 +85,7 @@ int main(int argc, char **argv)
     G_add_keyword(_("display"));
     G_add_keyword(_("cartography"));
     module->description =
-	_("Displays a legend for a raster map in the active frame "
+	_("Displays a legend for a raster map (2 or 3D) in the active frame "
 	  "of the graphics monitor.");
 
     opt_rast2d = G_define_standard_option(G_OPT_R_MAP);
@@ -776,7 +773,7 @@ int main(int argc, char **argv)
 	    if (color)
 		D_text(buff);
 
-	}			/*for */
+	}	/* for */
 
 	lleg = y1 - y0;
 	wleg = x1 - x0;
@@ -804,6 +801,31 @@ int main(int argc, char **argv)
 	D_stroke();
 
 
+	/* print units label, if present */
+	if (maptype == MAP_TYPE_RASTER2D)
+	    units = Rast_read_units(map_name, "");
+	else
+	    units = "";
+/* FIXME: does the raster3d really need to be opened to read the units?
+	    units = Rast3d_get_unit(map_fid); */
+
+	if (!units)
+	    units = "";
+
+	if(strlen(units)) {
+	    D_use_color(color);
+	    /* D_text_size() should be already set */
+	    if (horiz)
+		D_pos_abs((x0 + x1)/2. - (strlen(units) * txsiz * 0.81)/2,
+			  y1 + (txsiz * 3));
+	    else
+		D_pos_abs(x1 - 4, y0 - (txsiz * 1.75));
+
+	    D_text(units);
+	}
+
+
+	/* display sidebar histogram, if requested */
 	if (histo->answer) {
 	    if (opt_range->answer != NULL)
 		G_warning(_("Histogram constrained by range not yet implemented"));
@@ -813,7 +835,7 @@ int main(int argc, char **argv)
 	}
 
     }
-    else {			/* non FP, no smoothing */
+    else {	/* non FP, no smoothing */
 
 	int true_l, true_r;
 	double txsiz;