int main( int argc, char **argv ) { char *mapset; char *name; int fp; struct GModule *module; struct Option *map; struct Option *win; struct Cell_head window; /* Initialize the GIS calls */ G_gisinit( argv[0] ); module = G_define_module(); module->keywords = ( "display, raster" ); module->description = ( "Output raster map layers in a format suitable for display in QGIS" ); map = G_define_standard_option( G_OPT_R_MAP ); map->description = ( "Raster map to be displayed" ); win = G_define_option(); win->key = "window"; win->type = TYPE_DOUBLE; win->multiple = YES; win->description = "xmin,ymin,xmax,ymax,ncols,nrows"; if ( G_parser( argc, argv ) ) exit( EXIT_FAILURE ); name = map->answer; /* Make sure map is available */ mapset = G_find_cell2( name, "" ); if ( mapset == NULL ) G_fatal_error(( "Raster map <%s> not found" ), name ); /* It can happen that GRASS data set is 'corrupted' and zone differs in WIND and * cellhd, and G_open_cell_old fails, so it is better to read window from map */ /* G_get_window( &window ); */ G_get_cellhd( name, mapset, &window ); window.west = atof( win->answers[0] ); window.south = atof( win->answers[1] ); window.east = atof( win->answers[2] ); window.north = atof( win->answers[3] ); window.cols = atoi( win->answers[4] ); window.rows = atoi( win->answers[5] ); G_adjust_Cell_head( &window, 1, 1 ); G_set_window( &window ); fp = G_raster_map_is_fp( name, mapset ); /* use DCELL even if the map is FCELL */ if ( fp ) display( name, mapset, DCELL_TYPE ); else display( name, mapset, CELL_TYPE ); exit( EXIT_SUCCESS ); }
int G_read_colors(const char *name, const char *mapset, struct Colors *colors) { int fp; char buf[GNAME_MAX]; char *err; char xname[GNAME_MAX]; struct Range range; struct FPRange drange; CELL min, max; DCELL dmin, dmax; fp = G_raster_map_is_fp(name, mapset); G_init_colors(colors); strcpy(xname, name); mapset = G_find_cell(xname, mapset); name = xname; if (fp) G_mark_colors_as_fp(colors); /* first look for secondary color table in current mapset */ sprintf(buf, "colr2/%s", mapset); if (read_colors(buf, name, G_mapset(), colors) >= 0) return 1; /* now look for the regular color table */ switch (read_colors("colr", name, mapset, colors)) { case -2: if (!fp) { if (G_read_range(name, mapset, &range) >= 0) { G_get_range_min_max(&range, &min, &max); if (!G_is_c_null_value(&min) && !G_is_c_null_value(&max)) G_make_rainbow_colors(colors, min, max); return 0; } } else { if (G_read_fp_range(name, mapset, &drange) >= 0) { G_get_fp_range_min_max(&drange, &dmin, &dmax); if (!G_is_d_null_value(&dmin) && !G_is_d_null_value(&dmax)) G_make_rainbow_fp_colors(colors, dmin, dmax); return 0; } } err = "missing"; break; case -1: err = "invalid"; break; default: return 1; } G_warning(_("color support for [%s] in mapset [%s] %s"), name, mapset, err); return -1; }
int main(int argc, char **argv) { int overwrite; int interactive; int remove; int have_colors; struct Colors colors, colors_tmp; struct Cell_stats statf; int have_stats = 0; struct FPRange range; DCELL min, max; char *name, *mapset; char *style, *cmap, *cmapset; char *rules; int fp; struct GModule *module; struct { struct Flag *r, *w, *l, *g, *a, *e, *i, *q, *n; } flag; struct { struct Option *map, *colr, *rast, *rules; } opt; G_gisinit(argv[0]); module = G_define_module(); module->keywords = _("raster, color table"); module->description = _("Creates/modifies the color table associated with a raster map layer."); opt.map = G_define_standard_option(G_OPT_R_MAP); opt.map->required = NO; opt.map->guisection = _("Required"); scan_rules(); opt.colr = G_define_option(); opt.colr->key = "color"; opt.colr->key_desc = "style"; opt.colr->type = TYPE_STRING; opt.colr->required = NO; opt.colr->options = rules_list(); opt.colr->description = _("Type of color table"); opt.colr->descriptions = rules_descriptions(); opt.colr->guisection = _("Colors"); opt.rast = G_define_option(); opt.rast->key = "raster"; opt.rast->type = TYPE_STRING; opt.rast->required = NO; opt.rast->gisprompt = "old,cell,raster"; opt.rast->description = _("Raster map name from which to copy color table"); opt.rules = G_define_standard_option(G_OPT_F_INPUT); opt.rules->key = "rules"; opt.rules->required = NO; opt.rules->description = _("Path to rules file (\"-\" to read rules from stdin)"); opt.rules->guisection = _("Colors"); flag.r = G_define_flag(); flag.r->key = 'r'; flag.r->description = _("Remove existing color table"); flag.w = G_define_flag(); flag.w->key = 'w'; flag.w->description = _("Only write new color table if one doesn't already exist"); flag.l = G_define_flag(); flag.l->key = 'l'; flag.l->description = _("List available rules then exit"); flag.n = G_define_flag(); flag.n->key = 'n'; flag.n->description = _("Invert colors"); flag.n->guisection = _("Colors"); flag.g = G_define_flag(); flag.g->key = 'g'; flag.g->description = _("Logarithmic scaling"); flag.g->guisection = _("Colors"); flag.a = G_define_flag(); flag.a->key = 'a'; flag.a->description = _("Logarithmic-absolute scaling"); flag.a->guisection = _("Colors"); flag.e = G_define_flag(); flag.e->key = 'e'; flag.e->description = _("Histogram equalization"); flag.e->guisection = _("Colors"); flag.i = G_define_flag(); flag.i->key = 'i'; flag.i->description = _("Enter rules interactively"); /* please, remove before GRASS 7 released */ flag.q = G_define_flag(); flag.q->key = 'q'; flag.q->description = _("Run quietly"); if (G_parser(argc, argv)) exit(EXIT_FAILURE); /* please, remove before GRASS 7 released */ if (flag.q->answer) { G_putenv("GRASS_VERBOSE", "0"); G_warning(_("The '-q' flag is superseded and will be removed " "in future. Please use '--quiet' instead.")); } if (flag.l->answer) { list_rules(); return EXIT_SUCCESS; } overwrite = !flag.w->answer; interactive = flag.i->answer; remove = flag.r->answer; name = opt.map->answer; style = opt.colr->answer; cmap = opt.rast->answer; rules = opt.rules->answer; if (!name) G_fatal_error(_("No raster map specified")); if (!cmap && !style && !rules && !interactive && !remove) G_fatal_error(_("One of \"-i\" or \"-r\" or options \"color\", \"rast\" or \"rules\" must be specified!")); if (interactive && (style || rules || cmap)) G_fatal_error(_("Interactive mode is incompatible with \"color\", \"rules\", and \"raster\" options")); if ((style && (cmap || rules)) || (cmap && rules)) { if ((style && rules && !cmap) && strcmp(style, "rules") == 0) style = NULL; else G_fatal_error( _("\"color\", \"rules\", and \"raster\" options are mutually exclusive")); } /* handle rules="-" (from stdin) by translating that to colors=rules */ /* this method should not be ported to GRASS 7 verbatim, as color=rules DNE */ if (rules && strcmp(rules, "-") == 0) { style = G_store("rules"); rules = NULL; } if (flag.g->answer && flag.a->answer) G_fatal_error(_("-g and -a flags are mutually exclusive")); mapset = G_find_cell2(name, ""); if (mapset == NULL) G_fatal_error(_("Raster map <%s> not found"), name); if (remove) { int stat = G_remove_colors(name, mapset); if (stat < 0) G_fatal_error(_("Unable to remove color table of raster map <%s>"), name); if (stat == 0) G_warning(_("Color table of raster map <%s> not found"), name); return EXIT_SUCCESS; } G_suppress_warnings(1); have_colors = G_read_colors(name, mapset, &colors); /*if (have_colors >= 0) G_free_colors(&colors); */ if (have_colors > 0 && !overwrite) { G_warning(_("Color table exists. Exiting.")); exit(EXIT_FAILURE); } G_suppress_warnings(0); fp = G_raster_map_is_fp(name, mapset); G_read_fp_range(name, mapset, &range); G_get_fp_range_min_max(&range, &min, &max); if (interactive) { if (!read_color_rules(stdin, &colors, min, max, fp)) exit(EXIT_FAILURE); } else if (style) { /* * here the predefined color-table color-styles are created by GRASS library calls. */ if (strcmp(style, "random") == 0) { if (fp) G_fatal_error(_("Color table 'random' is not supported for floating point raster map")); G_make_random_colors(&colors, (CELL) min, (CELL) max); } else if (strcmp(style, "grey.eq") == 0) { if (fp) G_fatal_error(_("Color table 'grey.eq' is not supported for floating point raster map")); if (!have_stats) have_stats = get_stats(name, mapset, &statf); G_make_histogram_eq_colors(&colors, &statf); } else if (strcmp(style, "grey.log") == 0) { if (fp) G_fatal_error(_("Color table 'grey.log' is not supported for floating point raster map")); if (!have_stats) have_stats = get_stats(name, mapset, &statf); G_make_histogram_log_colors(&colors, &statf, (CELL) min, (CELL) max); } else if (strcmp(style, "rules") == 0) { if (!read_color_rules(stdin, &colors, min, max, fp)) exit(EXIT_FAILURE); } else if (find_rule(style)) G_make_fp_colors(&colors, style, min, max); else G_fatal_error(_("Unknown color request '%s'"), style); } else if (rules) { if (!G_load_fp_colors(&colors, rules, min, max)) { /* for backwards compatibility try as std name; remove for GRASS 7 */ char path[GPATH_MAX]; /* don't bother with native dirsep as not needed for backwards compatibility */ sprintf(path, "%s/etc/colors/%s", G_gisbase(), rules); if (!G_load_fp_colors(&colors, path, min, max)) G_fatal_error(_("Unable to load rules file <%s>"), rules); } } else { /* use color from another map (cmap) */ cmapset = G_find_cell2(cmap, ""); if (cmapset == NULL) G_fatal_error(_("Raster map <%s> not found"), cmap); if (G_read_colors(cmap, cmapset, &colors) < 0) G_fatal_error(_("Unable to read color table for raster map <%s>"), cmap); } if (fp) G_mark_colors_as_fp(&colors); if (flag.n->answer) G_invert_colors(&colors); if (flag.e->answer) { if (fp) { struct FP_stats fpstats; get_fp_stats(name, mapset, &fpstats, min, max, flag.g->answer, flag.a->answer); G_histogram_eq_colors_fp(&colors_tmp, &colors, &fpstats); } else { if (!have_stats) have_stats = get_stats(name, mapset, &statf); G_histogram_eq_colors(&colors_tmp, &colors, &statf); } colors = colors_tmp; } if (flag.g->answer) { G_log_colors(&colors_tmp, &colors, 100); colors = colors_tmp; } if (flag.a->answer) { G_abs_log_colors(&colors_tmp, &colors, 100); colors = colors_tmp; } if (fp) G_mark_colors_as_fp(&colors); if (G_write_colors(name, mapset, &colors) >= 0) G_message(_("Color table for raster map <%s> set to '%s'"), name, interactive ? "rules" : style ? style : rules ? rules : cmap); exit(EXIT_SUCCESS); }
int main (int argc, char *argv[]) { struct GModule *module; struct Option *map; /* raster map to work on */ struct Option *sites; /* output map to write */ struct Option *mode; /* Categorisation mode */ struct Option *min; /* range of values to categorise ... */ struct Option *max; /* .. anything outside will be NULL in output */ struct Option *logfile; /* log output to this file instead of stdout */ struct Option *precision; /* decimal digits precision for log file */ struct Option *cachesize; struct Flag *null; /* also count NULL values? */ struct Flag *all; /* disregard region when reporting total percentages */ struct Flag *zeroskip; /* also show categories with 0 count? */ struct Flag *uncat; /* also show cells outside category range? */ struct Flag *background; /* show background distribution? */ struct Flag *gain; /* calculate Kvamme's gain for each category? */ struct Flag *quiet; /* no status display on screen */ char *mapset; int show_progress = 1; /* enable progress display by default */ /* these vars are used to store information about the input map */ int cats; /* number of categories in input map */ long null_count; /* number of NULL cells */ long nocat_count; /* number of cells that do not fall into the category range [0 .. n] */ /* use to create command line for r.categorize call */ char *sysstr, *tmpfile, *input_map; int error; sysstr = NULL; tmpfile = NULL; /* setup some basic GIS stuff */ G_gisinit (argv[0]); module = G_define_module (); module->description = "Analyses distribution of vector sample over a raster map"; /* do not pause after a warning message was displayed */ G_sleep_on_error (0); /* DEFINE OPTIONS AND FLAGS */ /* raster map to sample */ map = G_define_standard_option (G_OPT_R_INPUT); map->key = "raster"; map->type = TYPE_STRING; map->required = YES; map->description = "Raster map to sample"; /* site map for sampling positions */ sites = G_define_standard_option (G_OPT_V_INPUT); sites->key = "positions"; sites->type = TYPE_STRING; sites->required = YES; sites->description = "Vector map with sampling positions"; /* Categorisation mode */ mode = G_define_option (); mode->key = "mode"; mode->type = TYPE_STRING; mode->required = NO; mode->description = "Categorisation mode (see manual)"; /* min raster value to categorise */ min = G_define_option (); min->key = "min"; min->type = TYPE_DOUBLE; min->required = NO; min->description = "Minimum value to include in categorisation"; /* max raster value to categorise */ max = G_define_option (); max->key = "max"; max->type = TYPE_DOUBLE; max->required = NO; max->description = "Maximum value to include in categorisation."; /* optional name of logfile */ logfile = G_define_option (); logfile->key = "logfile"; logfile->type = TYPE_DOUBLE; logfile->required = NO; logfile->description = "Name of ASCII logfile, if desired."; /* optional number of decimal digitis to store in logfile/show on screen */ precision = G_define_option (); precision->key = "precision"; precision->type = TYPE_DOUBLE; precision->required = NO; precision->answer = "2"; precision->description = "Number of decimal digits for statistics/logfile"; /* number of lines to store in cache */ cachesize = G_define_option (); cachesize->key = "cachesize"; cachesize->type = TYPE_INTEGER; cachesize->answer = "-1"; cachesize->required = NO; cachesize->description = "Number of raster rows to store in cache (-1 for auto)"; null = G_define_flag (); null->key = 'n'; null->description = "Include NULL cells in report."; uncat = G_define_flag (); uncat->key = 'u'; uncat->description = "Include uncategorised cells in statistics."; all = G_define_flag (); all->key = 'a'; all->description = "Disregard region setting for counts."; zeroskip = G_define_flag (); zeroskip->key = 'z'; zeroskip->description = "Also show categories with zero count/percentage."; background = G_define_flag (); background->key = 'b'; background->description = "Show background distribution of categories in raster input map."; gain = G_define_flag (); gain->key = 'g'; gain->description = "Calculate Kvamme's Gain Factor for each category."; quiet = G_define_flag (); quiet->key = 'q'; quiet->description = "Quiet operation: do not show progress display."; /* parse command line */ if (G_parser (argc, argv)) { exit (-1); } /* check for 'quiet' flag */ if ( quiet->answer ) { show_progress = 0; } PROGNAME = argv[0]; /* copy the 'map' option string to another buffer and use that */ /* from now on. We do this because we might want to manipulate */ /* that string and that is dangerous with GRASS Option->answer strings! */ input_map = G_calloc (255, sizeof (char)); G_strcpy (input_map, map->answer); mapset = G_calloc (255, sizeof (char)); /* check if input map is a fully categorised raster map */ mapset = G_find_cell (input_map,""); if ( mapset == NULL) { G_fatal_error ("The input map does not exist in the current database."); } if ( mode->answer == NULL ) { cats = GT_get_stats (input_map,mapset,&null_count, &nocat_count, show_progress); if ( cats < 0 ) { G_fatal_error ("Could not stat input map. Do you have read access?"); } if ( ((cats == 0) && (mode->answer==NULL)) ) { G_fatal_error ("No categories defined in input map.\nPlease specify a mode to create a fully classified map."); } } /* a classification mode was given: call r.categorize and save output in a tmp file */ if ( mode->answer != NULL ) { srand ((unsigned long) time(NULL)); tmpfile = G_calloc (255, sizeof(char)); sysstr = G_calloc (255, sizeof(char)); /* create tmp file name from current PID and system time */ sprintf (tmpfile,"tmp.%i.%i", getpid(),(rand())/10000); if ( getenv("GISBASE") == NULL ) { G_fatal_error ("GISBASE not set. Unable to call GRASS module 'r.categorise'."); } if ( quiet->answer ) { sprintf (sysstr,"%s/bin/r.categorize input=%s@%s output=%s mode=%s min=%s max=%s -q", getenv("GISBASE"), map->answer, mapset, tmpfile, mode->answer, min->answer, max->answer); } else { sprintf (sysstr,"%s/bin/r.categorize input=%s@%s output=%s mode=%s min=%s max=%s", getenv("GISBASE"), map->answer, mapset, tmpfile, mode->answer, min->answer, max->answer); } /* now create fully classified map using r.categorize and store */ /* it in a temporary raster map */ error = system (sysstr); if ( error < 0 ) { G_fatal_error ("Calling r.categorize has failed. Check your installation."); } /* store name of temporary file as new input map */ G_strcpy (input_map, tmpfile); /* check categories of tmpfile */ cats = GT_get_stats (input_map,mapset,&null_count, &nocat_count, show_progress); if (cats < 1) { G_fatal_error ("Could not create a fully categorised temporary file.\nTry another categorisation mode."); } } /* initialise cache structure */ if ( input_map != NULL ) { /* set cachesize */ CACHESIZE = atoi (cachesize->answer); if ( (CACHESIZE<-1) || (CACHESIZE > G_window_rows ()) ) { /* if cache size is invalid, just set to auto-mode (-1) */ G_warning ("Invalid cache size requested (must be between 0 and %i or -1).\n", G_window_rows()); CACHESIZE = -1; } } if ( G_raster_map_is_fp (input_map, mapset)) { do_report_DCELL (input_map, mapset, sites->answer, atoi (precision->answer),null->answer, uncat->answer, all->answer, quiet->answer, zeroskip->answer, logfile->answer, background->answer, gain->answer, show_progress); } else { do_report_CELL (input_map, mapset, sites->answer, atoi (precision->answer),null->answer, uncat->answer, all->answer, quiet->answer, zeroskip->answer, logfile->answer, background->answer, gain->answer, show_progress); } /* delete temporary file, if needed */ if ( mode->answer != NULL ) { delete_tmpfile (tmpfile); G_free (tmpfile); } if ( sysstr != NULL ) { G_free (sysstr); } G_free (input_map); return (EXIT_SUCCESS); }
int main(int argc, char **argv) { char *mapset; int o_method; struct GModule *module; struct Option *method, *basemap, *covermap, *outputmap; struct Flag *flag_c; struct Categories cats; char methods[1024]; G_gisinit(argv[0]); module = G_define_module(); module->keywords = _("raster, statistics"); module->description = _("Calculates category or object oriented statistics."); basemap = G_define_standard_option(G_OPT_R_BASE); covermap = G_define_standard_option(G_OPT_R_COVER); for (o_method = 0; menu[o_method].name; o_method++) { if (o_method) strcat(methods, ","); else *(methods) = 0; strcat(methods, menu[o_method].name); } method = G_define_option(); method->key = "method"; method->type = TYPE_STRING; method->required = YES; method->description = _("Method of object-based statistic"); method->options = methods; outputmap = G_define_standard_option(G_OPT_R_OUTPUT); outputmap->description = _("Resultant raster map (not used with 'distribution')"); outputmap->required = NO; flag_c = G_define_flag(); flag_c->key = 'c'; flag_c->description = _("Cover values extracted from the category labels of the cover map"); if (G_parser(argc, argv)) exit(EXIT_FAILURE); if ((mapset = G_find_cell2(basemap->answer, "")) == 0) G_fatal_error(_("Raster map <%s> not found"), basemap->answer); if (G_raster_map_is_fp(basemap->answer, mapset) != 0) G_fatal_error(_("This module currently only works for integer (CELL) maps")); if ((mapset = G_find_cell2(covermap->answer, "")) == 0) G_fatal_error(_("Raster map <%s> not found"), covermap->answer); if (G_raster_map_is_fp(covermap->answer, mapset) != 0) G_fatal_error(_("This module currently only works for integer (CELL) maps")); if (G_read_cats(covermap->answer, mapset, &cats) < 0) { G_fatal_error(_("Unable to read category file of raster map <%s@%s>"), covermap->answer, mapset); } for (o_method = 0; menu[o_method].name; o_method++) if (strcmp(menu[o_method].name, method->answer) == 0) break; if (!menu[o_method].name) { G_warning(_("<%s=%s> unknown %s"), method->key, method->answer, method->key); G_usage(); exit(EXIT_FAILURE); } switch (menu[o_method].val) { case DISTRIB: if (outputmap->answer != NULL) G_warning(_("Output map <%s> ignored"), outputmap->answer); o_distrib(basemap->answer, covermap->answer, outputmap->answer, flag_c->answer); break; case AVERAGE: is_ok(method->answer, outputmap->answer); o_average(basemap->answer, covermap->answer, outputmap->answer, flag_c->answer, &cats); break; case MODE: is_ok(method->answer, outputmap->answer); o_mode(basemap->answer, covermap->answer, outputmap->answer, flag_c->answer, &cats); break; case ADEV: is_ok(method->answer, outputmap->answer); o_adev(basemap->answer, covermap->answer, outputmap->answer, flag_c->answer, &cats); break; case SDEV: is_ok(method->answer, outputmap->answer); o_sdev(basemap->answer, covermap->answer, outputmap->answer, flag_c->answer, &cats); break; case VARIANC: is_ok(method->answer, outputmap->answer); o_var(basemap->answer, covermap->answer, outputmap->answer, flag_c->answer, &cats); break; case SKEWNES: is_ok(method->answer, outputmap->answer); o_skew(basemap->answer, covermap->answer, outputmap->answer, flag_c->answer, &cats); break; case KURTOSI: is_ok(method->answer, outputmap->answer); o_kurt(basemap->answer, covermap->answer, outputmap->answer, flag_c->answer, &cats); break; case MEDIAN: is_ok(method->answer, outputmap->answer); o_median(basemap->answer, covermap->answer, outputmap->answer, flag_c->answer, &cats); break; case MIN: is_ok(method->answer, outputmap->answer); o_min(basemap->answer, covermap->answer, outputmap->answer, flag_c->answer, &cats); break; case MAX: is_ok(method->answer, outputmap->answer); o_max(basemap->answer, covermap->answer, outputmap->answer, flag_c->answer, &cats); break; case SUM: is_ok(method->answer, outputmap->answer); o_sum(basemap->answer, covermap->answer, outputmap->answer, flag_c->answer, &cats); break; case DIV: is_ok(method->answer, outputmap->answer); o_divr(basemap->answer, covermap->answer, outputmap->answer, flag_c->answer, &cats); break; default: G_fatal_error(_("Not yet implemented!")); } return 0; }
/*! \brief Get map data type \param filename raster map name \param negflag \return -1 if map is integer and G_read_range() fails \return data type (ARRY_*) */ int Gs_numtype(const char *filename, int *negflag) { CELL max = 0, min = 0; struct Range range; const char *mapset; int shortbits, charbits, bitplace; static int max_short, max_char; static int first = 1; if (first) { max_short = max_char = 1; shortbits = 8 * sizeof(short); for (bitplace = 1; bitplace < shortbits; ++bitplace) { /*1 bit for sign */ max_short *= 2; } max_short -= 1; /* NO bits for sign, using unsigned char */ charbits = 8 * sizeof(unsigned char); for (bitplace = 0; bitplace < charbits; ++bitplace) { max_char *= 2; } max_char -= 1; first = 0; } mapset = G_find_cell2(filename, ""); if (!mapset) { G_warning(_("Raster map <%s> not found"), filename); return -1; } if (G_raster_map_is_fp(filename, mapset)) { G_debug(3, "Gs_numtype(): fp map detected"); return (ATTY_FLOAT); } if (-1 == G_read_range(filename, mapset, &range)) { return (-1); } G_get_range_min_max(&range, &min, &max); *negflag = (min < 0); if (max < max_char && min > 0) { return (ATTY_CHAR); } if (max < max_short && min > -max_short) { return (ATTY_SHORT); } return (ATTY_INT); }
int main(int argc, char *argv[]) { char name[128]; char *mapset; struct Categories cats; int vector = 0; int stat; /* Initialize GIS engine */ G_gisinit(argv[0]); if (argc > 1 && (strcmp(argv[1], "-v") == 0)) { vector = 1; argc--; argv++; } if (argc < 2) { if (vector) mapset = G_ask_vector_in_mapset(_("Which vector map needs " "updated categories?"), name); else mapset = G_ask_cell_in_mapset(_("Which raster map needs " "updated categories?"), name); if (mapset == NULL) G_fatal_error(_("%s map <%s> not found"), vector ? "Vector" : "Raster", name); } else { strncpy(name, argv[1], sizeof(name)); mapset = (vector) ? G_find_vector2(name, G_mapset()) : G_find_cell2(name, G_mapset()); if (mapset == NULL) G_fatal_error(_("%s map <%s> not found"), vector ? "Vector" : "Raster", name); } stat = (vector) ? G_read_vector_cats(name, mapset, &cats) : G_read_cats(name, mapset, &cats); if (stat < 0) G_init_cats((CELL) 0, "", &cats); if (!vector && G_raster_map_is_fp(name, mapset)) { if (E_edit_fp_cats(name, &cats) < 0) { G_message(_("Category file for <%s> not updated"), name); return EXIT_SUCCESS; } } else { if (E_edit_cats(name, &cats, stat < 0) < 0) { G_message(_("Category file for <%s> not updated"), name); return EXIT_SUCCESS; } } if (vector) G_write_vector_cats(name, &cats); else G_write_cats(name, &cats); G_message(_("Category file for <%s> updated"), name); return EXIT_SUCCESS; }