static void getParams(char **name, d_Mask ** maskRules, int *changeNull, double *newNullVal) { *name = params.map->answer; parse_vallist(params.setNull->answers, maskRules); *changeNull = (params.null->answer != NULL); if (*changeNull) if (sscanf(params.null->answer, "%lf", newNullVal) != 1) G3d_fatalError(_("Illegal value for null")); }
int main(int argc, char **argv) { char *name; int overlay; int invert, fp; struct GModule *module; struct Option *map; struct Option *vallist; struct Option *bg; struct Flag *flag_n; struct Flag *flag_i; /* Initialize the GIS calls */ G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("display")); G_add_keyword(_("raster")); module->description = _("Displays user-specified raster map in the active " "graphics frame."); /* set up command line */ map = G_define_standard_option(G_OPT_R_MAP); map->description = _("Name of raster map to be displayed"); vallist = G_define_option(); vallist->key = "values"; vallist->key_desc = "value[-value]"; vallist->type = TYPE_STRING; vallist->required = NO; vallist->multiple = YES; vallist->description = _("List of categories or values to be displayed"); vallist->guisection = _("Selection"); bg = G_define_standard_option(G_OPT_C_BG); bg->key_desc = "color"; bg->gisprompt = "old_color,color,color"; bg->label = _("Background color (for null)"); bg->description = _("Either a standard color name or R:G:B triplet"); bg->guisection = _("Null cells"); flag_n = G_define_flag(); flag_n->key = 'n'; flag_n->description = _("Make null cells opaque"); flag_n->guisection = _("Null cells"); flag_i = G_define_flag(); flag_i->key = 'i'; flag_i->description = _("Invert value list"); flag_i->guisection = _("Selection"); if (G_parser(argc, argv)) exit(EXIT_FAILURE); name = map->answer; overlay = !flag_n->answer; invert = flag_i->answer; if (D_open_driver() != 0) G_fatal_error(_("No graphics device selected. " "Use d.mon to select graphics device.")); fp = Rast_map_is_fp(name, ""); if (vallist->answer) { if (fp) parse_vallist(vallist->answers, &d_mask); else parse_catlist(vallist->answers, &mask); } /* use DCELL even if the map is FCELL */ display(name, overlay, bg->answer, fp ? DCELL_TYPE : CELL_TYPE, invert); D_save_command(G_recreate_command()); D_close_driver(); exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { char *name, *mapset; char rname[GNAME_MAX], rmapset[GMAPSET_MAX]; char path[GPATH_MAX]; int row, col, null_fd; unsigned char *null_bits; RASTER_MAP_TYPE map_type; int change_null = 0, create, remove, only_int, only_fp, only_null; int is_reclass; struct GModule *module; struct { struct Option *map; struct Option *setnull; struct Option *null; } parms; struct { struct Flag *f; struct Flag *n; struct Flag *i; struct Flag *c; struct Flag *r; } flags; G_gisinit(argv[0]); module = G_define_module(); module->keywords = _("raster, null data"); module->description = _("Manages NULL-values of given raster map."); parms.map = G_define_standard_option(G_OPT_R_MAP); parms.map->description = _("Name of raster map for which to edit null file"); parms.setnull = G_define_option(); parms.setnull->key = "setnull"; parms.setnull->key_desc = "val[-val]"; parms.setnull->type = TYPE_STRING; parms.setnull->required = NO; parms.setnull->multiple = YES; parms.setnull->description = _("List of cell values to be set to NULL"); parms.setnull->guisection = _("Modify"); parms.null = G_define_option(); parms.null->key = "null"; parms.null->type = TYPE_DOUBLE; parms.null->required = NO; parms.null->multiple = NO; parms.null->description = _("The value to replace the null value by"); parms.null->guisection = _("Modify"); flags.f = G_define_flag(); flags.f->key = 'f'; flags.f->description = _("Only do the work if the map is floating-point"); flags.f->guisection = _("Check"); flags.i = G_define_flag(); flags.i->key = 'i'; flags.i->description = _("Only do the work if the map is integer"); flags.i->guisection = _("Check"); flags.n = G_define_flag(); flags.n->key = 'n'; flags.n->description = _("Only do the work if the map doesn't have a NULL-value bitmap file"); flags.n->guisection = _("Check"); flags.c = G_define_flag(); flags.c->key = 'c'; flags.c->description = _("Create NULL-value bitmap file validating all data cells"); flags.r = G_define_flag(); flags.r->key = 'r'; flags.r->description = _("Remove NULL-value bitmap file"); flags.r->guisection = _("Remove"); if (G_parser(argc, argv)) exit(EXIT_FAILURE); only_int = flags.i->answer; only_fp = flags.f->answer; only_null = flags.n->answer; create = flags.c->answer; remove = flags.r->answer; name = parms.map->answer; mapset = G_find_cell2(name, ""); if (mapset == NULL) G_fatal_error(_("Raster map <%s> not found"), name); is_reclass = (G_is_reclass(name, mapset, rname, rmapset) > 0); if (is_reclass) G_fatal_error(_("Raster map <%s> is a reclass of map <%s@%s>. " "Consider to generate a copy with r.mapcalc. Exiting."), name, rname, rmapset); if (strcmp(mapset, G_mapset()) != 0) G_fatal_error(_("Raster map <%s> is not in your mapset <%s>"), name, G_mapset()); if (parms.null->answer) { if (sscanf(parms.null->answer, "%lf", &new_null) == 1) change_null = 1; else G_fatal_error(_("%s is illegal entry for null"), parms.null->answer); } map_type = G_raster_map_type(name, mapset); if (only_null && G_find_file_misc("cell_misc", "null", name, mapset)) G_fatal_error(_("Raster map <%s> already has a null bitmap file"), name); if (map_type == CELL_TYPE) { if (only_fp) G_fatal_error(_("<%s> is integer raster map (CELL)"), name); if ((double)((int)new_null) != new_null) { G_warning(_("<%s> is integer raster map (CELL). Using null=%d."), name, (int)new_null); new_null = (double)((int)new_null); } } else if (only_int) G_fatal_error(_("<%s> is floating pointing raster map"), name); parse_vallist(parms.setnull->answers, &d_mask); if (G_get_cellhd(name, mapset, &cellhd) < 0) G_fatal_error(_("Unable to read header of raster map <%s>"), G_fully_qualified_name(name, mapset)); if (create) { /* write a file of no-nulls */ null_bits = (unsigned char *)G__allocate_null_bits(cellhd.cols); /* init all cells to 0's */ for (col = 0; col < G__null_bitstream_size(cellhd.cols); col++) null_bits[col] = 0; null_fd = G_open_new_misc("cell_misc", "null", name); G_verbose_message(_("Writing new null file for raster map <%s>..."), name); for (row = 0; row < cellhd.rows; row++) { G_percent(row, cellhd.rows, 1); if (G__write_null_bits(null_fd, null_bits, row, cellhd.cols, 0) < 0) G_fatal_error(_("Error writing null row %d"), row); } G_percent(row, cellhd.rows, 1); close(null_fd); G_done_msg(_("Raster map <%s> modified."), name); exit(EXIT_SUCCESS); } if (remove) { /* write a file of no-nulls */ G_verbose_message(_("Removing null file for raster map <%s>..."), name); null_fd = G_open_new_misc("cell_misc", "null", name); G__file_name_misc(path, "cell_misc", "null", name, mapset); unlink(path); G_done_msg(_("Raster map <%s> modified."), name); exit(EXIT_SUCCESS); } process(name, mapset, change_null, map_type); exit(EXIT_SUCCESS); }