Beispiel #1
0
/*
 * check_stats() - Check and update statistics 
 *
 * RETURN: EXIT_SUCCESS / EXIT_FAILURE
 */
int check_stats(const char *name)
{
    struct Categories cats;
    struct FPRange fprange;
    int cats_ok;

    G_message(_("Updating statistics for <%s>"), name);
    
    /* Get category status and max */
    cats_ok = (Rast3d_read_cats(name, "", &cats) >= 0);
    Rast3d_read_range(name, "", &fprange);

    /* Further category checks */
    if (!cats_ok)
	Rast_init_cats("", &cats);
    else if (cats.num != fprange.max) {
	cats.num = fprange.max;
	cats_ok = 0;
    }

    /* Update categories if needed */
    if (!cats_ok) {
	G_message(_("Updating the number of categories for <%s>"), name);
	Rast3d_write_cats(name, &cats);
    }
    Rast_free_cats(&cats);

    return 0;
}
Beispiel #2
0
int
Rast3d_read_colors(const char *name, const char *mapset, struct Colors *colors)
 /* adapted from Rast_read_colors */
{
    const char *err;
    struct FPRange drange;
    DCELL dmin, dmax;

    Rast_init_colors(colors);

    Rast_mark_colors_as_fp(colors);

    switch (read_colors(name, mapset, colors)) {
    case -2:
	if (Rast3d_read_range(name, mapset, &drange) >= 0) {
	    Rast_get_fp_range_min_max(&drange, &dmin, &dmax);
	    if (!Rast_is_d_null_value(&dmin) && !Rast_is_d_null_value(&dmax))
		Rast_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;
}
Beispiel #3
0
/* Run in raster3d mode */
int main(int argc, char **argv)
{    
    struct GModule *module;
    struct
    {
	struct Option *map, *file;
    } opt;
    struct
    {
	struct Flag *p;
    } flag;

    const char *file;
    FILE * fp;
    struct Colors colors;
    struct FPRange range;
    
    G_gisinit(argv[0]);

    module = G_define_module();
    G_add_keyword(_("raster3d"));
    G_add_keyword(_("color table"));
    G_add_keyword(_("export"));
    module->description =
	_("Exports the color table associated with a 3D raster map.");

    opt.map = G_define_standard_option(G_OPT_R3_MAP);
    
    opt.file = G_define_standard_option(G_OPT_F_OUTPUT);
    opt.file->key = "rules";
    opt.file->label = _("Path to output rules file");
    opt.file->description = _("\"-\" to write to stdout");
    opt.file->answer = "-";
    
    flag.p = G_define_flag();
    flag.p->key = 'p';
    flag.p->description = _("Output values as percentages");

    if (G_parser(argc, argv))
	exit(EXIT_FAILURE);

    file = opt.file->answer;
    
    if (Rast3d_read_colors(opt.map->answer, "", &colors) < 0)
        G_fatal_error(_("Unable to read color table for raster3d map <%s>"),
		      opt.map->answer);
    
    Rast3d_read_range(opt.map->answer, "", &range);
    
    if (!file || strcmp(file, "-") == 0)
	fp = stdout;
    else {
	fp = fopen(file, "w");
	if (!fp)
	    G_fatal_error(_("Unable to open output file <%s>"), file);
    }
    
    Rast_print_colors(&colors, range.min, range.max, fp,
		      flag.p->answer ? 1 : 0);
    
    exit(EXIT_SUCCESS);
}