52 #include <grass/gis.h>
53 #include <grass/vask.h>
54 #include <grass/edit.h>
66 long first_cat, last_cat;
75 CELL max_ind, max_cat, min_ind;
76 DCELL max_val, min_val;
79 (&cats->q, &min_val, &max_val, &min_ind, &max_ind) < 0)
82 max_cat = (CELL) max_val;
87 last_cat = (long)max_cat;
94 strcpy(msg1,
"The current value for the highest category");
95 sprintf(msg2,
"in [%s] is shown below", name);
96 V_line(3,
"If you need to change it, enter another value");
100 strcpy(msg1,
"Please enter the highest category value");
101 sprintf(msg2,
"for [%s]", name);
104 V_line(10,
" Highest Category:");
105 V_ques(&last_cat,
'l', 10, 28, 5);
117 sprintf(next_line,
"** Negative values not allowed **");
124 if (cats->ncats > 0 && min_val < 0)
125 first_cat = (CELL) min_val;
128 if (cats->title !=
NULL)
129 strcpy(title, cats->title);
131 startcat = first_cat;
132 sprintf(msg1,
"[%s] ENTER NEW CATEGORY NAMES FOR THESE CATEGORIES", name);
138 V_line(3,
"CAT NEW CATEGORY NAME");
141 V_ques(title,
's', 2, 8, 60);
145 last_cat + 1 ? startcat + NLINES : last_cat + 1;
148 for (incr = startcat; incr < endcat; incr++) {
149 atnum = incr - startcat;
150 strcpy(buff[atnum],
G_get_cat((CELL) incr, cats));
151 catnum[atnum] = incr;
152 V_const(&catnum[atnum],
'l', line, 1, 3);
153 V_ques(buff[atnum],
's', line, 5, 60);
159 if (endcat > last_cat)
163 sprintf(next_line,
"%*s%*s (of %ld)", 41,
164 "Next category ('end' to end): ", 5,
"", last_cat);
166 V_ques(next,
's', line, 41, 5);
173 for (incr = startcat; incr < endcat; incr++) {
174 atnum = incr - startcat;
176 if (strcmp(buff[atnum],
G_get_cat((CELL) incr, cats)) != 0)
177 G_set_cat((CELL) incr, buff[atnum], cats);
182 if (strcmp(next,
"end") == 0)
184 if (sscanf(next,
"%ld", &endcat) != 1)
187 if (endcat < first_cat)
190 if (endcat > last_cat) {
191 endcat = last_cat - NLINES + 1;
250 struct Categories old_cats;
251 struct FPRange fp_range;
254 G_fatal_error(
"can't read the floating point range for %s", name);
263 ncats = old_cats.ncats;
267 sprintf(msg1,
"There are no predefined fp ranges to label");
269 sprintf(msg1,
"There are %d predefined fp ranges to label", ncats);
270 sprintf(msg2,
"Enter the number of fp ranges you want to label");
274 V_ques(&ncats,
'l', 2, 48, 5);
283 if (old_cats.title !=
NULL)
284 strcpy(title, old_cats.title);
287 sprintf(msg1,
"The fp data in map %s ranges from %f to %f", name, dmin,
289 sprintf(msg2,
"[%s] ENTER NEW CATEGORY NAMES FOR THESE CATEGORIES", name);
296 V_line(4,
"FP RANGE NEW CATEGORY NAME");
298 V_ques(title,
's', 2, 8, 60);
300 endcat = startcat +
NLINES <= ncats ? startcat + NLINES : ncats;
303 for (incr = startcat; incr < endcat; incr++) {
304 atnum = incr - startcat;
305 if (incr < old_cats.ncats) {
307 lab_len = strlen(old_cats.labels[incr]);
310 strncpy(buff[atnum], old_cats.labels[incr], lab_len);
311 buff[atnum][lab_len] = 0;
313 &max_val[atnum], &tmp_cell, &tmp_cell);
317 strcpy(buff[atnum],
"");
318 max_val[atnum] = min_val[atnum] = 0;
321 V_ques(&min_val[atnum],
'd', line, 1, 8);
323 V_ques(&max_val[atnum],
'd', line, 10, 8);
324 V_ques(buff[atnum],
's', line, 19, 58);
334 sprintf(next_line,
"%*s%*s (of %d)", 41,
335 "Next range number ('end' to end): ", 5,
"", ncats);
337 V_ques(next,
's', line, 41, 5);
344 for (incr = startcat; incr < endcat; incr++) {
345 atnum = incr - startcat;
349 if (!(strcmp(buff[atnum],
"") == 0 &&
350 min_val[atnum] == 0. && max_val[atnum] == 0.))
357 if (strcmp(next,
"end") == 0)
359 if (sscanf(next,
"%ld", &endcat) != 1)
365 if (endcat > ncats) {
366 endcat = ncats - NLINES + 1;
char * G_mapset(void)
current mapset name
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
int E_edit_fp_cats(const char *name, struct Categories *cats)
void G_free(void *buf)
Free allocated memory.
char * G_store(const char *s)
Copy string to allocated memory.
int E_edit_cats(const char *name, struct Categories *cats, int option)
void V_clear(void)
Zero out prompt and answer arrays.
int V_line(int linenumber, const char *text)
int V_call(void)
Interact with the user.
int G_set_cat(CELL num, char *label, struct Categories *pcats)
set a category label
void G_quant_get_ith_rule(const struct Quant *q, int i, DCELL *dLow, DCELL *dHigh, CELL *cLow, CELL *cHigh)
char * G_get_cat(CELL num, struct Categories *pcats)
get a category label
int G_quant_get_limits(const struct Quant *q, DCELL *dMin, DCELL *dMax, CELL *cMin, CELL *cMax)
Extracts the minimum and maximum floating-point and integer values from all the rules (except the "in...
int G_init_raster_cats(const char *title, struct Categories *pcats)
Same as existing G_init_raster_cats() only ncats argument is missign. ncats has no meaning in new Cat...
int G_strip(char *buf)
Removes all leading and trailing white space from string.
int V_const(void *src, int var_type, int row, int col, int length)
int G_get_fp_range_min_max(const struct FPRange *range, DCELL *min, DCELL *max)
Extract the min/max from the range structure r. If the range structure has no defined min/max (first!...
int G_read_fp_range(const char *name, const char *mapset, struct FPRange *drange)
Read the floating point range file f_range. This file is written in binary using XDR format...
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int G_free_raster_cats(struct Categories *pcats)
Same as existing G_free_cats()
int V_ques(void *src, int var_type, int row, int col, int length)
int G_set_d_raster_cat(DCELL *rast1, DCELL *rast2, char *label, struct Categories *pcats)
Adds the label for range rast1 through rast2 in category structure pcats.
int G_copy_raster_cats(struct Categories *pcats_to, const struct Categories *pcats_from)
Allocates NEW space for quant rules and labels n pcats_to and copies all info from pcats_from cats to...
void V_intrpt_ok(void)
Allow CTRL-C.