int pie(double cx, double cy, int size, double *val, int ncols, COLOR * ocolor, COLOR * colors) { int i, j, n; double a, end_ang, ang, tot_sum, sum, step, r; double x, y; struct line_pnts *Points; G_debug(4, "pie(): cx = %f cy = %f", cx, cy); Points = Vect_new_line_struct(); /* Calc sum */ tot_sum = 0; for (i = 0; i < ncols; i++) tot_sum += val[i]; step = PI / 180; r = (D_d_to_u_col(2) - D_d_to_u_col(1)) * size / 2; /* do it better */ /* Draw polygon for each value */ sum = 0; ang = 0; for (i = 0; i < ncols; i++) { sum += val[i]; end_ang = 2 * PI * sum / tot_sum; Vect_reset_line(Points); if (val[0] != tot_sum) /* all in one slice, don't draw line to center */ Vect_append_point(Points, cx, cy, 0); n = (int)ceil((end_ang - ang) / step); for (j = 0, a = ang; j <= n; j++, a += step) { if (a > end_ang) a = end_ang; x = cx + r * cos(a); y = cy + r * sin(a); Vect_append_point(Points, x, y, 0); } ang = end_ang; if (val[0] != tot_sum) Vect_append_point(Points, cx, cy, 0); if (!colors[i].none) { D_RGB_color(colors[i].r, colors[i].g, colors[i].b); D_polygon_abs(Points->x, Points->y, Points->n_points); } D_RGB_color(ocolor->r, ocolor->g, ocolor->b); D_polyline_abs(Points->x, Points->y, Points->n_points); } Vect_destroy_line_struct(Points); return 0; }
void show_label(double *px, double *py, LATTR *lattr, const char *text) { double X = *px, Y = *py; int Xoffset, Yoffset; double xarr[5], yarr[5]; double T, B, L, R; X = X + D_get_d_to_u_xconv() * 0.5 * lattr->size; Y = Y + D_get_d_to_u_yconv() * 1.5 * lattr->size; D_pos_abs(X, Y); D_get_text_box(text, &T, &B, &L, &R); /* Expand border 1/2 of text size */ T = T - D_get_d_to_u_yconv() * lattr->size / 2; B = B + D_get_d_to_u_yconv() * lattr->size / 2; L = L - D_get_d_to_u_xconv() * lattr->size / 2; R = R + D_get_d_to_u_xconv() * lattr->size / 2; Xoffset = 0; Yoffset = 0; if (lattr->xref == LCENTER) Xoffset = -(R - L) / 2; if (lattr->xref == LRIGHT) Xoffset = -(R - L); if (lattr->yref == LCENTER) Yoffset = -(B - T) / 2; if (lattr->yref == LBOTTOM) Yoffset = -(B - T); if (lattr->has_bgcolor || lattr->has_bcolor) { xarr[0] = xarr[1] = xarr[4] = L + Xoffset; xarr[2] = xarr[3] = R + Xoffset; yarr[0] = yarr[3] = yarr[4] = B + Yoffset; yarr[1] = yarr[2] = T + Yoffset; if (lattr->has_bgcolor) { D_RGB_color(lattr->bgcolor.R, lattr->bgcolor.G, lattr->bgcolor.B); D_polygon_abs(xarr, yarr, 5); } if (lattr->has_bcolor) { D_RGB_color(lattr->bcolor.R, lattr->bcolor.G, lattr->bcolor.B); D_polyline_abs(xarr, yarr, 5); } D_RGB_color(lattr->color.R, lattr->color.G, lattr->color.B); } D_pos_abs(X + Xoffset, Y + Yoffset); D_text(text); }
int display(struct Map_info *Map, struct line_pnts *Points, const struct color_rgb *color, int first, int last, int be_bold) { int from, to; D_RGB_color(color->r, color->g, color->b); if (first) from = 0; else from = 1; if (last) to = Points->n_points; else to = Points->n_points - 1; if (be_bold) D_line_width(2); D_polyline_abs(&Points->x[from], &Points->y[from], to - from); if (be_bold) D_line_width(0); return 0; }
int D_color_of_type(const void *raster, struct Colors *colors, RASTER_MAP_TYPE data_type) { int r, g, b; Rast_get_color(raster, &r, &g, &b, colors, data_type); D_RGB_color((unsigned char)r, (unsigned char)g, (unsigned char)b); return 0; }
static void set_color(char *tcolor) { int r, g, b, color; if (sscanf(tcolor, "%d:%d:%d", &r, &g, &b) == 3 || sscanf(tcolor, "0x%02x%02x%02x", &r, &g, &b) == 3) { if (r >= 0 && r < 256 && g >= 0 && g < 256 && b >= 0 && b < 256) { D_RGB_color(r, g, b); } } else { color = D_translate_color(tcolor); if (!color) { G_warning(_("[%s]: No such color. Use '%s'"), tcolor, DEFAULT_COLOR); color = D_translate_color(DEFAULT_COLOR); } D_use_color(color); } return; }
int display_attr(struct Map_info *Map, int type, char *attrcol, struct cat_list *Clist, LATTR *lattr, int chcat) { int i, ltype, more; struct line_pnts *Points; struct line_cats *Cats; int cat; char buf[2000]; struct field_info *fi; dbDriver *driver; dbString stmt, valstr, text; dbCursor cursor; dbTable *table; dbColumn *column; G_debug(2, "attr()"); if (attrcol == NULL || *attrcol == '\0') { G_fatal_error(_("attrcol not specified, cannot display attributes")); } Points = Vect_new_line_struct(); Cats = Vect_new_cats_struct(); db_init_string(&stmt); db_init_string(&valstr); db_init_string(&text); fi = Vect_get_field(Map, lattr->field); if (fi == NULL) return 1; driver = db_start_driver_open_database(fi->driver, fi->database); if (driver == NULL) G_fatal_error(_("Unable to open database <%s> by driver <%s>"), fi->database, fi->driver); Vect_rewind(Map); while (1) { ltype = Vect_read_next_line(Map, Points, Cats); if (ltype == -1) G_fatal_error(_("Unable to read vector map")); else if (ltype == -2) /* EOF */ break; if (!(type & ltype) && !((type & GV_AREA) && (ltype & GV_CENTROID))) continue; /* used for both lines and labels */ D_RGB_color(lattr->color.R, lattr->color.G, lattr->color.B); D_text_size(lattr->size, lattr->size); if (lattr->font) D_font(lattr->font); if (lattr->enc) D_encoding(lattr->enc); if (chcat) { int found = 0; for (i = 0; i < Cats->n_cats; i++) { if (Cats->field[i] == Clist->field && Vect_cat_in_cat_list(Cats->cat[i], Clist)) { found = 1; break; } } if (!found) continue; } else if (Clist->field > 0) { int found = 0; for (i = 0; i < Cats->n_cats; i++) { if (Cats->field[i] == Clist->field) { found = 1; break; } } /* lines with no category will be displayed */ if (Cats->n_cats > 0 && !found) continue; } if (Vect_cat_get(Cats, lattr->field, &cat)) { int ncats = 0; /* Read attribute from db */ db_free_string(&text); for (i = 0; i < Cats->n_cats; i++) { int nrows; if (Cats->field[i] != lattr->field) continue; db_init_string(&stmt); sprintf(buf, "select %s from %s where %s = %d", attrcol, fi->table, fi->key, Cats->cat[i]); G_debug(2, "SQL: %s", buf); db_append_string(&stmt, buf); if (db_open_select_cursor (driver, &stmt, &cursor, DB_SEQUENTIAL) != DB_OK) G_fatal_error(_("Unable to open select cursor: '%s'"), db_get_string(&stmt)); nrows = db_get_num_rows(&cursor); if (ncats > 0) db_append_string(&text, "/"); if (nrows > 0) { table = db_get_cursor_table(&cursor); column = db_get_table_column(table, 0); /* first column */ if (db_fetch(&cursor, DB_NEXT, &more) != DB_OK) continue; db_convert_column_value_to_string(column, &valstr); db_append_string(&text, db_get_string(&valstr)); } else { G_warning(_("No attribute found for cat %d: %s"), cat, db_get_string(&stmt)); } db_close_cursor(&cursor); ncats++; } show_label_line(Points, ltype, lattr, db_get_string(&text)); } } db_close_database_shutdown_driver(driver); Vect_destroy_line_struct(Points); Vect_destroy_cats_struct(Cats); return 0; }
int process_line(int ltype, const struct line_pnts *Points, const struct line_cats *Cats, LATTR *lattr, int chcat, const struct cat_list *Clist) { int i, cat, len; char *text = NULL, buf[100]; D_RGB_color(lattr->color.R, lattr->color.G, lattr->color.B); D_text_size(lattr->size, lattr->size); if (lattr->font) D_font(lattr->font); if (lattr->enc) D_encoding(lattr->enc); if (chcat) { int found = 0; for (i = 0; i < Cats->n_cats; i++) { if (Cats->field[i] == Clist->field && Vect_cat_in_cat_list(Cats->cat[i], Clist)) { found = 1; break; } } if (!found) return 0; } else if (Clist->field > 0) { int found = 0; for (i = 0; i < Cats->n_cats; i++) { if (Cats->field[i] == Clist->field) { found = 1; break; } } /* lines with no category will be displayed */ if (Cats->n_cats > 0 && !found) return 0; } if (Vect_cat_get(Cats, lattr->field, &cat)) { for (i = 0; i < Cats->n_cats; i++) { G_debug(3, "cat lab: field = %d, cat = %d", Cats->field[i], Cats->cat[i]); if (Cats->field[i] == lattr->field) { /* all cats of given lfield */ if (!text) { sprintf(buf, "%d", Cats->cat[i]); text = G_calloc(strlen(buf), sizeof(char)); text[0] = '\0'; strcpy(text, buf); } else { sprintf(buf, "/%d", Cats->cat[i]); len = strlen(text) + strlen(buf) + 1; text = G_realloc(text, len * sizeof(char)); strcat(text, buf); } } } show_label_line(Points, ltype, lattr, text); } if (text) G_free(text); return 1; }
/* *************************************************************** */ int plot1(struct Map_info *Map, int type, int area, struct cat_list *Clist, const struct color_rgb *color, const struct color_rgb *fcolor, int chcat, SYMBOL * Symb, int size, int id_flag, int table_colors_flag, int cats_color_flag, char *rgb_column, int default_width, char *width_column, double width_scale) { int i, ltype, nlines = 0, line, cat = -1; double *x, *y; struct line_pnts *Points, *PPoints; struct line_cats *Cats; double msize; int x0, y0; struct field_info *fi = NULL; dbDriver *driver = NULL; dbCatValArray cvarr_rgb, cvarr_width; dbCatVal *cv_rgb = NULL, *cv_width = NULL; int nrec_rgb = 0, nrec_width = 0; int open_db; int custom_rgb = FALSE; char colorstring[12]; /* RRR:GGG:BBB */ int red, grn, blu; RGBA_Color *line_color, *fill_color, *primary_color; unsigned char which; int width; line_color = G_malloc(sizeof(RGBA_Color)); fill_color = G_malloc(sizeof(RGBA_Color)); primary_color = G_malloc(sizeof(RGBA_Color)); primary_color->a = RGBA_COLOR_OPAQUE; /* change function prototype to pass RGBA_Color instead of color_rgb? */ if (color) { line_color->r = color->r; line_color->g = color->g; line_color->b = color->b; line_color->a = RGBA_COLOR_OPAQUE; } else line_color->a = RGBA_COLOR_NONE; if (fcolor) { fill_color->r = fcolor->r; fill_color->g = fcolor->g; fill_color->b = fcolor->b; fill_color->a = RGBA_COLOR_OPAQUE; } else fill_color->a = RGBA_COLOR_NONE; msize = size * (D_d_to_u_col(2.0) - D_d_to_u_col(1.0)); /* do it better */ Points = Vect_new_line_struct(); PPoints = Vect_new_line_struct(); Cats = Vect_new_cats_struct(); open_db = table_colors_flag || width_column; if (open_db) { fi = Vect_get_field(Map, (Clist->field > 0 ? Clist->field : 1)); if (fi == NULL) { G_fatal_error(_("Database connection not defined for layer %d"), (Clist->field > 0 ? Clist->field : 1)); } driver = db_start_driver_open_database(fi->driver, fi->database); if (driver == NULL) G_fatal_error(_("Unable to open database <%s> by driver <%s>"), fi->database, fi->driver); } if (table_colors_flag) { /* for reading RRR:GGG:BBB color strings from table */ if (rgb_column == NULL || *rgb_column == '\0') G_fatal_error(_("Color definition column not specified")); db_CatValArray_init(&cvarr_rgb); nrec_rgb = db_select_CatValArray(driver, fi->table, fi->key, rgb_column, NULL, &cvarr_rgb); G_debug(3, "nrec_rgb (%s) = %d", rgb_column, nrec_rgb); if (cvarr_rgb.ctype != DB_C_TYPE_STRING) G_fatal_error(_("Color definition column (%s) not a string. " "Column must be of form RRR:GGG:BBB where RGB values range 0-255."), rgb_column); if (nrec_rgb < 0) G_fatal_error(_("Cannot select data (%s) from table"), rgb_column); G_debug(2, "\n%d records selected from table", nrec_rgb); for (i = 0; i < cvarr_rgb.n_values; i++) { G_debug(4, "cat = %d %s = %s", cvarr_rgb.value[i].cat, rgb_column, db_get_string(cvarr_rgb.value[i].val.s)); } } if (width_column) { if (*width_column == '\0') G_fatal_error(_("Line width column not specified.")); db_CatValArray_init(&cvarr_width); nrec_width = db_select_CatValArray(driver, fi->table, fi->key, width_column, NULL, &cvarr_width); G_debug(3, "nrec_width (%s) = %d", width_column, nrec_width); if (cvarr_width.ctype != DB_C_TYPE_INT && cvarr_width.ctype != DB_C_TYPE_DOUBLE) G_fatal_error(_("Line width column (%s) not a number."), width_column); if (nrec_width < 0) G_fatal_error(_("Cannot select data (%s) from table"), width_column); G_debug(2, "\n%d records selected from table", nrec_width); for (i = 0; i < cvarr_width.n_values; i++) { G_debug(4, "cat = %d %s = %d", cvarr_width.value[i].cat, width_column, (cvarr_width.ctype == DB_C_TYPE_INT ? cvarr_width.value[i].val. i : (int)cvarr_width.value[i].val.d)); } } if (open_db) db_close_database_shutdown_driver(driver); Vect_rewind(Map); /* Is it necessary to reset line/label color in each loop ? */ if (color && !table_colors_flag && !cats_color_flag) D_RGB_color(color->r, color->g, color->b); if (Vect_level(Map) >= 2) nlines = Vect_get_num_lines(Map); line = 0; while (1) { if (Vect_level(Map) >= 2) { line++; if (line > nlines) return 0; if (!Vect_line_alive(Map, line)) continue; ltype = Vect_read_line(Map, Points, Cats, line); } else { ltype = Vect_read_next_line(Map, Points, Cats); switch (ltype) { case -1: fprintf(stderr, _("\nERROR: vector map - can't read\n")); return -1; case -2: /* EOF */ return 0; } } if (!(type & ltype)) continue; if (chcat) { int found = 0; if (id_flag) { /* use line id */ if (!(Vect_cat_in_cat_list(line, Clist))) continue; } else { for (i = 0; i < Cats->n_cats; i++) { if (Cats->field[i] == Clist->field && Vect_cat_in_cat_list(Cats->cat[i], Clist)) { found = 1; break; } } if (!found) continue; } } else if (Clist->field > 0) { int found = 0; for (i = 0; i < Cats->n_cats; i++) { if (Cats->field[i] == Clist->field) { found = 1; break; } } /* lines with no category will be displayed */ if (Cats->n_cats > 0 && !found) continue; } if (table_colors_flag) { /* only first category */ cat = Vect_get_line_cat(Map, line, (Clist->field > 0 ? Clist->field : (Cats->n_cats > 0 ? Cats->field[0] : 1))); if (cat >= 0) { G_debug(3, "display element %d, cat %d", line, cat); /* Read RGB colors from db for current area # */ if (db_CatValArray_get_value(&cvarr_rgb, cat, &cv_rgb) != DB_OK) { custom_rgb = FALSE; } else { sprintf(colorstring, "%s", db_get_string(cv_rgb->val.s)); if (*colorstring != '\0') { G_debug(3, "element %d: colorstring: %s", line, colorstring); if (G_str_to_color(colorstring, &red, &grn, &blu) == 1) { custom_rgb = TRUE; G_debug(3, "element:%d cat %d r:%d g:%d b:%d", line, cat, red, grn, blu); } else { custom_rgb = FALSE; G_warning(_("Error in color definition column (%s), element %d " "with cat %d: colorstring [%s]"), rgb_column, line, cat, colorstring); } } else { custom_rgb = FALSE; G_warning(_("Error in color definition column (%s), element %d with cat %d"), rgb_column, line, cat); } } } /* end if cat */ else { custom_rgb = FALSE; } } /* end if table_colors_flag */ /* random colors */ if (cats_color_flag) { custom_rgb = FALSE; if (Clist->field > 0) { cat = Vect_get_line_cat(Map, line, Clist->field); if (cat >= 0) { G_debug(3, "display element %d, cat %d", line, cat); /* fetch color number from category */ which = (cat % palette_ncolors); G_debug(3, "cat:%d which color:%d r:%d g:%d b:%d", cat, which, palette[which].R, palette[which].G, palette[which].B); custom_rgb = TRUE; red = palette[which].R; grn = palette[which].G; blu = palette[which].B; } } else if (Cats->n_cats > 0) { /* fetch color number from layer */ which = (Cats->field[0] % palette_ncolors); G_debug(3, "layer:%d which color:%d r:%d g:%d b:%d", Cats->field[0], which, palette[which].R, palette[which].G, palette[which].B); custom_rgb = TRUE; red = palette[which].R; grn = palette[which].G; blu = palette[which].B; } } if (nrec_width) { /* only first category */ cat = Vect_get_line_cat(Map, line, (Clist->field > 0 ? Clist->field : (Cats->n_cats > 0 ? Cats->field[0] : 1))); if (cat >= 0) { G_debug(3, "display element %d, cat %d", line, cat); /* Read line width from db for current area # */ if (db_CatValArray_get_value(&cvarr_width, cat, &cv_width) != DB_OK) { width = default_width; } else { width = width_scale * (cvarr_width.ctype == DB_C_TYPE_INT ? cv_width->val. i : (int)cv_width->val.d); if (width < 0) { G_warning(_("Error in line width column (%s), element %d " "with cat %d: line width [%d]"), width_column, line, cat, width); width = default_width; } } } /* end if cat */ else { width = default_width; } D_line_width(width); } /* end if nrec_width */ /* enough of the prep work, lets start plotting stuff */ x = Points->x; y = Points->y; if ((ltype & GV_POINTS) && Symb != NULL) { if (!(color || fcolor || custom_rgb)) continue; x0 = D_u_to_d_col(x[0]); y0 = D_u_to_d_row(y[0]); /* skip if the point is outside of the display window */ /* xy<0 tests make it go ever-so-slightly faster */ if (x0 < 0 || y0 < 0 || x0 > D_get_d_east() || x0 < D_get_d_west() || y0 > D_get_d_south() || y0 < D_get_d_north()) continue; /* use random or RGB column color if given, otherwise reset */ /* centroids always use default color to stand out from underlying area */ if (custom_rgb && (ltype != GV_CENTROID)) { primary_color->r = (unsigned char)red; primary_color->g = (unsigned char)grn; primary_color->b = (unsigned char)blu; D_symbol2(Symb, x0, y0, primary_color, line_color); } else D_symbol(Symb, x0, y0, line_color, fill_color); } else if (color || custom_rgb) { if (!table_colors_flag && !cats_color_flag) D_RGB_color(color->r, color->g, color->b); else { if (custom_rgb) D_RGB_color((unsigned char)red, (unsigned char)grn, (unsigned char)blu); else D_RGB_color(color->r, color->g, color->b); } /* Plot the lines */ if (Points->n_points == 1) /* line with one coor */ D_polydots_abs(x, y, Points->n_points); else /*use different user defined render methods */ D_polyline_abs(x, y, Points->n_points); } } Vect_destroy_line_struct(Points); Vect_destroy_cats_struct(Cats); return 0; /* not reached */ }
int main(int argc, char **argv) { int ret, level; int stat, type, display; int chcat; int has_color, has_fcolor; struct color_rgb color, fcolor; double size; int default_width; double width_scale; double minreg, maxreg, reg; char map_name[GNAME_MAX]; struct GModule *module; struct Option *map_opt; struct Option *color_opt, *fcolor_opt, *rgbcol_opt, *zcol_opt; struct Option *type_opt, *display_opt; struct Option *icon_opt, *size_opt, *sizecolumn_opt, *rotcolumn_opt; struct Option *where_opt; struct Option *field_opt, *cat_opt, *lfield_opt; struct Option *lcolor_opt, *bgcolor_opt, *bcolor_opt; struct Option *lsize_opt, *font_opt, *enc_opt, *xref_opt, *yref_opt; struct Option *attrcol_opt, *maxreg_opt, *minreg_opt; struct Option *width_opt, *wcolumn_opt, *wscale_opt; struct Option *leglab_opt; struct Option *icon_line_opt, *icon_area_opt; struct Flag *id_flag, *cats_acolors_flag, *sqrt_flag, *legend_flag; char *desc; struct cat_list *Clist; LATTR lattr; struct Map_info Map; struct Cell_head window; struct bound_box box; double overlap; stat = 0; /* Initialize the GIS calls */ G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("display")); G_add_keyword(_("graphics")); G_add_keyword(_("vector")); module->description = _("Displays user-specified vector map " "in the active graphics frame."); map_opt = G_define_standard_option(G_OPT_V_MAP); field_opt = G_define_standard_option(G_OPT_V_FIELD_ALL); field_opt->answer = "1"; field_opt->guisection = _("Selection"); display_opt = G_define_option(); display_opt->key = "display"; display_opt->type = TYPE_STRING; display_opt->required = YES; display_opt->multiple = YES; display_opt->answer = "shape"; display_opt->options = "shape,cat,topo,vert,dir,zcoor"; display_opt->description = _("Display"); desc = NULL; G_asprintf(&desc, "shape;%s;cat;%s;topo;%s;vert;%s;dir;%s;zcoor;%s", _("Display geometry of features"), _("Display category numbers of features"), _("Display topology information (nodes, edges)"), _("Display vertices of features"), _("Display direction of linear features"), _("Display z-coordinate of features (only for 3D vector maps)")); display_opt->descriptions = desc; /* Query */ type_opt = G_define_standard_option(G_OPT_V_TYPE); type_opt->answer = "point,line,area,face"; type_opt->options = "point,line,boundary,centroid,area,face"; type_opt->guisection = _("Selection"); cat_opt = G_define_standard_option(G_OPT_V_CATS); cat_opt->guisection = _("Selection"); where_opt = G_define_standard_option(G_OPT_DB_WHERE); where_opt->guisection = _("Selection"); /* Colors */ color_opt = G_define_standard_option(G_OPT_CN); color_opt->label = _("Feature color"); color_opt->guisection = _("Colors"); fcolor_opt = G_define_standard_option(G_OPT_CN); fcolor_opt->key = "fill_color"; fcolor_opt->answer = "200:200:200"; fcolor_opt->label = _("Area fill color"); fcolor_opt->guisection = _("Colors"); rgbcol_opt = G_define_standard_option(G_OPT_DB_COLUMN); rgbcol_opt->key = "rgb_column"; rgbcol_opt->guisection = _("Colors"); rgbcol_opt->label = _("Colorize features according color definition column"); rgbcol_opt->description = _("Color definition in R:G:B form"); zcol_opt = G_define_standard_option(G_OPT_M_COLR); zcol_opt->key = "zcolor"; zcol_opt->description = _("Colorize point or area features according to z-coordinate"); zcol_opt->guisection = _("Colors"); /* Lines */ width_opt = G_define_option(); width_opt->key = "width"; width_opt->type = TYPE_INTEGER; width_opt->answer = "0"; width_opt->guisection = _("Lines"); width_opt->description = _("Line width"); wcolumn_opt = G_define_standard_option(G_OPT_DB_COLUMN); wcolumn_opt->key = "width_column"; wcolumn_opt->guisection = _("Lines"); wcolumn_opt->label = _("Name of numeric column containing line width"); wcolumn_opt->description = _("These values will be scaled by width_scale"); wscale_opt = G_define_option(); wscale_opt->key = "width_scale"; wscale_opt->type = TYPE_DOUBLE; wscale_opt->answer = "1"; wscale_opt->guisection = _("Lines"); wscale_opt->description = _("Scale factor for width_column"); /* Symbols */ icon_opt = G_define_option(); icon_opt->key = "icon"; icon_opt->type = TYPE_STRING; icon_opt->required = NO; icon_opt->multiple = NO; icon_opt->guisection = _("Symbols"); icon_opt->answer = "basic/x"; /* This could also use ->gisprompt = "old,symbol,symbol" instead of ->options */ icon_opt->options = icon_files(); icon_opt->description = _("Point and centroid symbol"); size_opt = G_define_option(); size_opt->key = "size"; size_opt->type = TYPE_DOUBLE; size_opt->answer = "5"; size_opt->guisection = _("Symbols"); size_opt->label = _("Symbol size"); size_opt->description = _("When used with the size_column option this becomes the scale factor"); sizecolumn_opt = G_define_standard_option(G_OPT_DB_COLUMN); sizecolumn_opt->key = "size_column"; sizecolumn_opt->guisection = _("Symbols"); sizecolumn_opt->description = _("Name of numeric column containing symbol size"); rotcolumn_opt = G_define_standard_option(G_OPT_DB_COLUMN); rotcolumn_opt->key = "rotation_column"; rotcolumn_opt->guisection = _("Symbols"); rotcolumn_opt->label = _("Name of numeric column containing symbol rotation angle"); rotcolumn_opt->description = _("Measured in degrees CCW from east"); icon_area_opt = G_define_option(); icon_area_opt->key = "icon_area"; icon_area_opt->type = TYPE_STRING; icon_area_opt->required = NO; icon_area_opt->multiple = NO; icon_area_opt->guisection = _("Legend"); icon_area_opt->answer = "legend/area"; icon_area_opt->options = icon_files(); icon_area_opt->description = _("Area/boundary symbol for legend"); icon_line_opt = G_define_option(); icon_line_opt->key = "icon_line"; icon_line_opt->type = TYPE_STRING; icon_line_opt->required = NO; icon_line_opt->multiple = NO; icon_line_opt->guisection = _("Legend"); icon_line_opt->answer = "legend/line"; icon_line_opt->options = icon_files(); icon_line_opt->description = _("Line symbol for legend"); leglab_opt = G_define_option(); leglab_opt->key = "legend_label"; leglab_opt->type = TYPE_STRING; leglab_opt->guisection = _("Legend"); leglab_opt->description = _("Label to display after symbol in vector legend"); /* Labels */ lfield_opt = G_define_standard_option(G_OPT_V_FIELD); lfield_opt->key = "label_layer"; lfield_opt->required = NO; lfield_opt->guisection = _("Labels"); lfield_opt->label = _("Layer number for labels (default: the given layer number)"); attrcol_opt = G_define_standard_option(G_OPT_DB_COLUMN); attrcol_opt->key = "attribute_column"; attrcol_opt->multiple = NO; /* or fix attr.c, around line 102 */ attrcol_opt->guisection = _("Labels"); attrcol_opt->description = _("Name of column to be displayed as a label"); lcolor_opt = G_define_standard_option(G_OPT_C); lcolor_opt->key = "label_color"; lcolor_opt->answer = "red"; lcolor_opt->label = _("Label color"); lcolor_opt->guisection = _("Labels"); bgcolor_opt = G_define_standard_option(G_OPT_CN); bgcolor_opt->key = "label_bgcolor"; bgcolor_opt->answer = "none"; bgcolor_opt->guisection = _("Labels"); bgcolor_opt->label = _("Label background color"); bcolor_opt = G_define_standard_option(G_OPT_CN); bcolor_opt->key = "label_bcolor"; bcolor_opt->type = TYPE_STRING; bcolor_opt->answer = "none"; bcolor_opt->guisection = _("Labels"); bcolor_opt->label = _("Label border color"); lsize_opt = G_define_option(); lsize_opt->key = "label_size"; lsize_opt->type = TYPE_INTEGER; lsize_opt->answer = "8"; lsize_opt->guisection = _("Labels"); lsize_opt->description = _("Label size (pixels)"); font_opt = G_define_option(); font_opt->key = "font"; font_opt->type = TYPE_STRING; font_opt->guisection = _("Labels"); font_opt->description = _("Font name"); enc_opt = G_define_option(); enc_opt->key = "encoding"; enc_opt->type = TYPE_STRING; enc_opt->guisection = _("Labels"); enc_opt->description = _("Text encoding"); xref_opt = G_define_option(); xref_opt->key = "xref"; xref_opt->type = TYPE_STRING; xref_opt->guisection = _("Labels"); xref_opt->answer = "left"; xref_opt->options = "left,center,right"; xref_opt->description = _("Label horizontal justification"); yref_opt = G_define_option(); yref_opt->key = "yref"; yref_opt->type = TYPE_STRING; yref_opt->guisection = _("Labels"); yref_opt->answer = "center"; yref_opt->options = "top,center,bottom"; yref_opt->description = _("Label vertical justification"); minreg_opt = G_define_option(); minreg_opt->key = "minreg"; minreg_opt->type = TYPE_DOUBLE; minreg_opt->required = NO; minreg_opt->description = _("Minimum region size (average from height and width) " "when map is displayed"); maxreg_opt = G_define_option(); maxreg_opt->key = "maxreg"; maxreg_opt->type = TYPE_DOUBLE; maxreg_opt->required = NO; maxreg_opt->description = _("Maximum region size (average from height and width) " "when map is displayed"); /* Colors */ cats_acolors_flag = G_define_flag(); cats_acolors_flag->key = 'c'; cats_acolors_flag->guisection = _("Colors"); cats_acolors_flag->description = _("Random colors according to category number " "(or layer number if 'layer=-1' is given)"); /* Query */ id_flag = G_define_flag(); id_flag->key = 'i'; id_flag->guisection = _("Selection"); id_flag->description = _("Use values from 'cats' option as feature id"); sqrt_flag = G_define_flag(); sqrt_flag->key = 'r'; sqrt_flag->label = _("Use square root of the value of size_column"); sqrt_flag->description = _("This makes circle areas proportionate to the size_column values " "instead of circle radius"); sqrt_flag->guisection = _("Symbols"); legend_flag = G_define_flag(); legend_flag->key = 's'; legend_flag->label = _("Do not show this layer in vector legend"); legend_flag->guisection = _("Legend"); /* Check command line */ if (G_parser(argc, argv)) exit(EXIT_FAILURE); D_open_driver(); G_get_set_window(&window); /* Check min/max region */ reg = ((window.east - window.west) + (window.north - window.south)) / 2; if (minreg_opt->answer) { minreg = atof(minreg_opt->answer); if (reg < minreg) { G_important_message(_("Region size is lower than minreg, nothing displayed")); exit(EXIT_SUCCESS); } } if (maxreg_opt->answer) { maxreg = atof(maxreg_opt->answer); if (reg > maxreg) { G_important_message(_("Region size is greater than maxreg, nothing displayed")); exit(EXIT_SUCCESS); } } strcpy(map_name, map_opt->answer); default_width = atoi(width_opt->answer); if (default_width < 0) default_width = 0; width_scale = atof(wscale_opt->answer); if (cats_acolors_flag->answer && rgbcol_opt->answer) { G_warning(_("The -%c flag and <%s> option cannot be used together, " "the -%c flag will be ignored!"), cats_acolors_flag->key, rgbcol_opt->key, cats_acolors_flag->key); cats_acolors_flag->answer = FALSE; } color = G_standard_color_rgb(WHITE); has_color = option_to_color(&color, color_opt->answer); fcolor = G_standard_color_rgb(WHITE); has_fcolor = option_to_color(&fcolor, fcolor_opt->answer); size = atof(size_opt->answer); /* if where_opt was specified select categories from db * otherwise parse cat_opt */ Clist = Vect_new_cat_list(); Clist->field = atoi(field_opt->answer); /* open vector */ level = Vect_open_old2(&Map, map_name, "", field_opt->answer); chcat = 0; if (where_opt->answer) { if (Clist->field < 1) G_fatal_error(_("Option <%s> must be > 0"), field_opt->key); chcat = 1; option_to_where(&Map, Clist, where_opt->answer); } else if (cat_opt->answer) { if (Clist->field < 1 && !id_flag->answer) G_fatal_error(_("Option <%s> must be > 0"), field_opt->key); chcat = 1; ret = Vect_str_to_cat_list(cat_opt->answer, Clist); if (ret > 0) G_warning(n_("%d error in cat option", "%d errors in cat option", ret), ret); } type = Vect_option_to_types(type_opt); display = option_to_display(display_opt); /* labels */ options_to_lattr(&lattr, lfield_opt->answer, lcolor_opt->answer, bgcolor_opt->answer, bcolor_opt->answer, atoi(lsize_opt->answer), font_opt->answer, enc_opt->answer, xref_opt->answer, yref_opt->answer); D_setup(0); D_set_reduction(1.0); G_verbose_message(_("Plotting...")); if (level >= 2) Vect_get_map_box(&Map, &box); if (level >= 2 && (window.north < box.S || window.south > box.N || window.east < box.W || window.west > G_adjust_easting(box.E, &window))) { G_warning(_("The bounding box of the map is outside the current region, " "nothing drawn")); } else { overlap = G_window_percentage_overlap(&window, box.N, box.S, box.E, box.W); G_debug(1, "overlap = %f \n", overlap); if (overlap < 1) Vect_set_constraint_region(&Map, window.north, window.south, window.east, window.west, PORT_DOUBLE_MAX, -PORT_DOUBLE_MAX); /* default line width */ if (!wcolumn_opt->answer) D_line_width(default_width); if (display & DISP_SHAPE) { stat += display_shape(&Map, type, Clist, &window, has_color ? &color : NULL, has_fcolor ? &fcolor : NULL, chcat, icon_opt->answer, size, sizecolumn_opt->answer, sqrt_flag->answer ? TRUE : FALSE, rotcolumn_opt->answer, id_flag->answer ? TRUE : FALSE, cats_acolors_flag->answer ? TRUE : FALSE, rgbcol_opt->answer, default_width, wcolumn_opt->answer, width_scale, zcol_opt->answer); if (wcolumn_opt->answer) D_line_width(default_width); } if (has_color) { D_RGB_color(color.r, color.g, color.b); if (display & DISP_DIR) stat += display_dir(&Map, type, Clist, chcat, size); } if (!legend_flag->answer) { write_into_legfile(&Map, type, leglab_opt->answer, map_name, icon_opt->answer, size_opt->answer, color_opt->answer, fcolor_opt->answer, width_opt->answer, icon_area_opt->answer, icon_line_opt->answer, sizecolumn_opt->answer); } /* reset line width: Do we need to get line width from display * driver (not implemented)? It will help restore previous line * width (not just 0) determined by another module (e.g., * d.linewidth). */ if (!wcolumn_opt->answer) D_line_width(0); if (display & DISP_CAT) stat += display_label(&Map, type, Clist, &lattr, chcat); if (attrcol_opt->answer) stat += display_attr(&Map, type, attrcol_opt->answer, Clist, &lattr, chcat); if (display & DISP_ZCOOR) stat += display_zcoor(&Map, type, &lattr); if (display & DISP_VERT) stat += display_vert(&Map, type, &lattr, size); if (display & DISP_TOPO) stat += display_topo(&Map, type, &lattr, size); } D_save_command(G_recreate_command()); D_close_driver(); Vect_close(&Map); Vect_destroy_cat_list(Clist); if (stat != 0) { G_fatal_error(_("Rendering failed")); } G_done_msg(" "); exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { struct GModule *module; struct Option *opt1, *opt2; struct Flag *mapcoords; int R, G, B, color = 0; /* Initialize the GIS calls */ G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("display")); G_add_keyword(_("cartography")); module->description = _("Program for generating and displaying simple graphics on the " "display monitor."); opt1 = G_define_option(); opt1->key = "input"; opt1->type = TYPE_STRING; opt1->required = NO; opt1->description = _("Name of file containing graphics commands, " "if not given reads from standard input"); opt1->gisprompt = "old_file,file,input"; opt2 = G_define_option(); opt2->key = "color"; opt2->type = TYPE_STRING; opt2->required = NO; opt2->description = _("Color to draw with, either a standard GRASS color " "or R:G:B triplet"); opt2->answer = DEFAULT_FG_COLOR; opt2->gisprompt = "old_color,color,color"; mapcoords = G_define_flag(); mapcoords->key = 'm'; mapcoords->description = _("Coordinates are given in map units"); /* Check command line */ if (G_parser(argc, argv)) exit(EXIT_FAILURE); /* default font scaling: 5% of active frame */ hsize = vsize = 5.; if (opt1->answer != NULL) { if ((infile = fopen(opt1->answer, "r")) == NULL) G_fatal_error(_("Graph file <%s> not found"), opt1->answer); } else infile = stdin; /* open graphics window */ if (D_open_driver() != 0) G_fatal_error(_("No graphics device selected. " "Use d.mon to select graphics device.")); /* Parse and select color */ if (opt2->answer != NULL) { color = G_str_to_color(opt2->answer, &R, &G, &B); if (color == 0) G_fatal_error(_("[%s]: No such color"), opt2->answer); if (color == 1) { D_RGB_color(R, G, B); set_last_color(R, G, B, RGBA_COLOR_OPAQUE); } else /* (color==2) is "none" */ set_last_color(0, 0, 0, RGBA_COLOR_NONE); } if (mapcoords->answer) { mapunits = TRUE; D_setup(0); } else { D_setup2(0, 0, 100, 0, 0, 100); mapunits = FALSE; } /* Do the graphics */ set_graph_stuff(); set_text_size(); graphics(infile); D_save_command(G_recreate_command()); D_close_driver(); exit(EXIT_SUCCESS); }
/* Same as path() but get start/stop from the command line (for non-interactive use) Hamish Bowman March 2007 */ int coor_path(struct Map_info *Map, const struct color_rgb *hcolor, int be_bold, double start_x, double start_y, double end_x, double end_y) { int ret; double nx, ny, fx, fy, tx, ty, msize, maxdist; struct line_pnts *Points; int start_node, end_node; double fdist, tdist, cost; Points = Vect_new_line_struct(); msize = 10 * (D_d_to_u_col(2.0) - D_d_to_u_col(1.0)); /* do it better */ G_debug(1, "msize = %f\n", msize); /* x1 = D_d_to_u_col ((double)(screen_x-WDTH)); y1 = D_d_to_u_row ((double)(screen_y-WDTH)); x2 = D_d_to_u_col ((double)(screen_x+WDTH)); y2 = D_d_to_u_row ((double)(screen_y+WDTH)); x1 = fabs ( x2 - x1 ); y1 = fabs ( y2 - y1 ); if ( x1 > y1 ) maxdist = x1; else maxdist = y1; */ /** maxdist = 10 pixels on the display (WDTH*2); ? ** ie related to zoom level ?? just use msize ?? **/ maxdist = msize; G_debug(1, "Maximum distance in map units = %f\n", maxdist); /* Vect_find_node(): find number of nearest node, 0 if not found */ start_node = Vect_find_node(Map, start_x, start_y, 0.0, maxdist, 0); if (start_node > 0) { Vect_get_node_coor(Map, start_node, &nx, &ny, NULL); fprintf(stderr, _("Node %d: %f %f\n"), start_node, nx, ny); } if (start_node > 0) { fx = nx; fy = ny; } else { fx = start_x; fy = start_y; } D_RGB_color(hcolor->r, hcolor->g, hcolor->b); D_plot_icon(fx, fy, G_ICON_BOX, 0.0, msize); end_node = Vect_find_node(Map, end_x, end_y, 0.0, maxdist, 0); if (end_node > 0) { Vect_get_node_coor(Map, end_node, &nx, &ny, NULL); fprintf(stderr, _("Node %d: %f %f\n"), end_node, nx, ny); } if (end_node > 0) { tx = nx; ty = ny; } else { tx = end_x; ty = end_y; } D_RGB_color(hcolor->r, hcolor->g, hcolor->b); D_plot_icon(tx, ty, G_ICON_CROSS, 0.0, msize); G_debug(2, "find path %f %f -> %f %f", fx, fy, tx, ty); ret = Vect_net_shortest_path_coor(Map, fx, fy, 0.0, tx, ty, 0.0, 5 * maxdist, 5 * maxdist, &cost, Points, NULL, NULL, NULL, &fdist, &tdist); if (ret == 0) { fprintf(stdout, _("Destination unreachable\n")); } else { fprintf(stdout, _("Costs on the network = %f\n"), cost); fprintf(stdout, _(" Distance to the network = %f, " "distance from the network = %f\n\n"), fdist, tdist); display(Map, Points, hcolor, 1, 1, be_bold); } return 0; }
static void symbol(const SYMBOL *Symb, double x0, double y0, const RGBA_Color *fill_color, const RGBA_Color *line_color, const RGBA_Color *string_color) { int i, j, k; const SYMBPART *part; const SYMBCHAIN *chain; double xp, yp; double *x, *y; double sx = D_get_d_to_u_xconv(); double sy = D_get_d_to_u_yconv(); G_debug(2, "D_symbol(): %d parts", Symb->count); for (i = 0; i < Symb->count; i++) { part = Symb->part[i]; switch (part->type) { case S_POLYGON: /* draw background fills */ if ((part->fcolor.color == S_COL_DEFAULT && fill_color->a != RGBA_COLOR_NONE) || part->fcolor.color == S_COL_DEFINED) { if (part->fcolor.color == S_COL_DEFAULT) D_RGB_color(fill_color->r, fill_color->g, fill_color->b); else D_RGB_color(part->fcolor.r, part->fcolor.g, part->fcolor.b); for (j = 0; j < part->count; j++) { /* for each component polygon */ chain = part->chain[j]; x = G_malloc(sizeof(double) * chain->scount); y = G_malloc(sizeof(double) * chain->scount); for (k = 0; k < chain->scount; k++) { x[k] = x0 + sx * chain->sx[k]; y[k] = y0 - sy * chain->sy[k]; } D_polygon_abs(x, y, chain->scount); G_free(x); G_free(y); } } /* again, to draw the lines */ if ((part->color.color == S_COL_DEFAULT && line_color->a != RGBA_COLOR_NONE) || part->color.color == S_COL_DEFINED) { if (part->color.color == S_COL_DEFAULT) D_RGB_color(line_color->r, line_color->g, line_color->b); else D_RGB_color(part->color.r, part->color.g, part->color.b); for (j = 0; j < part->count; j++) { chain = part->chain[j]; D_begin(); for (k = 0; k < chain->scount; k++) { xp = x0 + sx * chain->sx[k]; yp = y0 - sy * chain->sy[k]; if (k == 0) D_move_abs(xp, yp); else D_cont_abs(xp, yp); } D_end(); D_stroke(); } } break; case S_STRING: if (part->color.color == S_COL_NONE) break; else if (part->color.color == S_COL_DEFAULT && string_color->a != RGBA_COLOR_NONE) D_RGB_color(string_color->r, string_color->g, string_color->b); else D_RGB_color(part->color.r, part->color.g, part->color.b); chain = part->chain[0]; D_begin(); for (j = 0; j < chain->scount; j++) { xp = x0 + sx * chain->sx[j]; yp = y0 - sy * chain->sy[j]; if (j == 0) D_move_abs(xp, yp); else D_cont_abs(xp, yp); } D_end(); D_stroke(); break; } /* switch */ } /* for loop */ }
int display_topo(struct Map_info *Map, int type, LATTR *lattr, double dsize) { int ltype, num, el; double msize; struct line_pnts *Points; struct line_cats *Cats; char text[50]; LATTR lattr2 = *lattr; if (Vect_level(Map) < 2) { G_warning(_("Unable to display topology, not available." "Please try to rebuild topology using " "v.build or v.build.all.")); return 1; } msize = dsize * (D_d_to_u_col(2.0) - D_d_to_u_col(1.0)); /* do it better */ lattr2.xref = lattr->xref == LRIGHT ? LLEFT : LRIGHT; G_debug(1, "display topo:"); Points = Vect_new_line_struct(); Cats = Vect_new_cats_struct(); D_RGB_color(lattr->color.R, lattr->color.G, lattr->color.B); D_text_size(lattr->size, lattr->size); if (lattr->font) D_font(lattr->font); if (lattr->enc) D_encoding(lattr->enc); Vect_rewind(Map); num = Vect_get_num_lines(Map); G_debug(1, "n_lines = %d", num); /* Lines */ for (el = 1; el <= num; el++) { if (!Vect_line_alive(Map, el)) continue; ltype = Vect_read_line(Map, Points, Cats, el); G_debug(3, "ltype = %d", ltype); switch (ltype) { case -1: G_fatal_error(_("Unable to read vector map")); case -2: /* EOF */ return 0; } if (!(type & ltype)) continue; /* used for both lines and labels */ sprintf(text, "%d", el); show_label_line(Points, ltype, lattr, text); } num = Vect_get_num_nodes(Map); G_debug(1, "n_nodes = %d", num); /* Nodes */ for (el = 1; el <= num; el++) { double X, Y; if (!Vect_node_alive(Map, el)) continue; Vect_get_node_coor(Map, el, &X, &Y, NULL); G_debug(3, "node = %d", el); sprintf(text, "n%d", el); show_label(&X, &Y, &lattr2, text); D_plot_icon(X, Y, G_ICON_BOX, 0, msize); } Vect_destroy_line_struct(Points); Vect_destroy_cats_struct(Cats); return 0; }
int bar(double cx, double cy, int size, double scale, double *val, int ncols, COLOR * ocolor, COLOR * colors, int y_center, double *max_reference, int do3d) { int i; double max; double x0, y0, x1, y1, dx, dy; double bw; /* bar width */ double pixel; /* pixel size */ struct line_pnts *Points, *max_Points; G_debug(4, "bar(): cx = %f cy = %f", cx, cy); Points = Vect_new_line_struct(); max_Points = Vect_new_line_struct(); pixel = D_d_to_u_col(2) - D_d_to_u_col(1); /* do it better */ /* Bottom (y0) */ max = 0; for (i = 0; i < ncols; i++) { if (val[i] > max) max = val[i]; } /* debug */ /* printf("%f \n", max_reference); */ if (y_center == 0) /* draw the columns with the bottom at the y value of the point */ y0 = cy; else /* center the columns around the y value of the point */ y0 = cy - scale * max * pixel / 2; /* Left (x0) */ x0 = cx - size * pixel / 2; bw = size * pixel / ncols; dx = bw / 5.0; dy = dx * 1.5; if (max_reference) { /* Draw polygon outlining max value in dataset with no fill color */ for (i = 0; i < ncols; i++) { Vect_reset_line(max_Points); Vect_append_point(max_Points, x0 + i * bw, y0, 0); Vect_append_point(max_Points, x0 + (i + 1) * bw, y0, 0); Vect_append_point(max_Points, x0 + (i + 1) * bw, y0 + scale * max_reference[i] * pixel, 0); Vect_append_point(max_Points, x0 + i * bw, y0 + scale * max_reference[i] * pixel, 0); Vect_append_point(max_Points, x0 + i * bw, y0, 0); /* the outline color : default is black */ D_RGB_color(ocolor->r, ocolor->g, ocolor->b); D_polyline_abs(max_Points->x, max_Points->y, max_Points->n_points); } } /* Draw polygon for each value */ for (i = 0; i < ncols; i++) { Vect_reset_line(Points); Vect_append_point(Points, x0 + i * bw, y0, 0); Vect_append_point(Points, x0 + (i + 1) * bw, y0, 0); Vect_append_point(Points, x0 + (i + 1) * bw, y0 + scale * val[i] * pixel, 0); Vect_append_point(Points, x0 + i * bw, y0 + scale * val[i] * pixel, 0); Vect_append_point(Points, x0 + i * bw, y0, 0); if (!colors[i].none) { D_RGB_color(colors[i].r, colors[i].g, colors[i].b); D_polygon_abs(Points->x, Points->y, Points->n_points); } D_RGB_color(ocolor->r, ocolor->g, ocolor->b); D_polyline_abs(Points->x, Points->y, Points->n_points); if (do3d) { /* up */ Vect_reset_line(Points); y1 = y0 + scale * val[i] * pixel; Vect_append_point(Points, x0 + i * bw, y1, 0); Vect_append_point(Points, x0 + i * bw + dx, y1 + dy, 0); Vect_append_point(Points, x0 + (i + 1) * bw + dx, y1 + dy, 0); Vect_append_point(Points, x0 + (i + 1) * bw, y1, 0); Vect_append_point(Points, x0 + i * bw, y1, 0); if (!colors[i].none) { D_RGB_color(colors[i].r, colors[i].g, colors[i].b); D_polygon_abs(Points->x, Points->y, Points->n_points); } D_RGB_color(ocolor->r, ocolor->g, ocolor->b); /* do not draw the same line twice */ Points->n_points = 4; D_polyline_abs(Points->x, Points->y, Points->n_points); /* right */ Vect_reset_line(Points); x1 = x0 + (i + 1) * bw; Vect_append_point(Points, x1 + dx + 0.5 * pixel, y1 + dy, 0); Vect_append_point(Points, x1 + dx + 0.5 * pixel, y0 + dy, 0); Vect_append_point(Points, x1, y0, 0); Vect_append_point(Points, x1, y1, 0); Vect_append_point(Points, x1 + dx + 0.5 * pixel, y1 + dy, 0); if (!colors[i].none && val[i] > 0) { D_RGB_color(colors[i].r, colors[i].g, colors[i].b); D_polygon_abs(Points->x, Points->y, Points->n_points); } D_RGB_color(ocolor->r, ocolor->g, ocolor->b); /* do not draw the same line twice */ Points->n_points = 3; D_polyline_abs(Points->x, Points->y, Points->n_points); } } /* tidy up */ Vect_destroy_line_struct(Points); Vect_destroy_line_struct(max_Points); return 0; }
int display_area(struct Map_info *Map, struct cat_list *Clist, const struct Cell_head *window, const struct color_rgb *bcolor, const struct color_rgb *fcolor, int chcat, int id_flag, int cats_color_flag, int default_width, double width_scale, struct Colors *zcolors, dbCatValArray *cvarr_rgb, struct Colors *colors, dbCatValArray *cvarr_width, int nrec_width) { int num, area, isle, n_isles, n_points; double xl, yl; struct line_pnts *Points, * APoints, **IPoints; struct line_cats *Cats; int n_ipoints_alloc; int cat, centroid; int red, grn, blu; int i, custom_rgb, found; int width; struct bound_box box; if (Vect_level(Map) < 2) { G_warning(_("Unable to display areas, topology not available. " "Please try to rebuild topology using " "v.build or v.build.all.")); return 1; } G_debug(1, "display areas:"); centroid = 0; Points = Vect_new_line_struct(); APoints = Vect_new_line_struct(); n_ipoints_alloc = 10; IPoints = (struct line_pnts **)G_malloc(n_ipoints_alloc * sizeof(struct line_pnts *)); for (i = 0; i < n_ipoints_alloc; i++) { IPoints[i] = Vect_new_line_struct(); } Cats = Vect_new_cats_struct(); num = Vect_get_num_areas(Map); G_debug(2, "\tn_areas = %d", num); for (area = 1; area <= num; area++) { G_debug(3, "\tarea = %d", area); if (!Vect_area_alive(Map, area)) continue; centroid = Vect_get_area_centroid(Map, area); if (!centroid) { continue; } /* Check box */ Vect_get_area_box(Map, area, &box); if (box.N < window->south || box.S > window->north || box.E < window->west || box.W > window->east) { if (window->proj != PROJECTION_LL) continue; else { /* out of bounds for -180 to 180, try 0 to 360 as well */ if (box.N < window->south || box.S > window->north) continue; if (box.E + 360 < window->west || box.W + 360 > window->east) continue; } } custom_rgb = FALSE; found = FALSE; if (chcat) { if (id_flag) { if (!(Vect_cat_in_cat_list(area, Clist))) continue; } else { G_debug(3, "centroid = %d", centroid); if (centroid < 1) continue; Vect_read_line(Map, Points, Cats, centroid); for (i = 0; i < Cats->n_cats; i++) { G_debug(3, " centroid = %d, field = %d, cat = %d", centroid, Cats->field[i], Cats->cat[i]); if (Cats->field[i] == Clist->field && Vect_cat_in_cat_list(Cats->cat[i], Clist)) { found = TRUE; break; } } if (!found) continue; } } else if (Clist->field > 0) { found = FALSE; G_debug(3, "\tcentroid = %d", centroid); if (centroid < 1) continue; Vect_read_line(Map, NULL, Cats, centroid); for (i = 0; i < Cats->n_cats; i++) { G_debug(3, "\tcentroid = %d, field = %d, cat = %d", centroid, Cats->field[i], Cats->cat[i]); if (Cats->field[i] == Clist->field) { found = TRUE; break; } } /* lines with no category will be displayed */ if (Cats->n_cats > 0 && !found) continue; } /* fill */ Vect_get_area_points(Map, area, APoints); G_debug(3, "\tn_points = %d", APoints->n_points); if (APoints->n_points < 3) { G_warning(_("Invalid area %d skipped (not enough points)"), area); continue; } Vect_reset_line(Points); Vect_append_points(Points, APoints, GV_FORWARD); n_points = Points->n_points; xl = Points->x[n_points - 1]; yl = Points->y[n_points - 1]; n_isles = Vect_get_area_num_isles(Map, area); if (n_isles >= n_ipoints_alloc) { IPoints = (struct line_pnts **)G_realloc(IPoints, (n_isles + 10) * sizeof(struct line_pnts *)); for (i = n_ipoints_alloc; i < n_isles + 10; i++) { IPoints[i] = Vect_new_line_struct(); } n_ipoints_alloc = n_isles + 10; } for (i = 0; i < n_isles; i++) { isle = Vect_get_area_isle(Map, area, i); Vect_get_isle_points(Map, isle, IPoints[i]); Vect_append_points(Points, IPoints[i], GV_FORWARD); Vect_append_point(Points, xl, yl, 0.0); /* ??? */ } cat = Vect_get_area_cat(Map, area, (Clist->field > 0 ? Clist->field : (Cats->n_cats > 0 ? Cats->field[0] : 1))); if (!centroid && cat == -1) { continue; } /* z height colors */ if (zcolors) { if (Rast_get_d_color(&Points->z[0], &red, &grn, &blu, zcolors) == 1) custom_rgb = TRUE; else custom_rgb = FALSE; } /* custom colors */ if (colors || cvarr_rgb) { custom_rgb = get_table_color(cat, area, colors, cvarr_rgb, &red, &grn, &blu); } /* random colors */ if (cats_color_flag) { custom_rgb = get_cat_color(area, Cats, Clist, &red, &grn, &blu); } /* line width */ if (nrec_width) { width = (int) get_property(cat, area, cvarr_width, (double) width_scale, (double) default_width); D_line_width(width); } if (fcolor || zcolors) { if (!cvarr_rgb && !cats_color_flag && !zcolors && !colors) { D_RGB_color(fcolor->r, fcolor->g, fcolor->b); D_polygon_abs(Points->x, Points->y, Points->n_points); } else { if (custom_rgb) { D_RGB_color((unsigned char)red, (unsigned char)grn, (unsigned char)blu); } else { D_RGB_color(fcolor->r, fcolor->g, fcolor->b); } if (cat >= 0) { D_polygon_abs(Points->x, Points->y, Points->n_points); } } } /* boundary */ if (bcolor) { if (custom_rgb) { D_RGB_color((unsigned char)red, (unsigned char)grn, (unsigned char)blu); } else { D_RGB_color(bcolor->r, bcolor->g, bcolor->b); } /* use different user defined render methods */ D_polyline_abs(APoints->x, APoints->y, APoints->n_points); for (i = 0; i < n_isles; i++) { /* use different user defined render methods */ D_polyline_abs(IPoints[i]->x, IPoints[i]->y, IPoints[i]->n_points); } } } if ((colors || cvarr_rgb) && get_num_color_rules_skipped() > 0) G_warning(_n("%d invalid color rule for areas skipped", "%d invalid color rules for areas skipped", get_num_color_rules_skipped()), get_num_color_rules_skipped()); Vect_destroy_line_struct(Points); Vect_destroy_line_struct(APoints); for (i = 0; i < n_ipoints_alloc; i++) { Vect_destroy_line_struct(IPoints[i]); } G_free(IPoints); Vect_destroy_cats_struct(Cats); return 0; }
int draw_line(int ltype, int line, const struct line_pnts *Points, const struct line_cats *Cats, int chcat, double size, int default_width, const struct cat_list *Clist, SYMBOL * Symb, RGBA_Color * primary_color, int *n_points, int *n_lines, int *n_centroids, int *n_boundaries, int *n_faces, RGBA_Color *secondary_color) { double var_size, rotation; int i; double x0, y0; double *x, *y; int found, cat; rotation = 0.0; var_size = size; cat = -1; if (!ltype) return 0; if (Points->n_points == 0) return 0; found = FALSE; if (chcat) { for (i = 0; i < Cats->n_cats; i++) { if (Cats->field[i] == Clist->field && Vect_cat_in_cat_list(Cats->cat[i], Clist)) { found = TRUE; break; } } if (!found) return 0; } else if (Clist->field > 0) { for (i = 0; i < Cats->n_cats; i++) { if (Cats->field[i] == Clist->field) { found = TRUE; break; } } /* lines with no category will be displayed */ if (Cats->n_cats > 0 && !found) return 0; } G_debug(3, "\tdisplay feature %d, cat %d", line, cat); /* enough of the prep work, lets start plotting stuff */ x = Points->x; y = Points->y; if ((ltype & GV_POINTS)) { x0 = x[0]; y0 = y[0]; /* skip if the point is outside of the display window */ /* xy < 0 tests make it go ever-so-slightly faster */ if (x0 > D_get_u_east() || x0 < D_get_u_west() || y0 < D_get_u_south() || y0 > D_get_u_north()) return 0; D_line_width(default_width); D_symbol2(Symb, x0, y0, primary_color, secondary_color); } else { /* Plot the lines */ D_line_width(default_width); D_RGB_color(primary_color->r, primary_color->g, primary_color->b); if (Points->n_points == 1) /* line with one coor */ D_polydots_abs(x, y, Points->n_points); else /* use different user defined render methods */ D_polyline_abs(x, y, Points->n_points); } switch (ltype) { case GV_POINT: (*n_points)++; break; case GV_LINE: (*n_lines)++; break; case GV_CENTROID: (*n_centroids)++; break; case GV_BOUNDARY: (*n_boundaries)++; break; case GV_FACE: (*n_faces)++; break; default: break; } return 1; }