21
21
#include <stdlib.h>
22
#include <grass/gis.h>
23
#include <grass/glocale.h>
24
22
#include "local_proto.h"
26
int get_stats(const char *name, const char *mapset, struct Cell_stats *statf)
24
int get_stats(struct maps_info *input_maps, struct Cell_stats *statf) {
29
26
int row, nrows, ncols;
32
if ((fd = G_open_cell_old(name, mapset)) < 0)
33
G_fatal_error(_("Unable to open raster map <%s>"),
34
G_fully_qualified_name(name, mapset));
36
cell = G_allocate_cell_buf();
37
nrows = G_window_rows();
38
ncols = G_window_cols();
40
G_init_cell_stats(statf);
41
G_verbose_message(_("Reading raster map <%s>..."),
42
G_fully_qualified_name(name, mapset));
43
for (row = 0; row < nrows; row++) {
44
G_percent(row, nrows, 2);
45
if (G_get_c_raster_row(fd, cell, row) < 0)
46
G_fatal_error(_("Unable to read raster map <%s> row %d"),
47
G_fully_qualified_name(name, mapset), row);
48
G_update_cell_stats(cell, ncols, statf);
30
Rast_init_cell_stats(statf);
32
for(i = 0; i < input_maps->num; i++) {
33
fd = Rast_open_old(input_maps->names[i], input_maps->mapsets[i]);
35
cell = Rast_allocate_c_buf();
36
nrows = Rast_window_rows();
37
ncols = Rast_window_cols();
39
G_verbose_message(_("(%i/%i) Reading raster map <%s>..."),
40
i + 1, input_maps->num,
41
G_fully_qualified_name(input_maps->names[i], input_maps->mapsets[i]));
43
for (row = 0; row < nrows; row++) {
44
G_percent(row, nrows, 2);
45
Rast_get_c_row(fd, cell, row);
46
Rast_update_cell_stats(cell, ncols, statf);
48
G_percent(row, nrows, 2);
50
G_percent(row, nrows, 2);
57
void get_fp_stats(const char *name, const char *mapset,
58
struct FP_stats *statf,
59
DCELL min, DCELL max, int geometric, int geom_abs)
62
int row, col, nrows, ncols;
56
void get_fp_stats(struct maps_info *input_maps,
57
struct FP_stats *statf,
58
DCELL min, DCELL max, int geometric, int geom_abs, int type) {
60
int row, col, depth, nrows, ncols, ndepths = 1;
65
if ((fd = G_open_cell_old(name, mapset)) < 0)
66
G_fatal_error("Unable to open raster map <%s>",
67
G_fully_qualified_name(name, mapset));
69
dcell = G_allocate_d_raster_buf();
70
nrows = G_window_rows();
71
ncols = G_window_cols();
73
statf->geometric = geometric;
74
statf->geom_abs = geom_abs;
77
if (statf->geometric) {
79
G_fatal_error(_("Unable to use logarithmic scaling if range includes zero"));
91
if (statf->geom_abs) {
92
double a = log(fabs(min) + 1);
93
double b = log(fabs(max) + 1);
94
int has_zero = min * max < 0;
104
statf->stats = G_calloc(statf->count + 1, sizeof(unsigned long));
107
G_verbose_message(_("Reading raster map <%s>..."),
108
G_fully_qualified_name(name, mapset));
109
for (row = 0; row < nrows; row++) {
110
G_percent(row, nrows, 2);
112
if (G_get_d_raster_row(fd, dcell, row) < 0)
113
G_fatal_error(_("Unable to read raster map <%s> row %d"),
114
G_fully_qualified_name(name, mapset), row);
116
for (col = 0; col < ncols; col++) {
120
if (G_is_d_null_value(&dcell[col]))
126
if (statf->geometric)
129
x = log(fabs(x) + 1);
131
i = (int) floor(statf->count * (x - statf->min) / (statf->max - statf->min));
137
G_percent(row, nrows, 2);
65
RASTER3D_Map *map3d = NULL;
67
statf->geometric = geometric;
68
statf->geom_abs = geom_abs;
71
if (statf->geometric) {
73
G_fatal_error(_("Unable to use logarithmic scaling if range includes zero"));
84
if (statf->geom_abs) {
85
double a = log(fabs(min) + 1);
86
double b = log(fabs(max) + 1);
87
int has_zero = min * max < 0;
97
statf->stats = G_calloc(statf->count + 1, sizeof (unsigned long));
100
/* Loop over all input maps */
101
for(i = 0; i < input_maps->num; i++) {
102
name = input_maps->names[i];
103
mapset = input_maps->mapsets[i];
105
if (type == RASTER_TYPE) {
106
fd = Rast_open_old(name, mapset);
107
dcell = Rast_allocate_d_buf();
108
nrows = Rast_window_rows();
109
ncols = Rast_window_cols();
111
/* Initiate the default settings */
112
Rast3d_init_defaults();
114
map3d = Rast3d_open_cell_old(name, mapset, RASTER3D_DEFAULT_WINDOW,
115
RASTER3D_TILE_SAME_AS_FILE, RASTER3D_USE_CACHE_DEFAULT);
118
Rast3d_fatal_error(_("Error opening 3d raster map"));
120
nrows = map3d->window.rows;
121
ncols = map3d->window.cols;
122
ndepths = map3d->window.depths;
125
G_verbose_message(_("(%i/%i) Reading map <%s>..."), i, input_maps->num,
126
G_fully_qualified_name(name, mapset));
128
for (depth = 0; depth < ndepths; depth++) {
129
for (row = 0; row < nrows; row++) {
130
G_percent(row, nrows, 2);
132
if (type == RASTER_TYPE)
133
Rast_get_d_row(fd, dcell, row);
135
for (col = 0; col < ncols; col++) {
139
if (type == RASTER_TYPE)
142
x = Rast3d_get_double(map3d, col, row, depth);
144
if (Rast_is_d_null_value(&x))
149
if (statf->geometric)
152
x = log(fabs(x) + 1);
154
j = (int) floor(statf->count * (x - statf->min) / (statf->max - statf->min));
161
G_percent(row, nrows, 2);
163
if (type == RASTER_TYPE) {