[GRASS-SVN] r50835 - grass-addons/grass7/imagery/i.topo.corr
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Feb 16 06:12:59 EST 2012
Author: mmetz
Date: 2012-02-16 03:12:59 -0800 (Thu, 16 Feb 2012)
New Revision: 50835
Modified:
grass-addons/grass7/imagery/i.topo.corr/correction.c
grass-addons/grass7/imagery/i.topo.corr/main.c
Log:
i.topo.corr: various bug fixes
Modified: grass-addons/grass7/imagery/i.topo.corr/correction.c
===================================================================
--- grass-addons/grass7/imagery/i.topo.corr/correction.c 2012-02-16 09:57:01 UTC (rev 50834)
+++ grass-addons/grass7/imagery/i.topo.corr/correction.c 2012-02-16 11:12:59 UTC (rev 50835)
@@ -40,29 +40,19 @@
for (row = 0; row < nrows; row++) {
G_percent(row, nrows, 2);
- Rast_get_row(band->fd, band->rast, row, DCELL_TYPE);
+ Rast_get_row(band->fd, band->rast, row, band->type);
Rast_get_row(cosi->fd, cosi->rast, row, cosi->type);
+
+ pref = band->rast;
+ pcos = cosi->rast;
for (col = 0; col < ncols; col++) {
- switch (cosi->type) {
- case FCELL_TYPE:
- pcos = (void *)((FCELL *) cosi->rast + col);
- cos_i = (double)((FCELL *) cosi->rast)[col];
- break;
- case DCELL_TYPE:
- pcos = (void *)((DCELL *) cosi->rast + col);
- cos_i = (double)((DCELL *) cosi->rast)[col];
- break;
- default:
- pcos = NULL;
- cos_i = 0.;
- break;
- }
- pref = (void *)((DCELL *) band->rast + col);
+
+ cos_i = Rast_get_d_value(pcos, cosi->type);
- if (!Rast_is_null_value(pref, DCELL_TYPE) &&
+ if (!Rast_is_null_value(pref, band->type) &&
!Rast_is_null_value(pcos, cosi->type)) {
- ref_i = (double)*((DCELL *) pref);
+ ref_i = Rast_get_d_value(pref, band->type);
switch (method) {
case MINNAERT:
if (cos_i > 0. && cos_z > 0. && ref_i > 0.) {
@@ -88,6 +78,8 @@
break;
}
}
+ pref = G_incr_void_ptr(pref, Rast_cell_size(band->type));
+ pcos = G_incr_void_ptr(pcos, Rast_cell_size(cosi->type));
}
}
m = (n == 0.) ? 1. : (n * sxy - sx * sy) / (n * sxx - sx * sx);
@@ -121,30 +113,19 @@
Rast_get_row(band->fd, band->rast, row, band->type);
Rast_get_row(cosi->fd, cosi->rast, row, cosi->type);
+ pref = band->rast;
+ pcos = cosi->rast;
+
+ Rast_set_null_value(out->rast, ncols, DCELL_TYPE);
+
for (col = 0; col < ncols; col++) {
- switch (cosi->type) {
- case FCELL_TYPE:
- pcos = (void *)((FCELL *) cosi->rast + col);
- cos_i = (double)*((FCELL *) pcos);
- break;
- case DCELL_TYPE:
- pcos = (void *)((DCELL *) cosi->rast + col);
- cos_i = (double)*((DCELL *) pcos);
- break;
- default:
- pcos = NULL;
- cos_i = 0.;
- break;
- }
- pref = (void *)((DCELL *) band->rast + col);
- if (pcos == NULL ||
- Rast_is_null_value(pref, DCELL_TYPE) ||
- Rast_is_null_value(pcos, cosi->type)) {
- Rast_set_null_value((DCELL *) out->rast + col, 1, DCELL_TYPE);
- }
- else {
- ref_i = (double)*((DCELL *) pref);
+ cos_i = Rast_get_d_value(pcos, cosi->type);
+
+ if (!Rast_is_null_value(pref, band->type) &&
+ !Rast_is_null_value(pcos, cosi->type)) {
+
+ ref_i = Rast_get_d_value(pref, band->type);
((DCELL *) out->rast)[col] =
(DCELL) (ref_i * pow((cos_z + cka) / (cos_i + ckb), kk));
G_debug(3,
@@ -152,6 +133,8 @@
ref_i, cka, cos_i, ckb, kk,
((DCELL *) out->rast)[col]);
}
+ pref = G_incr_void_ptr(pref, Rast_cell_size(band->type));
+ pcos = G_incr_void_ptr(pcos, Rast_cell_size(cosi->type));
}
Rast_put_row(out->fd, out->rast, out->type);
}
Modified: grass-addons/grass7/imagery/i.topo.corr/main.c
===================================================================
--- grass-addons/grass7/imagery/i.topo.corr/main.c 2012-02-16 09:57:01 UTC (rev 50834)
+++ grass-addons/grass7/imagery/i.topo.corr/main.c 2012-02-16 11:12:59 UTC (rev 50835)
@@ -30,8 +30,6 @@
struct GModule *module;
struct Cell_head hd_band, hd_dem, window;
- char bufname[128]; /* TODO: use GNAME_MAX? */
-
int i;
struct Option *base, *output, *input, *zeni, *azim, *metho;
struct Flag *ilum;
@@ -101,6 +99,7 @@
(_("Reflectance maps are necessary to make topographic correction"));
zenith = atof(zeni->answer);
+ out.type = DCELL_TYPE;
/* Evaluate only cos_i raster file */
/* i.topo.corr -i out=cosi.on07 base=SRTM_v2 zenith=33.3631 azimuth=59.8897 */
@@ -109,18 +108,18 @@
azimuth = atof(azim->answer);
/* Warning: make buffers and output after set window */
strcpy(dem.name, base->answer);
- dem.fd = Rast_open_old(dem.name, "");
- dem.type = Rast_get_map_type(dem.fd);
/* Set window to DEM file */
Rast_get_window(&window);
Rast_get_cellhd(dem.name, "", &hd_dem);
Rast_align_window(&window, &hd_dem);
+ dem.fd = Rast_open_old(dem.name, "");
+ dem.type = Rast_get_map_type(dem.fd);
/* 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 */
- dem.rast = Rast_allocate_buf(DCELL_TYPE);
+ dem.rast = Rast_allocate_buf(dem.type);
eval_cosi(&out, &dem, zenith, azimuth);
/* Close files, buffers, and write history */
G_free(dem.rast);
@@ -153,7 +152,8 @@
G_fatal_error(_("Invalid method: %s"), metho->answer);
dem.fd = Rast_open_old(base->answer, "");
- dem.type= Rast_open_old(base->answer, "");
+ dem.type = Rast_get_map_type(dem.fd);
+ Rast_close(dem.fd);
if (dem.type == CELL_TYPE)
G_fatal_error(_("Illumination model is of CELL type"));
@@ -161,6 +161,8 @@
G_message(_("Band %s: "), input->answers[i]);
/* Abre fichero de bandas y el de salida */
strcpy(band.name, input->answers[i]);
+ Rast_get_cellhd(band.name, "", &hd_band);
+ Rast_set_window(&hd_band); /* Antes de out_open y allocate para mismo tamaño */
band.fd = Rast_open_old(band.name, "");
band.type = Rast_get_map_type(band.fd);
if (band.type != DCELL_TYPE) {
@@ -169,12 +171,11 @@
Rast_close(band.fd);
continue;
}
- 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,
+ dem.fd = Rast_open_old(base->answer, "");
+ snprintf(out.name, GNAME_MAX - 1, "%s.%s", output->answer,
input->answers[i]);
- out.fd = Rast_open_new(bufname, DCELL_TYPE);
+ out.fd = Rast_open_new(out.name, DCELL_TYPE);
out.rast = Rast_allocate_buf(out.type);
band.rast = Rast_allocate_buf(band.type);
dem.rast = Rast_allocate_buf(dem.type);
@@ -182,6 +183,7 @@
eval_tcor(method, &out, &dem, &band, zenith);
/* ----- */
G_free(dem.rast);
+ Rast_close(dem.fd);
G_free(band.rast);
Rast_close(band.fd);
G_free(out.rast);
@@ -194,13 +196,13 @@
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);
}
exit(EXIT_SUCCESS);
More information about the grass-commit
mailing list