static void transfer_to_cell_di(int fd, void *cell) { struct fileinfo *fcb = &R__.fileinfo[fd]; DCELL *work_buf = G_alloca(R__.rd_window.cols * sizeof(DCELL)); int i; transfer_to_cell_XX(fd, work_buf); for (i = 0; i < R__.rd_window.cols; i++) ((CELL *) cell)[i] = (fcb->col_map[i] == 0) ? 0 : Rast_quant_get_cell_value(&fcb->quant, work_buf[i]); G_freea(work_buf); }
/*! * \brief Looks up the category label for each raster value (DCELL). * * Looks up the category label for each raster value in the * <i>rast_row</i> and updates the marks for labels found. * * <b>Note:</b> Non-zero mark for i-th label stores the number of of * raster cells read so far which are labeled with i-th label and fall * into i-th data range. * * \param rast_row raster row to update stats * \param ncols number of columns * \param pcats pointer to Categories structure * * \return -1 on error * \return 1 on success */ int Rast_mark_cats(const void *rast_row, int ncols, struct Categories *pcats, RASTER_MAP_TYPE data_type) { size_t size = Rast_cell_size(data_type); CELL i; while (ncols-- > 0) { i = Rast_quant_get_cell_value(&pcats->q, Rast_get_d_value(rast_row, data_type)); if (Rast_is_c_null_value(&i)) continue; if (i > pcats->ncats) return -1; pcats->marks[i]++; rast_row = G_incr_void_ptr(rast_row, size); } return 1; }
/*! * \brief Get a raster category label * * This routine looks up category <i>rast</i> in the <i>pcats</i> * structure and returns a pointer to a string which is the label for * the category. A legal pointer is always returned. If the category * does not exist in <i>pcats</i>, then a pointer to the empty string * "" is returned. * * <b>Warning:</b> The pointer that is returned points to a hidden * static buffer. Successive calls to Rast_get_c_cat() overwrite this * buffer. * * \param rast cell value * \param pcats pointer to Categories structure * \param data_type map type (CELL, FCELL, DCELL) * * \return pointer to category label * \return "" if category is not found */ char *Rast_get_cat(void *rast, struct Categories *pcats, RASTER_MAP_TYPE data_type) { static char label[1024]; char *f, *l, *v; CELL i; DCELL val; float a[2]; char fmt[30], value_str[30]; if (Rast_is_null_value(rast, data_type)) { sprintf(label, "no data"); return label; } /* first search the list of labels */ *label = 0; val = Rast_get_d_value(rast, data_type); i = Rast_quant_get_cell_value(&pcats->q, val); G_debug(5, "Rast_get_cat(): val %lf found i %d", val, i); if (!Rast_is_c_null_value(&i) && i < pcats->ncats) { if (pcats->labels[i] != NULL) return pcats->labels[i]; return label; } /* generate the label */ if ((f = pcats->fmt) == NULL) return label; a[0] = (float)val *pcats->m1 + pcats->a1; a[1] = (float)val *pcats->m2 + pcats->a2; l = label; while (*f) { if (*f == '$') { f++; if (*f == '$') *l++ = *f++; else if (*f == '?') { f++; get_cond(&f, v = value_str, val); while (*v) *l++ = *v++; } else if (get_fmt(&f, fmt, &i)) { sprintf(v = value_str, fmt, a[i]); while (*v) *l++ = *v++; } else *l++ = '$'; } else { *l++ = *f++; } } *l = 0; return label; }