[GRASS-SVN] r47464 - grass-addons/grass7/imagery/i.topo.corr
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Aug 5 15:49:27 EDT 2011
Author: glynn
Date: 2011-08-05 12:49:27 -0700 (Fri, 05 Aug 2011)
New Revision: 47464
Modified:
grass-addons/grass7/imagery/i.topo.corr/local_proto.h
grass-addons/grass7/imagery/i.topo.corr/main.c
Log:
Don't translate key, gisprompt fields
Fix gisprompt format
Fix Gfile initialisation (include name)
Replace use of r.colors with library functions
Modified: grass-addons/grass7/imagery/i.topo.corr/local_proto.h
===================================================================
--- grass-addons/grass7/imagery/i.topo.corr/local_proto.h 2011-08-05 18:39:15 UTC (rev 47463)
+++ grass-addons/grass7/imagery/i.topo.corr/local_proto.h 2011-08-05 19:49:27 UTC (rev 47464)
@@ -11,7 +11,6 @@
{
int fd;
char name[GNAME_MAX];
- char *mapset;
void *rast;
RASTER_MAP_TYPE type;
} Gfile;
Modified: grass-addons/grass7/imagery/i.topo.corr/main.c
===================================================================
--- grass-addons/grass7/imagery/i.topo.corr/main.c 2011-08-05 18:39:15 UTC (rev 47463)
+++ grass-addons/grass7/imagery/i.topo.corr/main.c 2011-08-05 19:49:27 UTC (rev 47464)
@@ -17,6 +17,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <grass/gis.h>
#include <grass/raster.h>
#include <grass/glocale.h>
@@ -52,49 +53,46 @@
/* It defines the different parameters */
input = G_define_option();
- input->key = _("input");
+ input->key = "input";
input->type = TYPE_STRING;
input->required = NO;
input->multiple = YES;
- input->gisprompt = _("input,cell,raster");
+ input->gisprompt = "old,cell,raster";
input->description =
_("List of reflectance band maps to correct topographically");
output = G_define_option();
- output->key = _("output");
+ output->key = "output";
output->type = TYPE_STRING;
output->required = YES;
- output->gisprompt = _("output,cell,raster");
+ output->gisprompt = "new,cell,raster";
output->description =
_("File name of output (flag -i) or prefix of output files");
base = G_define_option();
- base->key = _("basemap");
+ base->key = "basemap";
base->type = TYPE_STRING;
base->required = YES;
- base->gisprompt = _("base,cell,raster");
+ base->gisprompt = "old,cell,raster";
base->description = _("Base map for analysis (elevation or ilumination)");
zeni = G_define_option();
- zeni->key = _("zenith");
+ zeni->key = "zenith";
zeni->type = TYPE_DOUBLE;
zeni->required = YES;
- zeni->gisprompt = _("zenith,float");
zeni->description = _("Solar zenith in degrees");
azim = G_define_option();
- azim->key = _("azimuth");
+ azim->key = "azimuth";
azim->type = TYPE_DOUBLE;
azim->required = NO;
- azim->gisprompt = _("azimuth,float");
azim->description = _("Solar azimuth in degrees (only if flag -i)");
metho = G_define_option();
- metho->key = _("method");
+ metho->key = "method";
metho->type = TYPE_STRING;
metho->required = NO;
metho->options = "cosine,minnaert,c-factor,percent";
- metho->gisprompt = _("topographic correction method");
metho->description = _("Topographic correction method");
metho->answer = "c-factor";
@@ -120,13 +118,15 @@
if (ilum->answer) {
azimuth = atof(azim->answer);
/* Warning: make buffers and output after set window */
- dem.fd = Rast_open_old(base->answer, "");
+ strcpy(dem.name, base->answer);
+ dem.fd = Rast_open_old(dem.name, "");
/* Set window to DEM file */
Rast_get_window(&window);
Rast_get_cellhd(dem.name, "", &hd_dem);
Rast_align_window(&window, &hd_dem);
Rast_set_window(&window);
/* Open and buffer of the output file */
+ strcpy(out.name, output->answer);
out.fd = Rast_open_new(output->answer, DCELL_TYPE);
out.rast = Rast_allocate_buf(out.type);
/* Open and buffer of the elevation file */
@@ -180,16 +180,17 @@
G_fatal_error(_("Illumination model is of CELL type"));
for (i = 0; input->answers[i] != NULL; i++) {
- G_message("\nBand %s: ", input->answers[i]);
+ G_message(_("Band %s: "), input->answers[i]);
/* Abre fichero de bandas y el de salida */
- band.fd = Rast_open_old(input->answers[i], "");
+ strcpy(band.name, input->answers[i]);
+ band.fd = Rast_open_old(band.name, "");
if (band.type != DCELL_TYPE) {
G_warning(_("Reflectance of <%s> is not of DCELL type - ignored."),
input->answers[i]);
Rast_close(band.fd);
continue;
}
- Rast_get_cellhd(band.name, band.mapset, &hd_band);
+ Rast_get_cellhd(band.name, "", &hd_band);
Rast_set_window(&hd_band); /* Antes de out_open y allocate para mismo tamaño */
/* ----- */
snprintf(bufname, 127, "%s.%s", output->answer,
@@ -210,11 +211,15 @@
Rast_command_history(&history);
Rast_write_history(out.name, &history);
- char command[300];
-
- /* TODO: better avoid system() */
- sprintf(command, "r.colors map=%s color=grey", out.name);
- system(command);
+ {
+ struct FPRange range;
+ DCELL min, max;
+ struct Colors grey;
+ Rast_read_fp_range(out.name, G_mapset(), &range);
+ Rast_get_fp_range_min_max(&range, &min, &max);
+ Rast_make_grey_scale_colors(&grey, min, max);
+ Rast_write_colors(out.name, G_mapset(), &grey);
+ }
}
Rast_close(dem.fd);
}
More information about the grass-commit
mailing list