[GRASS-SVN] r47646 - grass/trunk/vector/v.colors
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Aug 15 12:04:08 EDT 2011
Author: martinl
Date: 2011-08-15 09:04:07 -0700 (Mon, 15 Aug 2011)
New Revision: 47646
Modified:
grass/trunk/vector/v.colors/local_proto.h
grass/trunk/vector/v.colors/main.c
grass/trunk/vector/v.colors/scan_attr.c
grass/trunk/vector/v.colors/scan_cats.c
Log:
v.colors: implement range
Modified: grass/trunk/vector/v.colors/local_proto.h
===================================================================
--- grass/trunk/vector/v.colors/local_proto.h 2011-08-15 15:56:49 UTC (rev 47645)
+++ grass/trunk/vector/v.colors/local_proto.h 2011-08-15 16:04:07 UTC (rev 47646)
@@ -1,11 +1,12 @@
/* scan_attr */
int scan_attr(const struct Map_info *, int, const char *, const char *,
- struct Colors *, int *, int *);
+ const struct FPRange *, struct Colors *, int *, int *);
/* scan_cats */
void scan_cats(const struct Map_info *, int, const char *,
- struct Colors *, int *, int *);
+ const struct FPRange *, struct Colors *, int *, int *);
/* write_rgb.c */
void write_rgb_values(const struct Map_info *, int, const char *,
struct Colors *);
+
Modified: grass/trunk/vector/v.colors/main.c
===================================================================
--- grass/trunk/vector/v.colors/main.c 2011-08-15 15:56:49 UTC (rev 47645)
+++ grass/trunk/vector/v.colors/main.c 2011-08-15 16:04:07 UTC (rev 47646)
@@ -34,7 +34,8 @@
} flag;
struct {
- struct Option *map, *field, *colr, *rast, *volume, *rules, *attrcol, *rgbcol;
+ struct Option *map, *field, *colr, *rast, *volume, *rules,
+ *attrcol, *rgbcol, *range;
} opt;
int layer, cmin, cmax;
@@ -45,6 +46,7 @@
char *name;
struct Map_info Map;
+ struct FPRange range;
struct Colors colors, colors_tmp;
/* struct Cell_stats statf; */
@@ -63,12 +65,23 @@
opt.attrcol = G_define_standard_option(G_OPT_DB_COLUMN);
opt.attrcol->label = _("Name of column containing numeric data");
opt.attrcol->description = _("If not given categories are used");
+ opt.attrcol->guisection = _("Define");
+
+ opt.range = G_define_option();
+ opt.range->key = "range";
+ opt.range->type = TYPE_DOUBLE;
+ opt.range->required = NO;
+ opt.range->description = _("Manually set range (refers to 'column' option)");
+ opt.range->key_desc = "min,max";
+
opt.colr = G_define_standard_option(G_OPT_M_COLR);
-
+ opt.colr->guisection = _("Define");
+
opt.rgbcol = G_define_standard_option(G_OPT_DB_COLUMN);
opt.rgbcol->key = "rgb_column";
opt.rgbcol->label = _("Name of color column to populate RGB values");
opt.rgbcol->description = _("If not given writes color table");
+ opt.rgbcol->guisection = _("Define");
opt.rast = G_define_standard_option(G_OPT_R_INPUT);
opt.rast->key = "raster";
@@ -208,6 +221,14 @@
if (layer < 1)
G_fatal_error(_("Layer <%s> not found"), opt.field->answer);
+ if (opt.range->answer) {
+ range.min = atof(opt.range->answers[0]);
+ range.max = atof(opt.range->answers[1]);
+ if (range.min > range.max)
+ G_fatal_error(_("Option <%s>: min must be greater or equal to max"),
+ opt.range->key);
+ }
+
if (is_from_stdin) {
/*
if (!read_color_rules(stdin, &colors, min, max, fp))
@@ -218,10 +239,11 @@
G_fatal_error(_("Color table <%s> not found"), style);
if (!attrcolumn) {
- scan_cats(&Map, layer, style, &colors, &cmin, &cmax);
+ scan_cats(&Map, layer, style, opt.range->answer ? &range : NULL,
+ &colors, &cmin, &cmax);
}
else {
- scan_attr(&Map, layer, attrcolumn, style,
+ scan_attr(&Map, layer, attrcolumn, style, opt.range->answer ? &range : NULL,
&colors, &cmin, &cmax);
}
Modified: grass/trunk/vector/v.colors/scan_attr.c
===================================================================
--- grass/trunk/vector/v.colors/scan_attr.c 2011-08-15 15:56:49 UTC (rev 47645)
+++ grass/trunk/vector/v.colors/scan_attr.c 2011-08-15 16:04:07 UTC (rev 47646)
@@ -6,7 +6,8 @@
#include "local_proto.h"
int scan_attr(const struct Map_info *Map, int layer, const char *column_name,
- const char *style, struct Colors *colors, int *cmin, int *cmax)
+ const char *style, const struct FPRange *range,
+ struct Colors *colors, int *cmin, int *cmax)
{
int ctype, is_fp, nrec, i, cat;
int red, grn, blu;
@@ -53,11 +54,43 @@
if (is_fp) {
fmin = cvarr.value[0].val.d;
fmax = cvarr.value[cvarr.n_values-1].val.d;
+
+ if (range) {
+ if (range->min >= fmin && range->min <= fmax)
+ fmin = range->min;
+ else
+ G_warning(_("Min value (%f) is out of range %f,%f"),
+ range->min, fmin, fmax);
+
+ if (range->max <= fmax && range->max >= fmin)
+ fmax = range->max;
+ else
+ G_warning(_("Max value (%f) is out of range %f,%f"),
+ range->max, fmin, fmax);
+ }
+
+ G_debug(3, "scan_attr(): range=%f,%f", fmin, fmax);
Rast_make_fp_colors(&vcolors, style, (DCELL) fmin, (DCELL) fmax);
}
else {
fmin = cvarr.value[0].val.i;
fmax = cvarr.value[cvarr.n_values-1].val.i;
+
+ if (range) {
+ if (range->min >= fmin && range->min <= fmax)
+ fmin = range->min;
+ else
+ G_warning(_("Min value (%d) is out of range %d,%d"),
+ (int) range->min, (int) fmin, (int) fmax);
+
+ if (range->max <= fmax && range->max >= fmin)
+ fmax = range->max;
+ else
+ G_warning(_("Max value (%d) is out of range %d,%d"),
+ (int) range->max, (int) fmin, (int) fmax);
+ }
+
+ G_debug(3, "scan_attr(): range=%d,%d", (int) fmin, (int) fmax);
Rast_make_colors(&vcolors, style, (CELL) fmin, (CELL) fmax);
}
@@ -68,17 +101,21 @@
if (is_fp) {
if (Rast_get_d_color((const DCELL *) &(cv->val.d), &red, &grn, &blu,
&vcolors) == 0) {
- G_warning(_("No color rule defined for value %f"), cv->val.d);
+ /* G_warning(_("No color rule defined for value %f"), cv->val.d); */
+ G_debug(3, "scan_attr(): cat=%d, val=%f -> no color rule", cat, cv->val.d);
continue;
}
}
else {
if (Rast_get_c_color((const CELL *) &(cv->val.i), &red, &grn, &blu,
&vcolors) == 0) {
- G_warning(_("No color rule defined for value %d"), cv->val.i);
+ /* G_warning(_("No color rule defined for value %d"), cv->val.i); */
+ G_debug(3, "scan_attr(): cat=%d, val=%d -> no color rule", cat, cv->val.i);
continue;
}
}
+ G_debug(3, "scan_attr(): cat=%d, val=%f, r=%d, g=%d, b=%d",
+ cat, is_fp ? cv->val.d : cv->val.i, red, grn, blu);
Rast_add_c_color_rule((const CELL*) &cat, red, grn, blu,
(const CELL*) &cat, red, grn, blu, colors);
Modified: grass/trunk/vector/v.colors/scan_cats.c
===================================================================
--- grass/trunk/vector/v.colors/scan_cats.c 2011-08-15 15:56:49 UTC (rev 47645)
+++ grass/trunk/vector/v.colors/scan_cats.c 2011-08-15 16:04:07 UTC (rev 47646)
@@ -7,7 +7,7 @@
static void scan_layer(int, const struct line_cats *, int *, int *);
void scan_cats(const struct Map_info *Map, int field, const char *style,
- struct Colors *colors, int *cmin, int *cmax)
+ const struct FPRange *range, struct Colors *colors, int *cmin, int *cmax)
{
int ltype, lmin, lmax;
struct line_cats *Cats;
@@ -31,6 +31,21 @@
*cmax = lmax;
}
+ if (range) {
+ if (range->min >= *cmin && range->min <= *cmax)
+ *cmin = range->min;
+ else
+ G_warning(_("Min value (%d) is out of range %d,%d"),
+ (int) range->min, *cmin, *cmax);
+
+ if (range->max <= *cmax && range->max >= *cmin)
+ *cmax = range->max;
+ else
+ G_warning(_("Max value (%d) is out of range %d,%d"),
+ (int) range->max, *cmin, *cmax);
+ }
+
+ G_debug(3, "scan_cats(): range=%d,%d", *cmin, *cmax);
Rast_make_colors(colors, style, (CELL) *cmin, (CELL) *cmax);
Vect_destroy_cats_struct(Cats);
More information about the grass-commit
mailing list