[GRASS-SVN] r47655 - grass/trunk/vector/v.colors
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Aug 15 15:18:07 EDT 2011
Author: martinl
Date: 2011-08-15 12:18:07 -0700 (Mon, 15 Aug 2011)
New Revision: 47655
Modified:
grass/trunk/vector/v.colors/local_proto.h
grass/trunk/vector/v.colors/main.c
grass/trunk/vector/v.colors/make_colors.c
grass/trunk/vector/v.colors/scan_attr.c
grass/trunk/vector/v.colors/scan_cats.c
Log:
v.colors: fix rules to produce cat-based color tables
Modified: grass/trunk/vector/v.colors/local_proto.h
===================================================================
--- grass/trunk/vector/v.colors/local_proto.h 2011-08-15 17:50:23 UTC (rev 47654)
+++ grass/trunk/vector/v.colors/local_proto.h 2011-08-15 19:18:07 UTC (rev 47655)
@@ -1,13 +1,15 @@
/* make_colors.c */
void make_colors(struct Colors *, const char *, DCELL, DCELL, int);
+void load_colors(struct Colors *, const char *, DCELL, DCELL, int);
/* scan_attr.c */
int scan_attr(const struct Map_info *, int, const char *, const char *,
- const struct FPRange *, struct Colors *, int *, int *);
+ const char *, const struct FPRange *, struct Colors *);
+
/* scan_cats.c */
-void scan_cats(const struct Map_info *, int, const char *,
- const struct FPRange *, struct Colors *, int *, int *);
+void scan_cats(const struct Map_info *, int, const char *, const char *,
+ const struct FPRange *, struct Colors *);
/* write_rgb.c */
void write_rgb_values(const struct Map_info *, int, const char *,
Modified: grass/trunk/vector/v.colors/main.c
===================================================================
--- grass/trunk/vector/v.colors/main.c 2011-08-15 17:50:23 UTC (rev 47654)
+++ grass/trunk/vector/v.colors/main.c 2011-08-15 19:18:07 UTC (rev 47655)
@@ -37,7 +37,7 @@
*attrcol, *rgbcol, *range;
} opt;
- int layer, cmin, cmax;
+ int layer;
int have_stats;
int overwrite, remove, is_from_stdin, stat, have_colors;
const char *mapset, *cmapset;
@@ -70,7 +70,8 @@
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->label = _("Manually set range (refers to 'column' option)");
+ opt.range->description = _("Ignored when 'rules' given");
opt.range->key_desc = "min,max";
opt.colr = G_define_standard_option(G_OPT_M_COLR);
@@ -233,23 +234,21 @@
if (!read_color_rules(stdin, &colors, min, max, fp))
exit(EXIT_FAILURE);
*/
- } else if (style) {
- if (!G_find_color_rule(style))
+ } else if (style || rules) {
+ if (style && !G_find_color_rule(style))
G_fatal_error(_("Color table <%s> not found"), style);
if (!attrcolumn) {
- scan_cats(&Map, layer, style, opt.range->answer ? &range : NULL,
- &colors, &cmin, &cmax);
+ scan_cats(&Map, layer, style, rules,
+ opt.range->answer ? &range : NULL,
+ &colors);
}
else {
- scan_attr(&Map, layer, attrcolumn, style, opt.range->answer ? &range : NULL,
- &colors, &cmin, &cmax);
+ scan_attr(&Map, layer, attrcolumn, style, rules,
+ opt.range->answer ? &range : NULL,
+ &colors);
}
}
- else if (rules) {
- if (!Rast_load_colors(&colors, rules, (CELL) cmin, (CELL) cmax))
- G_fatal_error(_("Unable to load rules file <%s>"), rules);
- }
else {
/* use color from another map (cmap) */
if (opt.rast->answer) {
Modified: grass/trunk/vector/v.colors/make_colors.c
===================================================================
--- grass/trunk/vector/v.colors/make_colors.c 2011-08-15 17:50:23 UTC (rev 47654)
+++ grass/trunk/vector/v.colors/make_colors.c 2011-08-15 19:18:07 UTC (rev 47655)
@@ -37,3 +37,16 @@
Rast_make_colors(colors, style, (CELL) min, (CELL) max);
}
}
+
+void load_colors(struct Colors *colors, const char *rules, DCELL min, DCELL max, int is_fp)
+{
+ int ret;
+
+ if (is_fp)
+ ret = Rast_load_fp_colors(colors, rules, (DCELL) min, (DCELL) max);
+ else
+ ret = Rast_load_colors(colors, rules, (CELL) min, (CELL) max);
+
+ if (ret == 0)
+ G_fatal_error(_("Unable to load rules file <%s>"), rules);
+}
Modified: grass/trunk/vector/v.colors/scan_attr.c
===================================================================
--- grass/trunk/vector/v.colors/scan_attr.c 2011-08-15 17:50:23 UTC (rev 47654)
+++ grass/trunk/vector/v.colors/scan_attr.c 2011-08-15 19:18:07 UTC (rev 47655)
@@ -6,8 +6,8 @@
#include "local_proto.h"
int scan_attr(const struct Map_info *Map, int layer, const char *column_name,
- const char *style, const struct FPRange *range,
- struct Colors *colors, int *cmin, int *cmax)
+ const char *style, const char *rules,
+ const struct FPRange *range, struct Colors *colors)
{
int ctype, is_fp, nrec, i, cat;
int red, grn, blu;
@@ -19,9 +19,7 @@
dbCatVal *cv;
dbCatValArray cvarr;
- *cmin = *cmax = -1;
Rast_init_colors(colors);
- Rast_init_colors(&vcolors);
fi = Vect_get_field(Map, layer);
if (!fi)
@@ -87,7 +85,10 @@
(int) range->max, (int) fmin, (int) fmax);
}
}
- make_colors(&vcolors, style, (DCELL) fmin, (DCELL) fmax, is_fp);
+ if (style)
+ make_colors(&vcolors, style, (DCELL) fmin, (DCELL) fmax, is_fp);
+ else if (rules)
+ load_colors(&vcolors, rules, (DCELL) fmin, (DCELL) fmax, is_fp);
/* color table for categories */
for (i = 0; i < cvarr.n_values; i++) {
@@ -113,16 +114,6 @@
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);
-
- if (i == 0) {
- *cmin = *cmax = cat;
- }
- else {
- if (cat <= *cmin)
- *cmin = cat;
- if (cat >= *cmax)
- *cmax = cat;
- }
}
db_close_database(driver);
Modified: grass/trunk/vector/v.colors/scan_cats.c
===================================================================
--- grass/trunk/vector/v.colors/scan_cats.c 2011-08-15 17:50:23 UTC (rev 47654)
+++ grass/trunk/vector/v.colors/scan_cats.c 2011-08-15 19:18:07 UTC (rev 47655)
@@ -6,13 +6,14 @@
static void scan_layer(int, const struct line_cats *, int *, int *);
-void scan_cats(const struct Map_info *Map, int field, const char *style,
- const struct FPRange *range, struct Colors *colors, int *cmin, int *cmax)
+void scan_cats(const struct Map_info *Map, int field,
+ const char *style, const char *rules,
+ const struct FPRange *range, struct Colors *colors)
{
- int ltype, lmin, lmax;
+ int ltype, lmin, lmax, cmin, cmax;
struct line_cats *Cats;
- *cmin = *cmax = -1;
+ cmin = cmax = -1;
Cats = Vect_new_cats_struct();
G_message(_("Reading features..."));
@@ -25,28 +26,32 @@
scan_layer(field, Cats, &lmin, &lmax);
- if (*cmin == -1 || lmin <= *cmin)
- *cmin = lmin;
- if (*cmax == -1 || lmax >= *cmax)
- *cmax = lmax;
+ if (cmin == -1 || lmin <= cmin)
+ cmin = lmin;
+ if (cmax == -1 || lmax >= cmax)
+ cmax = lmax;
}
if (range) {
- if (range->min >= *cmin && range->min <= *cmax)
- *cmin = range->min;
+ 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);
+ (int) range->min, cmin, cmax);
- if (range->max <= *cmax && range->max >= *cmin)
- *cmax = range->max;
+ 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);
+ (int) range->max, cmin, cmax);
}
-
- make_colors(colors, style, (DCELL) *cmin, (DCELL) *cmax, FALSE);
+ if (style)
+ make_colors(colors, style, (DCELL) cmin, (DCELL) cmax, FALSE);
+ else if (rules) {
+ load_colors(colors, rules, (DCELL) cmin, (DCELL) cmax, FALSE);
+ }
+
Vect_destroy_cats_struct(Cats);
}
More information about the grass-commit
mailing list