2
* nearest.c - returns the nearest neighbor to a given
9
void p_nearest(struct cache *ibuffer, /* input buffer */
10
void *obufptr, /* ptr in output buffer */
11
int cell_type, /* raster map type of obufptr */
12
double *row_idx, /* row index in input matrix */
13
double *col_idx, /* column index in input matrix */
14
struct Cell_head *cellhd /* cell header of input layer */
17
int row, col; /* row/col of nearest neighbor */
20
/* cut indices to integer and get nearest cell */
21
/* the row_idx, col_idx correction for bilinear/bicubic does not apply here */
22
row = (int)floor(*row_idx);
23
col = (int)floor(*col_idx);
25
/* check for out of bounds - if out of bounds set NULL value */
26
if (row < 0 || row >= cellhd->rows || col < 0 || col >= cellhd->cols) {
27
Rast_set_null_value(obufptr, 1, cell_type);
31
cellp = CPTR(ibuffer, row, col);
33
if (Rast_is_d_null_value(cellp)) {
34
Rast_set_null_value(obufptr, 1, cell_type);
38
Rast_set_d_value(obufptr, *cellp, cell_type);