Loading...
Searching...
No Matches
c_median.c
Go to the documentation of this file.
#include <grass/gis.h>
#include <grass/raster.h>
#include <grass/stats.h>
void c_median(DCELL *result, DCELL *values, int n, const void *closure G_UNUSED)
{
n = sort_cell(values, n);
if (n < 1)
Rast_set_d_null_value(result, 1);
else
*result = (values[(n - 1) / 2] + values[n / 2]) / 2;
}
void w_median(DCELL *result, DCELL (*values)[2], int n,
const void *closure G_UNUSED)
{
DCELL total;
int i;
DCELL k;
n = sort_cell_w(values, n);
if (n < 1) {
Rast_set_d_null_value(result, 1);
return;
}
total = 0.0;
for (i = 0; i < n; i++)
total += values[i][1];
k = 0.0;
for (i = 0; i < n; i++) {
k += values[i][1];
if (k >= total / 2)
break;
}
*result = values[i][0];
}
w_median
void w_median(DCELL *result, DCELL(*values)[2], int n, const void *closure)
Definition c_median.c:15
c_median
void c_median(DCELL *result, DCELL *values, int n, const void *closure)
Definition c_median.c:5
sort_cell
int sort_cell(DCELL *array, int n)
Definition sort_cell.c:27
sort_cell_w
int sort_cell_w(DCELL(*array)[2], int n)
Definition sort_cell.c:46