int main(int argc, char **argv) { struct GModule *module; struct Option *bg_color_opt, *fg_color_opt, *coords, *n_arrow, *fsize, *width_opt, *rotation_opt, *lbl_opt; struct Flag *no_text, *rotate_text, *rads; double east, north; double rotation; double fontsize, line_width; int rot_with_text; /* Initialize the GIS calls */ G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("display")); G_add_keyword(_("cartography")); module->description = _("Displays a north arrow on the graphics monitor."); n_arrow = G_define_option(); n_arrow->key = "style"; n_arrow->description = _("North arrow style"); n_arrow->options = "1a,1b,2,3,4,5,6,7a,7b,8a,8b,9,fancy_compass,basic_compass,arrow1,arrow2,arrow3,star"; G_asprintf((char **)&(n_arrow->descriptions), "1a;%s;" "1b;%s;" "2;%s;" "3;%s;" "4;%s;" "5;%s;" "6;%s;" "7a;%s;" "7b;%s;" "8a;%s;" "8b;%s;" "9;%s;" "fancy_compass;%s;" "basic_compass;%s;" "arrow1;%s;" "arrow2;%s;" "arrow3;%s;" "star;%s;", _("Two color arrowhead"), _("Two color arrowhead with circle"), _("Narrow with blending N"), _("Long with small arrowhead"), _("Inverted narrow inside a circle"), _("Triangle and N inside a circle"), _("Arrowhead and N inside a circle"), _("Tall half convex arrowhead"), _("Tall half concave arrowhead"), _("Thin arrow in a circle"), _("Fat arrow in a circle"), _("One color arrowhead"), _("Fancy compass"), _("Basic compass"), _("Simple arrow"), _("Thin arrow"), _("Fat arrow"), _("4-point star")); n_arrow->answer = "1a"; n_arrow->guisection = _("Style"); n_arrow->gisprompt = "old,northarrow,northarrow"; coords = G_define_option(); coords->key = "at"; coords->key_desc = "x,y"; coords->type = TYPE_DOUBLE; coords->answer = "85.0,15.0"; coords->options = "0-100"; coords->label = _("Screen coordinates of the rectangle's top-left corner"); coords->description = _("(0,0) is lower-left of the display frame"); rotation_opt = G_define_option(); rotation_opt->key = "rotation"; rotation_opt->type = TYPE_DOUBLE; rotation_opt->required = NO; rotation_opt->answer = "0"; rotation_opt->description = _("Rotation angle in degrees (counter-clockwise)"); lbl_opt = G_define_option(); lbl_opt->key = "label"; lbl_opt->required = NO; lbl_opt->answer = "N"; lbl_opt->description = _("Displayed letter on the top of arrow"); lbl_opt->guisection = _("Text"); fg_color_opt = G_define_standard_option(G_OPT_C); fg_color_opt->label = _("Line color"); fg_color_opt->guisection = _("Colors"); bg_color_opt = G_define_standard_option(G_OPT_CN); bg_color_opt->key = "fill_color"; bg_color_opt->label = _("Fill color"); bg_color_opt->answer = _("black"); bg_color_opt->guisection = _("Colors"); width_opt = G_define_option(); width_opt->key = "width"; width_opt->type = TYPE_DOUBLE; width_opt->answer = "0"; width_opt->description = _("Line width"); fsize = G_define_option(); fsize->key = "fontsize"; fsize->type = TYPE_DOUBLE; fsize->required = NO; fsize->answer = "14"; fsize->options = "1-360"; fsize->description = _("Font size"); fsize->guisection = _("Text"); no_text = G_define_flag(); no_text->key = 't'; no_text->description = _("Draw the symbol without text"); no_text->guisection = _("Text"); rotate_text = G_define_flag(); rotate_text->key = 'w'; rotate_text->description = _("Do not rotate text with symbol"); rotate_text->guisection = _("Text"); rads = G_define_flag(); rads->key = 'r'; rads->description = _("Use radians instead of degrees for rotation"); /* TODO: - add a -n flag to rotate to match true north instead of grid north. Similar to 'g.region -n' but use the at=x,y coord for the convergence angle calc. (assuming that's the center of the icon) */ if (G_parser(argc, argv)) exit(EXIT_FAILURE); sscanf(coords->answers[0], "%lf", &east); sscanf(coords->answers[1], "%lf", &north); fontsize = atof(fsize->answer); if (no_text->answer) fontsize = -1; rot_with_text = 0; if (!rotate_text->answer) rot_with_text = 1; /* Convert to radians */ rotation = atof(rotation_opt->answer); if (!rads->answer) rotation *= M_PI / 180.0; rotation = fmod(rotation, 2.0 * M_PI); if (rotation < 0.0) rotation += 2.0 * M_PI; /* Parse and select foreground color */ fg_color = D_parse_color(fg_color_opt->answer, 0); /* Parse and select background color */ bg_color = D_parse_color(bg_color_opt->answer, 1); if (bg_color == 0) do_background = FALSE; line_width = atof(width_opt->answer); if (line_width < 0) line_width = 0; else if (line_width > 72) line_width = 72; D_open_driver(); draw_n_arrow(east, north, rotation, lbl_opt->answer, rot_with_text, fontsize, n_arrow->answer, line_width); D_save_command(G_recreate_command()); D_close_driver(); exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { struct GModule *module; struct { struct Option *text; struct Option *size; struct Option *fgcolor; struct Option *bgcolor; struct Option *line; struct Option *at; struct Option *rotation; struct Option *align; struct Option *linespacing; struct Option *font; struct Option *path; struct Option *charset; struct Option *input; } opt; struct { struct Flag *p; struct Flag *g; struct Flag *b; struct Flag *r; struct Flag *s; } flag; /* options and flags */ char *text; double size; double x, y; int line; double rotation; char align[3]; double linespacing; char bold; /* window info */ struct rectinfo win; /* command file */ FILE *cmd_fp; char buf[512]; int first_text; int linefeed; int set_l; double orig_x, orig_y; double prev_x, prev_y; double set_x, set_y; double east, north; int do_background, fg_color, bg_color; /* initialize the GIS calls */ G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("display")); G_add_keyword(_("cartography")); module->description = _("Draws text in the active display frame on the graphics monitor using the current font."); opt.text = G_define_option(); opt.text->key = "text"; opt.text->type = TYPE_STRING; opt.text->required = NO; opt.text->description = _("Text to display"); opt.text->guisection = _("Input"); opt.input = G_define_standard_option(G_OPT_F_INPUT); opt.input->required = NO; opt.input->description = _("Input file"); opt.input->guisection = _("Input"); opt.fgcolor = G_define_option(); opt.fgcolor->key = "color"; opt.fgcolor->type = TYPE_STRING; opt.fgcolor->answer = DEFAULT_COLOR; opt.fgcolor->required = NO; opt.fgcolor->description = _("Text color, either a standard GRASS color or R:G:B triplet"); opt.fgcolor->gisprompt = "old_color,color,color"; opt.fgcolor->guisection = _("Text"); opt.bgcolor = G_define_option(); opt.bgcolor->key = "bgcolor"; opt.bgcolor->type = TYPE_STRING; opt.bgcolor->required = NO; opt.bgcolor->description = _("Text background color, either a standard GRASS color or R:G:B triplet"); opt.bgcolor->gisprompt = "old_color,color,color"; opt.bgcolor->guisection = _("Text"); opt.rotation = G_define_option(); opt.rotation->key = "rotation"; opt.rotation->type = TYPE_DOUBLE; opt.rotation->required = NO; opt.rotation->answer = "0"; opt.rotation->description = _("Rotation angle in degrees (counter-clockwise)"); opt.rotation->guisection = _("Text"); opt.linespacing = G_define_option(); opt.linespacing->key = "linespacing"; opt.linespacing->type = TYPE_DOUBLE; opt.linespacing->required = NO; opt.linespacing->answer = "1.25"; opt.linespacing->description = _("Line spacing"); opt.linespacing->guisection = _("Text"); opt.at = G_define_option(); opt.at->key = "at"; opt.at->key_desc = "x,y"; opt.at->type = TYPE_DOUBLE; opt.at->required = NO; opt.at->description = _("Screen position at which text will begin to be drawn (percentage, [0,0] is lower left)"); opt.at->guisection = _("Position"); opt.line = G_define_option(); opt.line->key = "line"; opt.line->required = NO; opt.line->type = TYPE_INTEGER; opt.line->options = "1-1000"; opt.line->description = _("The screen line number on which text will begin to be drawn"); opt.line->guisection = _("Position"); opt.align = G_define_option(); opt.align->key = "align"; opt.align->type = TYPE_STRING; opt.align->required = NO; opt.align->answer = "ll"; opt.align->options = "ll,lc,lr,cl,cc,cr,ul,uc,ur"; opt.align->description = _("Text alignment"); opt.align->guisection = _("Position"); opt.font = G_define_option(); opt.font->key = "font"; opt.font->type = TYPE_STRING; opt.font->required = NO; opt.font->description = _("Font name"); opt.font->guisection = _("Font settings"); opt.size = G_define_option(); opt.size->key = "size"; opt.size->type = TYPE_DOUBLE; opt.size->required = NO; opt.size->answer = "5"; opt.size->options = "0-100"; opt.size->description = _("Height of letters in percentage of available frame height"); opt.size->guisection = _("Font settings"); opt.path = G_define_standard_option(G_OPT_F_INPUT); opt.path->key = "path"; opt.path->required = NO; opt.path->description = _("Path to font file"); opt.path->gisprompt = "old,font,file"; opt.path->guisection = _("Font settings"); opt.charset = G_define_option(); opt.charset->key = "charset"; opt.charset->type = TYPE_STRING; opt.charset->required = NO; opt.charset->description = _("Text encoding (only applicable to TrueType fonts)"); opt.charset->guisection = _("Font settings"); flag.p = G_define_flag(); flag.p->key = 'p'; flag.p->description = _("Screen position in pixels ([0,0] is top left)"); flag.p->guisection = _("Position"); flag.g = G_define_flag(); flag.g->key = 'g'; flag.g->description = _("Screen position in geographic coordinates"); flag.g->guisection = _("Position"); flag.b = G_define_flag(); flag.b->key = 'b'; flag.b->description = _("Use bold text"); flag.b->guisection = _("Text"); flag.r = G_define_flag(); flag.r->key = 'r'; flag.r->description = _("Use radians instead of degrees for rotation"); flag.r->guisection = _("Text"); flag.s = G_define_flag(); flag.s->key = 's'; flag.s->description = _("Font size is height in pixels"); flag.s->guisection = _("Font settings"); /* check command line */ if (G_parser(argc, argv)) exit(1); /* parse and check options and flags */ if ((opt.line->answer && opt.at->answer) || (flag.p->answer && flag.g->answer)) G_fatal_error(_("Please choose only one placement method")); text = opt.text->answer; line = (opt.line->answer ? atoi(opt.line->answer) : 1); /* calculate rotation angle in radian */ rotation = atof(opt.rotation->answer); if (!flag.r->answer) rotation *= M_PI / 180.0; rotation = fmod(rotation, 2.0 * M_PI); if (rotation < 0.0) rotation += 2.0 * M_PI; strncpy(align, opt.align->answer, 2); linespacing = atof(opt.linespacing->answer); bold = flag.b->answer; D_open_driver(); if (opt.font->answer) D_font(opt.font->answer); else if (opt.path->answer) D_font(opt.path->answer); if (opt.charset->answer) D_encoding(opt.charset->answer); D_setup_unity(0); /* figure out where to put text */ D_get_src(&win.t, &win.b, &win.l, &win.r); if (flag.s->answer) size = atof(opt.size->answer); else #ifdef BACKWARD_COMPATIBILITY size = atof(opt.size->answer) / 100.0 * (win.b - win.t) / linespacing; #else size = atof(opt.size->answer) / 100.0 * (win.b - win.t); #endif fg_color = D_parse_color(opt.fgcolor->answer, TRUE); if (opt.bgcolor->answer) { do_background = 1; bg_color = D_parse_color(opt.bgcolor->answer, TRUE); if (bg_color == 0) /* ie color="none" */ do_background = 0; } else do_background = 0; set_color(opt.fgcolor->answer); orig_x = orig_y = 0; if (opt.at->answer) { if (get_coordinates(&x, &y, &east, &north, win, opt.at->answers, flag.p->answer, flag.g->answer)) G_fatal_error(_("Invalid coordinates")); orig_x = x; orig_y = y; } else { x = win.l + (size * linespacing + 0.5) - size; /* d.text: +5 */ y = win.t + line * (size * linespacing + 0.5); } prev_x = x; prev_y = y; D_text_size(size, size); D_text_rotation(rotation * 180.0 / M_PI); if (text) { double x2, y2; x2 = x; y2 = y; if (text[0]) draw_text(text, &x2, &y2, size, align, rotation, bold, do_background, fg_color, bg_color); /* reset */ D_text_size(5, 5); D_text_rotation(0.0); D_save_command(G_recreate_command()); D_close_driver(); exit(EXIT_SUCCESS); } if (!opt.input->answer || strcmp(opt.input->answer, "-") == 0) cmd_fp = stdin; else { cmd_fp = fopen(opt.input->answer, "r"); if (!cmd_fp) G_fatal_error(_("Unable to open input file <%s>"), opt.input->answer); } if (isatty(fileno(cmd_fp))) fprintf(stderr, _("\nPlease enter text instructions. Enter EOF (ctrl-d) on last line to quit\n")); set_x = set_y = set_l = 0; first_text = 1; linefeed = 1; /* do the plotting */ while (fgets(buf, sizeof(buf), cmd_fp)) { int buf_len; char *buf_ptr, *ptr; buf_len = strlen(buf) - 1; for (; buf[buf_len] == '\r' || buf[buf_len] == '\n'; buf_len--) ; buf[buf_len + 1] = 0; if (buf[0] == '.' && buf[1] != '.') { int i; double d; G_squeeze(buf); /* added 6/91 DBS @ CWU */ for (buf_ptr = buf + 2; *buf_ptr == ' '; buf_ptr++) ; buf_len = strlen(buf_ptr); switch (buf[1] & 0x7f) { case 'F': /* font */ if ((ptr = strchr(buf_ptr, ':'))) *ptr = 0; D_font(buf_ptr); if (ptr) D_encoding(ptr + 1); break; case 'C': /* color */ set_color(buf_ptr); fg_color = D_parse_color(buf_ptr, 1); break; case 'G': /* background color */ bg_color = D_parse_color(buf_ptr, 1); do_background = 1; break; case 'S': /* size */ i = 0; if (strchr("+-", buf_ptr[0])) i = 1; d = atof(buf_ptr); if (buf_ptr[buf_len - 1] != 'p') #ifdef BACKWARD_COMPATIBILITY d *= (win.b - win.t) / 100.0 / linespacing; #else d *= (win.b - win.t) / 100.0; #endif size = d + (i ? size : 0); D_text_size(size, size); break; case 'B': /* bold */ bold = (atoi(buf_ptr) ? 1 : 0); break; case 'A': /* align */ strncpy(align, buf_ptr, 2); break; case 'R': /* rotation */ i = 0; if (strchr("+-", buf_ptr[0])) i = 1; d = atof(buf_ptr); if (buf_ptr[buf_len - 1] != 'r') d *= M_PI / 180.0; d += (i ? rotation : 0.0); rotation = fmod(d, 2.0 * M_PI); if (rotation < 0.0) rotation += 2.0 * M_PI; D_text_rotation(rotation * 180.0 / M_PI); break; case 'I': /* linespacing */ linespacing = atof(buf_ptr); break; case 'X': /* x */ set_l = 0; set_x = 1; i = 0; if (strchr("+-", buf_ptr[0])) i = 1; d = atof(buf_ptr); if (buf_ptr[buf_len - 1] == '%') /* percentage */ d *= (win.r - win.l) / 100.0; else if (buf_ptr[buf_len - 1] != 'p') /* column */ d = (d - 1) * size * linespacing + 0.5; x = prev_x = d + (i ? x : orig_x); break; case 'Y': /* y */ set_l = 0; set_y = 1; i = 0; if (strchr("+-", buf_ptr[0])) i = 1; d = atof(buf_ptr); if (buf_ptr[buf_len - 1] == '%') /* percentage */ d = win.b - d * (win.b - win.t) / 100.0; else if (buf_ptr[buf_len - 1] != 'p') /* row */ d *= size * linespacing + 0.5; y = prev_y = d + (i ? y : orig_y); break; case 'L': /* linefeed */ set_l = 1; linefeed = (atoi(buf_ptr) ? 1 : 0); break; case 'E': i = 0; if (strchr("+-", buf_ptr[0])) i = 1; d = atof(buf_ptr); if (buf_ptr[buf_len - 1] == '%') d *= (win.r - win.l) / 100.0; else if (buf_ptr[buf_len - 1] != 'p') d = D_u_to_d_col(d); x = prev_x = orig_x = d + (i ? orig_x : win.l); break; case 'N': i = 0; if (strchr("+-", buf_ptr[0])) i = 1; d = atof(buf_ptr); if (buf_ptr[buf_len - 1] == '%') d *= (win.b - win.t) / 100.0; else if (buf_ptr[buf_len - 1] != 'p') d = D_u_to_d_row(d); y = prev_y = orig_y = d + (i ? orig_y : win.t); break; } } else { buf_ptr = buf; if (buf[0] == '.' && buf[1] == '.') buf_ptr++; if (!first_text && (linefeed || set_l)) { /* if x is not given, increment x */ if (!set_x) x = prev_x + (size * linespacing + 0.5) * sin(rotation); /* if y is not given, increment y */ if (!set_y) y = prev_y + (size * linespacing + 0.5) * cos(rotation); prev_x = x; prev_y = y; } set_x = set_y = set_l = first_text = 0; draw_text(buf_ptr, &x, &y, size, align, rotation, bold, do_background, fg_color, bg_color); } } if (cmd_fp != stdin) fclose(cmd_fp); /* reset */ D_text_size(5, 5); D_text_rotation(0.0); D_close_driver(); exit(EXIT_SUCCESS); }
int do_symbol(char *buff) { double xper, yper; int size; int ix, iy; char *symb_name; SYMBOL *Symb; char *line_color_str, *fill_color_str; RGBA_Color *line_color, *fill_color; int R, G, B, ret; line_color = G_malloc(sizeof(RGBA_Color)); fill_color = G_malloc(sizeof(RGBA_Color)); symb_name = G_malloc(sizeof(char) * strlen(buff) + 1); /* well, it won't be any bigger than this */ line_color_str = G_malloc(sizeof(char) * strlen(buff) + 1); fill_color_str = G_malloc(sizeof(char) * strlen(buff) + 1); G_debug(3, "do_symbol() [%s]", buff); /* set default colors so colors are optional */ strcpy(line_color_str, DEFAULT_FG_COLOR); strcpy(fill_color_str, "grey"); if (sscanf (buff, "%*s %s %d %lf %lf %s %s", symb_name, &size, &xper, &yper, line_color_str, fill_color_str) < 4) { G_warning(_("Problem parsing command [%s]"), buff); return (-1); } if (mapunits) { ix = (int)(D_u_to_d_col(xper) + 0.5); iy = (int)(D_u_to_d_row(yper) + 0.5); /* consider size in map units too? maybe as percentage of display? perhaps use "size * D_get_u_to_d_yconv()" to convert */ } else { if (xper < 0. || yper < 0. || xper > 100. || yper > 100.) return (-1); ix = l + (int)(xper * xincr); iy = b - (int)(yper * yincr); } /* parse line color */ ret = G_str_to_color(line_color_str, &R, &G, &B); line_color->r = (unsigned char)R; line_color->g = (unsigned char)G; line_color->b = (unsigned char)B; if (ret == 1) { /* here alpha is only used as an on/off switch, otherwise unused by the display drivers */ line_color->a = RGBA_COLOR_OPAQUE; } else if (ret == 2) line_color->a = RGBA_COLOR_NONE; else { G_warning(_("[%s]: No such color"), line_color_str); return (-1); } /* parse fill color */ ret = G_str_to_color(fill_color_str, &R, &G, &B); fill_color->r = (unsigned char)R; fill_color->g = (unsigned char)G; fill_color->b = (unsigned char)B; if (ret == 1) fill_color->a = RGBA_COLOR_OPAQUE; else if (ret == 2) fill_color->a = RGBA_COLOR_NONE; else { G_warning(_("[%s]: No such color"), fill_color_str); return (-1); } Symb = S_read(symb_name); if (Symb == NULL) { G_warning(_("Cannot read symbol, cannot display points")); return (-1); } else S_stroke(Symb, size, rotation, 0); D_symbol(Symb, ix, iy, line_color, fill_color); /* restore previous d.graph draw color */ if (last_color.a == RGBA_COLOR_OPAQUE) R_RGB_color(last_color.r, last_color.g, last_color.b); else if (last_color.a == RGBA_COLOR_NONE) D_raster_use_color(D_parse_color(DEFAULT_BG_COLOR, 0)); else /* unset or bad */ R_RGB_color(line_color->r, line_color->g, line_color->b); G_free(symb_name); G_free(line_color_str); G_free(fill_color_str); G_free(line_color); G_free(fill_color); return (0); }
int main(int argc, char **argv) { int text_height; int text_width; struct Categories cats; struct Range range; struct Colors pcolors; char title[GNAME_MAX]; double tt, tb, tl, tr; double t, b, l, r; struct GModule *module; struct Option *opt1; struct Option *opt2, *bg_opt; struct Option *opt4; struct Option *opt5; struct Flag *flag1; struct Flag *flag2; struct Flag *flag3; /* Initialize the GIS calls */ G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("display")); G_add_keyword(_("histogram")); G_add_keyword(_("statistics")); module->description = _("Displays a histogram in the form of a pie or bar chart " "for a user-specified raster map."); opt1 = G_define_standard_option(G_OPT_R_MAP); opt1->description = _("Raster map for which histogram will be displayed"); opt4 = G_define_option(); opt4->key = "style"; opt4->description = _("Indicate if a pie or bar chart is desired"); opt4->type = TYPE_STRING; opt4->required = NO; opt4->options = "pie,bar"; opt4->answer = "bar"; /* The color option specifies the color for the labels, tic-marks, * and borders of the chart. */ opt2 = G_define_standard_option(G_OPT_C); opt2->label = _("Color for text and axes"); bg_opt = G_define_standard_option(G_OPT_CN); bg_opt->key = "bgcolor"; bg_opt->label = _("Background color"); bg_opt->answer = DEFAULT_BG_COLOR; #ifdef CAN_DO_AREAS opt3 = G_define_option(); opt3->key = "type"; opt3->description = _("Indicate if cell counts or map areas should be displayed"); opt3->type = TYPE_STRING; opt3->required = NO; opt3->answer = "count"; opt3->options = "count,area"; #endif opt5 = G_define_option(); opt5->key = "nsteps"; opt5->description = _("Number of steps to divide the data range into (fp maps only)"); opt5->type = TYPE_INTEGER; opt5->required = NO; opt5->answer = "255"; flag1 = G_define_flag(); flag1->key = 'n'; flag1->description = _("Display information for null cells"); flag3 = G_define_flag(); flag3->key = 'c'; flag3->description = _("Report for ranges defined in cats file (fp maps only)"); if (G_parser(argc, argv)) exit(EXIT_FAILURE); map_name = opt1->answer; color = D_parse_color(opt2->answer, FALSE); type = COUNT; #ifdef CAN_DO_AREAS if (strcmp(opt3->answer, "count") == 0) type = COUNT; else type = AREA; #endif if (strcmp(opt4->answer, "bar") == 0) style = BAR; else style = PIE; if (sscanf(opt5->answer, "%d", &nsteps) != 1) G_fatal_error(_("Invalid number of steps: %s"), opt5->answer); cat_ranges = flag3->answer; if (cat_ranges && nsteps != 255) G_warning(_("When -C flag is set, the nsteps argument is ignored")); nodata = flag1->answer; if (Rast_read_colors(map_name, "", &pcolors) == -1) G_fatal_error(_("Color file for <%s> not available"), map_name); if (Rast_read_cats(map_name, "", &cats) == -1) G_fatal_error(_("Category file for <%s> not available"), map_name); if (Rast_read_range(map_name, "", &range) == -1) G_fatal_error(_("Range information for <%s> not available"), map_name); /* get the distribution statistics */ get_stats(map_name, &dist_stats); /* set up the graphics driver and initialize its color-table */ D_open_driver(); D_setup_unity(0); /* 0 = don't clear frame */ D_get_src(&t, &b, &l, &r); /* clear the frame, if requested to do so */ if (strcmp(bg_opt->answer, "none") != 0) D_erase(bg_opt->answer); /* draw a title for */ sprintf(title, "%s", map_name); text_height = (b - t) * 0.05; text_width = (r - l) * 0.05 * 0.50; D_text_size(text_width, text_height); D_get_text_box(title, &tt, &tb, &tl, &tr); D_pos_abs(l + (r - l) / 2 - (tr - tl) / 2, t + (b - t) * 0.07); D_use_color(color); D_text(title); /* plot the distributrion statistics */ if (style == PIE) pie(&dist_stats, &pcolors); else bar(&dist_stats, &pcolors); D_save_command(G_recreate_command()); D_close_driver(); exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { struct GModule *module; struct Option *bg_color_opt, *fg_color_opt, *coords, *fsize, *barstyle, *text_placement, *length_opt, *segm_opt, *units_opt, *label_opt, *width_scale_opt; struct Flag *feet, *no_text, *n_symbol; struct Cell_head W; double east, north; double fontsize; int bar_style, text_position, units; double length; int segm; char *label; double width_scale; /* Initialize the GIS calls */ G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("display")); G_add_keyword(_("cartography")); module->description = _("Displays a barscale on the graphics monitor."); feet = G_define_flag(); feet->key = 'f'; feet->description = _("Use feet/miles instead of meters"); no_text = G_define_flag(); no_text->key = 't'; no_text->description = _("Draw the scale bar without text"); no_text->guisection = _("Text"); n_symbol = G_define_flag(); n_symbol->key = 'n'; n_symbol->description = _("Display north-arrow symbol."); n_symbol->guisection = _("Style"); barstyle = G_define_option(); barstyle->key = "style"; barstyle->description = _("Type of barscale to draw"); barstyle->options = "classic,line,solid,hollow,full_checker,part_checker,mixed_checker,tail_checker,up_ticks,down_ticks,both_ticks,arrow_ends"; barstyle->answer = "classic"; barstyle->gisprompt = "old,barscale,barscale"; barstyle->guisection = _("Style"); G_asprintf((char **)&(barstyle->descriptions), "classic;%s;" "line;%s;" "solid;%s;" "hollow;%s;" "full_checker;%s;" "part_checker;%s;" "mixed_checker;%s;" "tail_checker;%s;" "up_ticks;%s;" "down_ticks;%s;" "both_ticks;%s;" "arrow_ends;%s", _("Classic style"), _("Line style"), _("Solid style"), _("Hollow style"), _("Full checker style"), _("Part checker style"), _("Mixed checker style"), _("Tail checker style"), _("Up ticks style"), _("Down ticks style"), _("Both ticks style"), _("Arrow ends style")); coords = G_define_option(); coords->key = "at"; coords->key_desc = "x,y"; coords->type = TYPE_DOUBLE; coords->answer = "0.0,10.0"; coords->options = "0-100"; coords->label = _("Screen coordinates of the rectangle's top-left corner"); coords->description = _("(0,0) is lower-left of the display frame"); length_opt = G_define_option(); length_opt->key = "length"; length_opt->key_desc = "integer"; length_opt->type = TYPE_INTEGER; length_opt->answer = "0"; length_opt->options = "0-"; length_opt->label = _("Length of barscale in map units"); units_opt = G_define_option(); units_opt->key = "units"; units_opt->description = _("Barscale units to display"); units_opt->options = "meters, kilometers, feet, miles"; label_opt = G_define_option(); label_opt->key = "label"; label_opt->description = _("Custom label of unit"); label_opt->type = TYPE_STRING; label_opt->guisection = _("Text"); segm_opt = G_define_option(); segm_opt->key = "segment"; segm_opt->type = TYPE_INTEGER; segm_opt->answer = "10"; segm_opt->options = "1-100"; segm_opt->label = _("Number of segments"); segm_opt->guisection = _("Style"); fg_color_opt = G_define_standard_option(G_OPT_C); fg_color_opt->label = _("Bar scale and text color"); fg_color_opt->guisection = _("Colors"); bg_color_opt = G_define_standard_option(G_OPT_CN); bg_color_opt->key = "bgcolor"; bg_color_opt->answer = "white"; bg_color_opt->label = _("Background color (drawn behind the bar)"); bg_color_opt->guisection = _("Colors"); text_placement = G_define_option(); text_placement->key = "text_position"; text_placement->description = _("Text position"); text_placement->options = "under,over,left,right"; text_placement->answer = "right"; text_placement->guisection = _("Text"); width_scale_opt = G_define_option(); width_scale_opt->key = "width_scale"; width_scale_opt->type = TYPE_DOUBLE; width_scale_opt->required = NO; width_scale_opt->answer = "1"; width_scale_opt->options = "0.5-100"; width_scale_opt->description = _("Scale factor to change bar width"); fsize = G_define_option(); fsize->key = "fontsize"; fsize->type = TYPE_DOUBLE; fsize->required = NO; fsize->answer = "12"; fsize->options = "1-360"; fsize->description = _("Font size"); fsize->guisection = _("Text"); G_option_exclusive(feet, units_opt, NULL); if (G_parser(argc, argv)) exit(EXIT_FAILURE); G_get_window(&W); if (W.proj == PROJECTION_LL) G_fatal_error(_("%s does not work with a latitude-longitude location"), argv[0]); north_arrow = n_symbol->answer ? TRUE : FALSE; switch (barstyle->answer[0]) { case 'c': bar_style = STYLE_CLASSIC_BAR; break; case 'p': bar_style = STYLE_PART_CHECKER; break; case 'f': bar_style = STYLE_FULL_CHECKER; break; case 'm': bar_style = STYLE_MIXED_CHECKER; break; case 't': bar_style = STYLE_TAIL_CHECKER; break; case 'l': bar_style = STYLE_THIN_WITH_ENDS; break; case 's': bar_style = STYLE_SOLID_BAR; break; case 'h': bar_style = STYLE_HOLLOW_BAR; break; case 'u': bar_style = STYLE_TICKS_UP; break; case 'd': bar_style = STYLE_TICKS_DOWN; break; case 'b': bar_style = STYLE_TICKS_BOTH; break; case 'a': bar_style = STYLE_ARROW_ENDS; break; default: G_fatal_error(_("Programmer error")); } switch (text_placement->answer[0]) { case 'u': text_position = TEXT_UNDER; break; case 'o': text_position = TEXT_OVER; break; case 'l': text_position = TEXT_LEFT; break; case 'r': text_position = TEXT_RIGHT; break; default: G_fatal_error(_("Programmer error")); } sscanf(coords->answers[0], "%lf", &east); sscanf(coords->answers[1], "%lf", &north); length = atof(length_opt->answer); sscanf(segm_opt->answer, "%d", &segm); if (feet->answer == 1){ use_feet = 1; units = U_FEET; label = "ft"; } else { if (!units_opt->answer) units = G_database_unit(); else units = G_units(units_opt->answer); switch (units) { case U_METERS: label = "m"; break; case U_KILOMETERS: label = "km"; break; case U_FEET: use_feet = 1; label = "ft"; break; case U_USFEET: use_feet = 1; label = "ft"; break; case U_MILES: use_feet = 1; label = "mi"; break; default: units = U_METERS; label = "m"; } } if (label_opt->answer){ label = label_opt->answer; } fontsize = atof(fsize->answer); if (no_text->answer) fontsize = -1; width_scale = atof(width_scale_opt->answer); /* Parse and select foreground color */ fg_color = D_parse_color(fg_color_opt->answer, 0); /* Parse and select background color */ bg_color = D_parse_color(bg_color_opt->answer, 1); if (bg_color == 0) do_background = FALSE; D_open_driver(); D_setup(0); draw_scale(east, north, length, segm, units, label, bar_style, text_position, width_scale, fontsize); D_save_command(G_recreate_command()); D_close_driver(); exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { char *map_name; int maptype; int color; int i; int thin, lines, steps; int fp; int label_indent; int hide_catnum, hide_catstr, show_ticks, show_bg, hide_nodata, do_smooth; struct Categories cats; struct Colors colors; struct GModule *module; struct Option *opt_rast2d, *opt_rast3d, *opt_color, *opt_lines, *opt_thin, *opt_labelnum, *opt_at, *opt_use, *opt_range, *opt_font, *opt_path, *opt_charset, *opt_fontsize, *opt_title, *opt_ticks, *opt_tstep, *opt_brdcolor, *opt_bgcolor, *opt_tit_fontsize, *opt_digits, *opt_units; struct Flag *hidestr, *hidenum, *hidenodata, *smooth, *flipit, *histo, *showtick, *showbg, *log_sc; double X0, X1, Y0, Y1; int flip, UserRange; double UserRangeMin, UserRangeMax, UserRangeTemp; double *catlist; int catlistCount, use_catlist, ticksCount; double fontsize; char *title; char *units; double *tick_values; double t_step; int colorb, colorbg; double tit_fontsize; int log_scale, digits; /* Initialize the GIS calls */ G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("display")); G_add_keyword(_("cartography")); G_add_keyword(_("legend")); module->description = _("Displays a legend for a 2D or 3D raster map in the active frame " "of the graphics monitor."); opt_rast2d = G_define_standard_option(G_OPT_R_MAP); opt_rast2d->key = "raster"; opt_rast2d->required = NO; opt_rast2d->guisection = _("Input"); opt_rast3d = G_define_standard_option(G_OPT_R3_MAP); opt_rast3d->key = "raster_3d"; opt_rast3d->required = NO; opt_rast3d->guisection = _("Input"); opt_title = G_define_option(); opt_title->key = "title"; opt_title->type = TYPE_STRING; opt_title->required = NO; opt_title->description = _("Legend title"); opt_title->guisection = _("Title"); opt_tit_fontsize = G_define_option(); opt_tit_fontsize->key = "title_fontsize"; opt_tit_fontsize->type = TYPE_DOUBLE; opt_tit_fontsize->required = NO; opt_tit_fontsize->options = "1-360"; opt_tit_fontsize->label = _("Title font size"); opt_tit_fontsize->description = _("Default: Same as fontsize"); opt_tit_fontsize->guisection = _("Title"); opt_lines = G_define_option(); opt_lines->key = "lines"; opt_lines->type = TYPE_INTEGER; opt_lines->answer = "0"; opt_lines->options = "0-1000"; opt_lines->description = _("Number of text lines (useful for truncating long legends)"); opt_lines->guisection = _("Advanced"); opt_thin = G_define_option(); opt_thin->key = "thin"; opt_thin->type = TYPE_INTEGER; opt_thin->required = NO; opt_thin->answer = "1"; opt_thin->options = "1-1000"; opt_thin->description = _("Thinning factor (thin=10 gives cats 0,10,20...)"); opt_thin->guisection = _("Advanced"); opt_units = G_define_option(); opt_units->key = "units"; opt_units->type = TYPE_STRING; opt_units->required = NO; opt_units->description = _("Units to display after labels (e.g. meters)"); opt_units->guisection = _("Advanced"); opt_labelnum = G_define_option(); opt_labelnum->key = "labelnum"; opt_labelnum->type = TYPE_INTEGER; opt_labelnum->answer = "5"; opt_labelnum->options = "2-100"; opt_labelnum->description = _("Number of text labels for smooth gradient legend"); opt_labelnum->guisection = _("Gradient"); opt_ticks = G_define_option(); opt_ticks->key = "label_values"; opt_ticks->type = TYPE_DOUBLE; opt_ticks->required = NO; opt_ticks->description = _("Specific values to draw ticks"); opt_ticks->required = NO; opt_ticks->multiple = YES; opt_ticks->guisection = _("Gradient"); opt_tstep = G_define_option(); opt_tstep->key = "label_step"; opt_tstep->type = TYPE_DOUBLE; opt_tstep->required = NO; opt_tstep->description = _("Display label every step"); opt_tstep->guisection = _("Gradient"); opt_digits = G_define_option(); opt_digits->key = "digits"; opt_digits->type = TYPE_INTEGER; opt_digits->required = NO; opt_digits->description = _("Number of digits after decimal point"); opt_digits->guisection = _("Advanced"); opt_digits->answer = NULL; opt_digits->options = "0-6"; opt_at = G_define_option(); opt_at->key = "at"; opt_at->key_desc = "bottom,top,left,right"; opt_at->type = TYPE_DOUBLE; /* needs to be TYPE_DOUBLE to get past options check */ opt_at->required = NO; opt_at->options = "0-100"; opt_at->label = _("Size and placement as percentage of screen coordinates " "(0,0 is lower left)"); opt_at->description = opt_at->key_desc; opt_at->answer = NULL; opt_use = G_define_option(); opt_use->key = "use"; opt_use->type = TYPE_DOUBLE; /* string as it is fed through the parser? */ opt_use->required = NO; opt_use->description = _("List of discrete category numbers/values for legend"); opt_use->multiple = YES; opt_use->guisection = _("Subset"); opt_range = G_define_option(); opt_range->key = "range"; opt_range->key_desc = "min,max"; opt_range->type = TYPE_DOUBLE; /* should it be type_double or _string ?? */ opt_range->required = NO; opt_range->description = _("Use a subset of the map range for the legend (min,max)"); opt_range->guisection = _("Subset"); opt_color = G_define_standard_option(G_OPT_C); opt_color->label = _("Text color"); opt_color->guisection = _("Font settings"); opt_font = G_define_option(); opt_font->key = "font"; opt_font->type = TYPE_STRING; opt_font->required = NO; opt_font->description = _("Font name"); opt_font->guisection = _("Font settings"); opt_fontsize = G_define_option(); opt_fontsize->key = "fontsize"; opt_fontsize->type = TYPE_DOUBLE; opt_fontsize->required = NO; opt_fontsize->options = "1-360"; opt_fontsize->label = _("Font size"); opt_fontsize->description = _("Default: Auto-scaled"); opt_fontsize->guisection = _("Font settings"); opt_path = G_define_standard_option(G_OPT_F_INPUT); opt_path->key = "path"; opt_path->required = NO; opt_path->description = _("Path to font file"); opt_path->gisprompt = "old_file,font,file"; opt_path->guisection = _("Font settings"); opt_charset = G_define_option(); opt_charset->key = "charset"; opt_charset->type = TYPE_STRING; opt_charset->required = NO; opt_charset->description = _("Text encoding (only applicable to TrueType fonts)"); opt_charset->guisection = _("Font settings"); opt_brdcolor = G_define_standard_option(G_OPT_CN); opt_brdcolor->key = "border_color"; opt_brdcolor->answer = "black"; opt_brdcolor->label = _("Border color"); opt_brdcolor->guisection = _("Background"); opt_bgcolor = G_define_standard_option(G_OPT_CN); opt_bgcolor->key = "bgcolor"; opt_bgcolor->answer = "white"; opt_bgcolor->label = _("Background color"); opt_bgcolor->guisection = _("Background"); hidestr = G_define_flag(); hidestr->key = 'v'; hidestr->description = _("Do not show category labels"); hidestr->guisection = _("Advanced"); hidenum = G_define_flag(); hidenum->key = 'c'; hidenum->description = _("Do not show category numbers"); hidenum->guisection = _("Advanced"); showtick = G_define_flag(); showtick->key = 't'; showtick->description = _("Draw legend ticks for labels"); showtick->guisection = _("Gradient"); hidenodata = G_define_flag(); hidenodata->key = 'n'; hidenodata->description = _("Skip categories with no label"); hidenodata->guisection = _("Advanced"); smooth = G_define_flag(); smooth->key = 's'; smooth->description = _("Draw smooth gradient"); smooth->guisection = _("Gradient"); flipit = G_define_flag(); flipit->key = 'f'; flipit->description = _("Flip legend"); flipit->guisection = _("Advanced"); histo = G_define_flag(); histo->key = 'd'; histo->description = _("Add histogram to smoothed legend"); histo->guisection = _("Gradient"); showbg = G_define_flag(); showbg->key = 'b'; showbg->description = _("Show background"); showbg->guisection = _("Background"); log_sc = G_define_flag(); log_sc->key = 'l'; log_sc->description = _("Use logarithmic scale"); log_sc->guisection = _("Advanced"); G_option_required(opt_rast2d, opt_rast3d, NULL); G_option_exclusive(opt_rast2d, opt_rast3d, NULL); G_option_exclusive(hidenum, opt_ticks, NULL); G_option_exclusive(hidenum, opt_tstep, NULL); /* Check command line */ if (G_parser(argc, argv)) exit(EXIT_FAILURE); if (opt_rast2d->answer) { map_name = opt_rast2d->answer; maptype = MAP_TYPE_RASTER2D; } else { map_name = opt_rast3d->answer; maptype = MAP_TYPE_RASTER3D; } if (opt_title->answer) title = opt_title->answer; else title = ""; if (opt_units->answer) { units = opt_units->answer; } else units = ""; hide_catstr = hidestr->answer; /* note hide_catstr gets changed and re-read below */ hide_catnum = hidenum->answer; show_ticks = showtick->answer; hide_nodata = hidenodata->answer; do_smooth = smooth->answer; flip = flipit->answer; show_bg = showbg->answer; log_scale = log_sc->answer; if (showtick->answer) { label_indent = 12; } else label_indent = 6; if (opt_digits->answer != NULL) sscanf(opt_digits->answer, "%d", &digits); else digits = -1; color = D_parse_color(opt_color->answer, TRUE); if (opt_lines->answer != NULL) sscanf(opt_lines->answer, "%d", &lines); thin = 1; if (opt_thin->answer != NULL) sscanf(opt_thin->answer, "%d", &thin); if (!thin) thin = 1; if (opt_labelnum->answer != NULL) sscanf(opt_labelnum->answer, "%d", &steps); if ((opt_tstep->answer) || (opt_ticks->answer)) steps = 0; if (opt_tstep->answer != NULL) t_step = atof(opt_tstep->answer); ticksCount = 0; if (opt_ticks->answer != NULL) { tick_values = (double *)G_calloc(100 + 1, sizeof(double)); for (i = 0; i < 100; i++) /* fill with dummy values */ tick_values[i] = 1.0 * (i + 1); tick_values[i] = 0; for (i = 0; (opt_ticks->answers[i] != NULL) && i < 100; i++) tick_values[i] = atof(opt_ticks->answers[i]); ticksCount = i; } catlistCount = 0; if (opt_use->answer != NULL) { /* should this be answerS ? */ use_catlist = TRUE; catlist = (double *)G_calloc(100 + 1, sizeof(double)); for (i = 0; i < 100; i++) /* fill with dummy values */ catlist[i] = 1.0 * (i + 1); catlist[i] = 0; for (i = 0; (opt_use->answers[i] != NULL) && i < 100; i++) catlist[i] = atof(opt_use->answers[i]); catlistCount = i; } else use_catlist = FALSE; UserRange = FALSE; if (opt_range->answer != NULL) { /* should this be answerS ? */ sscanf(opt_range->answers[0], "%lf", &UserRangeMin); sscanf(opt_range->answers[1], "%lf", &UserRangeMax); UserRange = TRUE; if (UserRangeMin > UserRangeMax) { UserRangeTemp = UserRangeMax; UserRangeMax = UserRangeMin; UserRangeMin = UserRangeTemp; flip = !flip; } } if (maptype == MAP_TYPE_RASTER2D) { if (Rast_read_colors(map_name, "", &colors) == -1) G_fatal_error(_("Color file for <%s> not available"), map_name); fp = Rast_map_is_fp(map_name, ""); Rast_read_cats(map_name, "", &cats); } else { if (Rast3d_read_colors(map_name, "", &colors) == -1) G_fatal_error(_("Color file for <%s> not available"), map_name); fp = TRUE; /* currently raster 3D is always floating point */ Rast3d_read_cats(map_name, "", &cats); } if (fp && !use_catlist) { do_smooth = TRUE; /* fprintf(stderr, "FP map found - switching gradient legend on\n"); */ flip = !flip; } D_open_driver(); /* Parse and select background color */ colorb = D_parse_color(opt_brdcolor->answer, TRUE); colorbg = D_parse_color(opt_bgcolor->answer, TRUE); if (opt_font->answer) D_font(opt_font->answer); else if (opt_path->answer) D_font(opt_path->answer); if (opt_fontsize->answer != NULL) fontsize = atof(opt_fontsize->answer); else fontsize = 12; /* dummy placeholder, should never be called */ if (opt_charset->answer) D_encoding(opt_charset->answer); if (opt_tit_fontsize->answer != NULL) tit_fontsize = atof(opt_tit_fontsize->answer); else tit_fontsize = 0; if (opt_at->answer != NULL) { sscanf(opt_at->answers[0], "%lf", &Y1); sscanf(opt_at->answers[1], "%lf", &Y0); sscanf(opt_at->answers[2], "%lf", &X0); sscanf(opt_at->answers[3], "%lf", &X1); } else { /* default */ Y1 = 12; Y0 = 88; X0 = 3; X1 = 7; if (histo->answer) { X0 += 5; X1 += 5; } } if (show_bg) draw(map_name, maptype, color, thin, lines, steps, fp, label_indent, hide_catnum, hide_catstr, show_ticks, hide_nodata, do_smooth, cats, colors, X0, X1, Y0, Y1, flip, UserRange, UserRangeMin, UserRangeMax, catlist, catlistCount, use_catlist, ticksCount, fontsize, tit_fontsize, title, tick_values, t_step, colorb, colorbg, opt_use, opt_at, opt_fontsize, opt_tstep, opt_range, histo, hidestr, log_scale, 0, digits, units); draw(map_name, maptype, color, thin, lines, steps, fp, label_indent, hide_catnum, hide_catstr, show_ticks, hide_nodata, do_smooth, cats, colors, X0, X1, Y0, Y1, flip, UserRange, UserRangeMin, UserRangeMax, catlist, catlistCount, use_catlist, ticksCount, fontsize, tit_fontsize, title, tick_values, t_step, colorb, colorbg, opt_use, opt_at, opt_fontsize, opt_tstep, opt_range, histo, hidestr, log_scale, 1, digits, units); D_close_driver(); exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { int colorg = 0; int colorb = 0; int colort = 0; int colorbg = 0; double size = 0., gsize = 0.; /* initialize to zero */ double east, north; int do_text, fontsize, mark_type, line_width, dirn; struct GModule *module; struct Option *opt1, *opt2, *opt3, *opt4, *fsize, *tcolor, *lwidth, *direction, *bgcolor; struct Flag *noborder, *notext, *geogrid, *nogrid, *wgs84, *cross, *fiducial, *dot, *align; struct pj_info info_in; /* Proj structures */ struct pj_info info_out; /* Proj structures */ struct Cell_head wind; /* Initialize the GIS calls */ G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("display")); G_add_keyword(_("cartography")); G_add_keyword(_("graticule")); module->description = _("Overlays a user-specified grid " "in the active display frame on the graphics monitor."); opt2 = G_define_option(); opt2->key = "size"; opt2->key_desc = "value"; opt2->type = TYPE_STRING; opt2->required = YES; opt2->label = _("Size of grid to be drawn (in map units)"); opt2->description = _("0 for north-south resolution of the current region. " "In map units or DDD:MM:SS format. " "Example: \"1000\" or \"0:10\""); opt3 = G_define_standard_option(G_OPT_M_COORDS); opt3->key = "origin"; opt3->answer = "0,0"; opt3->multiple = NO; opt3->description = _("Lines of the grid pass through this coordinate"); direction = G_define_option(); direction->key = "direction"; direction->type = TYPE_STRING; direction->required = NO; direction->answer = "both"; direction->options = "both,east-west,north-south"; direction->description = _("Draw only east-west lines, north-south lines, or both "); direction->guisection = _("Disable"); lwidth = G_define_option(); lwidth->key = "width"; lwidth->type = TYPE_DOUBLE; lwidth->required = NO; lwidth->description = _("Grid line width"); opt1 = G_define_standard_option(G_OPT_C); opt1->answer = "gray"; opt1->label = _("Grid color"); opt1->guisection = _("Color"); opt4 = G_define_standard_option(G_OPT_C); opt4->key = "border_color"; opt4->label = _("Border color"); opt4->guisection = _("Color"); tcolor = G_define_standard_option(G_OPT_C); tcolor->key = "text_color"; tcolor->answer = "gray"; tcolor->label = _("Text color"); tcolor->guisection = _("Color"); bgcolor = G_define_standard_option(G_OPT_CN); bgcolor->key = "bgcolor"; bgcolor->answer = "none"; bgcolor->label = _("Background color"); bgcolor->guisection = _("Color"); fsize = G_define_option(); fsize->key = "fontsize"; fsize->type = TYPE_INTEGER; fsize->required = NO; fsize->answer = "9"; fsize->options = "1-72"; fsize->description = _("Font size for gridline coordinate labels"); align = G_define_flag(); align->key = 'a'; align->description = _("Align the origin to the east-north corner of the current region"); geogrid = G_define_flag(); geogrid->key = 'g'; geogrid->description = _("Draw geographic grid (referenced to current ellipsoid)"); geogrid->guisection = _("Draw"); wgs84 = G_define_flag(); wgs84->key = 'w'; wgs84->description = _("Draw geographic grid (referenced to WGS84 ellipsoid)"); wgs84->guisection = _("Draw"); cross = G_define_flag(); cross->key = 'c'; cross->description = _("Draw '+' marks instead of grid lines"); cross->guisection = _("Draw"); dot = G_define_flag(); dot->key = 'd'; dot->description = _("Draw '.' marks instead of grid lines"); dot->guisection = _("Draw"); fiducial = G_define_flag(); fiducial->key = 'f'; fiducial->description = _("Draw fiducial marks instead of grid lines"); fiducial->guisection = _("Draw"); nogrid = G_define_flag(); nogrid->key = 'n'; nogrid->description = _("Disable grid drawing"); nogrid->guisection = _("Disable"); noborder = G_define_flag(); noborder->key = 'b'; noborder->description = _("Disable border drawing"); noborder->guisection = _("Disable"); notext = G_define_flag(); notext->key = 't'; notext->description = _("Disable text drawing"); notext->guisection = _("Disable"); /* Check command line */ if (G_parser(argc, argv)) exit(EXIT_FAILURE); /* do some checking */ if (nogrid->answer && noborder->answer) G_fatal_error(_("Both grid and border drawing are disabled")); if (wgs84->answer) geogrid->answer = 1; /* -w implies -g */ if (geogrid->answer && G_projection() == PROJECTION_LL) G_fatal_error(_("Geo-grid option not available for LL projection, use without -g/-w")); if (geogrid->answer && G_projection() == PROJECTION_XY) G_fatal_error(_("Geo-grid option not available for XY projection, use without -g/-w")); if (notext->answer) do_text = FALSE; else do_text = TRUE; if (lwidth->answer) { line_width = atoi(lwidth->answer); if (line_width < 0 || line_width > 1e3) G_fatal_error("Invalid line width"); } else line_width = 0; fontsize = atoi(fsize->answer); mark_type = MARK_GRID; if (cross->answer + fiducial->answer + dot->answer > 1) G_fatal_error(_("Choose a single mark style")); if (cross->answer) mark_type = MARK_CROSS; if (fiducial->answer) mark_type = MARK_FIDUCIAL; if (dot->answer) mark_type = MARK_DOT; if (G_strcasecmp(direction->answer, "both") == 0) dirn = DIRN_BOTH; else if (G_strcasecmp(direction->answer, "east-west") == 0) dirn = DIRN_LAT; else if (G_strcasecmp(direction->answer, "north-south") == 0) dirn = DIRN_LON; else G_fatal_error("Invalid direction: %s", direction->answer); if (align->answer || strcmp(opt2->answer, "0") == 0) G_get_element_window(&wind, "", "WIND", G_mapset()); if (strcmp(opt2->answer, "0") == 0) { if (geogrid->answer) gsize = wind.ns_res; else size = wind.ns_res; } else { /* get grid size */ if (geogrid->answer) { if (!G_scan_resolution(opt2->answer, &gsize, PROJECTION_LL) || gsize <= 0.0) G_fatal_error(_("Invalid geo-grid size <%s>"), opt2->answer); } else { if (!G_scan_resolution(opt2->answer, &size, G_projection()) || size <= 0.0) G_fatal_error(_("Invalid grid size <%s>"), opt2->answer); } } if (align->answer) { /* reduce accumulated errors when ew_res is not the same as ns_res. */ struct Cell_head w; G_get_set_window(&w); east = wind.west + (int)((w.west - wind.west) / wind.ew_res) * wind.ew_res; north = wind.south + (int)((w.south - wind.south) / wind.ns_res) * wind.ns_res; } else { /* get grid easting start */ if (!G_scan_easting(opt3->answers[0], &east, G_projection())) { G_usage(); G_fatal_error(_("Illegal east coordinate <%s>"), opt3->answers[0]); } /* get grid northing start */ if (!G_scan_northing(opt3->answers[1], &north, G_projection())) { G_usage(); G_fatal_error(_("Illegal north coordinate <%s>"), opt3->answers[1]); } } /* Setup driver and check important information */ D_open_driver(); /* Parse and select grid color */ colorg = D_parse_color(opt1->answer, FALSE); /* Parse and select border color */ colorb = D_parse_color(opt4->answer, FALSE); /* Parse and select text color */ colort = D_parse_color(tcolor->answer, FALSE); /* Parse and select background color */ colorbg = D_parse_color(bgcolor->answer, TRUE); D_setup(0); /* draw grid */ if (!nogrid->answer) { if (geogrid->answer) { /* initialzie proj stuff */ init_proj(&info_in, &info_out, wgs84->answer); plot_geogrid(gsize, info_in, info_out, do_text, colorg, colort, colorbg, fontsize, mark_type, line_width, dirn); } else { /* Do the grid plotting */ plot_grid(size, east, north, do_text, colorg, colort, colorbg, fontsize, mark_type, line_width, dirn); } } /* Draw border */ if (!noborder->answer) { /* Set border color */ D_use_color(colorb); /* Do the border plotting */ plot_border(size, east, north, dirn); } D_save_command(G_recreate_command()); D_close_driver(); exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { struct GModule *module; // struct Option *opt_input, *opt_sep; struct Option *opt_at, *opt_cols, *opt_font, *opt_fontsize, *opt_fontcolor, *opt_title, *opt_tit_font, *opt_tit_fontsize, *opt_sub_font, *opt_sub_fontsize, *opt_bcolor, *opt_bgcolor, *opt_symb_size, *opt_bg_width, *opt_output, *opt_input, *opt_sep; struct Flag *fl_bg; double LL, LT; char *title, *file_name; int bcolor, bgcolor, do_bg; int fontsize, fontcolor, tit_size, sub_size; char *font, *tit_font, *sub_font; int cols, symb_size, bg_width; char *out_file; FILE *source; char buf[BUFFSIZE]; char *sep; size_t nread; /* Initialize the GIS calls */ G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("display")); G_add_keyword(_("cartography")); G_add_keyword(_("vector")); G_add_keyword(_("legend")); module->description = _("Displays a vector legend " "in the active graphics frame."); opt_at = G_define_option(); opt_at->key = "at"; opt_at->key_desc = "left,top"; opt_at->type = TYPE_DOUBLE; opt_at->options = "0-100"; opt_at->answer = "10,40"; opt_at->required = NO; opt_at->description = _("Screen position of legend to be drawn (percentage, [0,0] is lower left)"); opt_cols = G_define_option(); opt_cols->key = "columns"; opt_cols->type = TYPE_INTEGER; opt_cols->answer = "1"; opt_cols->required = NO; opt_cols->description = _("Number of legend columns"); opt_cols->guisection = _("Layout"); opt_title = G_define_option(); opt_title->key = "title"; opt_title->type = TYPE_STRING; opt_title->required = NO; opt_title->description = _("Legend title"); opt_title->guisection = _("Title"); opt_symb_size = G_define_option(); opt_symb_size->key = "symbol_size"; opt_symb_size->type = TYPE_INTEGER; opt_symb_size->required = NO; opt_symb_size->description = _("Symbol size"); opt_symb_size->answer = "20"; opt_symb_size->guisection = _("Layout"); opt_bcolor = G_define_standard_option(G_OPT_CN); opt_bcolor->key = "border_color"; opt_bcolor->answer = "black"; opt_bcolor->label = _("Border color"); opt_bcolor->guisection = _("Background"); opt_bgcolor = G_define_standard_option(G_OPT_CN); opt_bgcolor->key = "bgcolor"; opt_bgcolor->answer = "white"; opt_bgcolor->label = _("Background color"); opt_bgcolor->guisection = _("Background"); opt_bg_width = G_define_option(); opt_bg_width->type = TYPE_INTEGER; opt_bg_width->key = "border_width"; opt_bg_width->answer = "2"; opt_bg_width->label = _("Background border width"); opt_bg_width->guisection = _("Background"); opt_font = G_define_option(); opt_font->key = "font"; opt_font->type = TYPE_STRING; opt_font->required = NO; opt_font->description = _("Font name"); opt_font->guisection = _("Font settings"); opt_fontsize = G_define_option(); opt_fontsize->key = "fontsize"; opt_fontsize->type = TYPE_DOUBLE; opt_fontsize->required = NO; opt_fontsize->options = "1-360"; opt_fontsize->label = _("Font size"); opt_fontsize->description = _("Default: 12"); opt_fontsize->guisection = _("Font settings"); opt_tit_font = G_define_option(); opt_tit_font->key = "title_font"; opt_tit_font->type = TYPE_STRING; opt_tit_font->required = NO; opt_tit_font->description = _("Title font name"); opt_tit_font->guisection = _("Font settings"); opt_tit_fontsize = G_define_option(); opt_tit_fontsize->key = "title_fontsize"; opt_tit_fontsize->type = TYPE_DOUBLE; opt_tit_fontsize->required = NO; opt_tit_fontsize->options = "1-360"; opt_tit_fontsize->label = _("Title font size"); opt_tit_fontsize->description = _("Default: 18"); opt_tit_fontsize->guisection = _("Title"); opt_sub_font = G_define_option(); opt_sub_font->key = "sub_font"; opt_sub_font->type = TYPE_STRING; opt_sub_font->required = NO; opt_sub_font->description = _("Subtitle font name"); opt_sub_font->guisection = _("Font settings"); opt_sub_fontsize = G_define_option(); opt_sub_fontsize->key = "sub_fontsize"; opt_sub_fontsize->type = TYPE_DOUBLE; opt_sub_fontsize->required = NO; opt_sub_fontsize->options = "1-360"; opt_sub_fontsize->label = _("Subtitle font size"); opt_sub_fontsize->description = _("Default: 14"); opt_sub_fontsize->guisection = _("Font settings"); opt_fontcolor = G_define_standard_option(G_OPT_C); opt_fontcolor->key = "fontcolor"; opt_fontcolor->answer = "black"; opt_fontcolor->label = _("Font color"); opt_fontcolor->guisection = _("Font settings"); fl_bg = G_define_flag(); fl_bg->key = 'b'; fl_bg->description = _("Display legend background"); fl_bg->guisection = _("Background"); opt_input = G_define_standard_option(G_OPT_F_INPUT); opt_input->label = _("Input legend file"); opt_input->description = _("Path to legend file "); opt_input->required = NO; opt_input->guisection = _("In/Out"); opt_output = G_define_standard_option(G_OPT_F_OUTPUT); opt_output->label = _("Output csv file"); opt_output->description = _("Path to output file or '-' " "for standard output"); opt_output->required = NO; opt_output->guisection = _("In/Out"); opt_sep = G_define_standard_option(G_OPT_F_SEP); opt_sep->guisection = _("In/Out"); /* Check command line */ if (G_parser(argc, argv)) { exit(EXIT_FAILURE); } D_open_driver(); D_setup_unity(0); /* parse and check options and flags */ if (opt_at->answer) { sscanf(opt_at->answers[0], "%lf", &LL); sscanf(opt_at->answers[1], "%lf", <); } else { LL = 10; LT = 40; } if (opt_title->answer) title = opt_title->answer; else title = ""; if (opt_cols->answer) sscanf(opt_cols->answer, "%d", &cols); else cols = 1; sscanf(opt_symb_size->answer, "%d", &symb_size); sscanf(opt_bg_width->answer, "%d", &bg_width); /* Background */ do_bg = fl_bg->answer; bcolor = D_parse_color(opt_bcolor->answer, TRUE); bgcolor = D_parse_color(opt_bgcolor->answer, TRUE); /* Font settings */ if (opt_font->answer) font = opt_font->answer; else font = "sans"; if (opt_fontsize->answer != NULL) sscanf(opt_fontsize->answer, "%d", &fontsize); else fontsize = 14; if (opt_tit_font->answer) tit_font = opt_tit_font->answer; else tit_font = font; if (opt_tit_fontsize->answer) sscanf(opt_tit_fontsize->answer, "%d", &tit_size); else tit_size = fontsize; if (opt_sub_font->answer) sub_font = opt_sub_font->answer; else sub_font = font; if (opt_sub_fontsize->answer) sscanf(opt_sub_fontsize->answer, "%d", &sub_size); else sub_size = fontsize; fontcolor = D_parse_color(opt_fontcolor->answer, FALSE); /*default color: black */ /* I/O */ sep = G_option_to_separator(opt_sep); if (opt_input->answer) { file_name = opt_input->answer; if (!file_name) G_fatal_error(_("Unable to open input file <%s>"), file_name); } else { file_name = getenv("GRASS_LEGEND_FILE"); if (!file_name) G_fatal_error("No legend file defined."); } if (opt_output->answer) { if (strcmp(opt_output->answer,"-") == 0) { source = fopen(file_name, "r"); if (!source) G_fatal_error(_("Unable to open input file <%s>"), file_name); while ((nread = fread(buf, 1, sizeof(buf), source))) fwrite(buf, 1, nread, stdout); fclose(source); } else { out_file = opt_output->answer; G_copy_file(file_name, out_file); } } /* Pre-calculate the layout */ if (do_bg) draw(file_name, LL, LT, title, cols, bgcolor, bcolor, bg_width, 1, tit_font, tit_size, sub_font, sub_size, font, fontsize, fontcolor, symb_size, sep); /* Draw legend */ draw(file_name, LL, LT, title, cols, bgcolor, bcolor, bg_width, 0, tit_font, tit_size, sub_font, sub_size, font, fontsize, fontcolor, symb_size, sep); D_close_driver(); exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { int colorg = 0; int colorb = 0; int colort = 0; double size = 0., gsize = 0.; /* initialize to zero */ double east, north; int do_text, fontsize, mark_type, line_width; struct GModule *module; struct Option *opt1, *opt2, *opt3, *opt4, *fsize, *tcolor, *lwidth; struct Flag *noborder, *notext, *geogrid, *nogrid, *wgs84, *cross, *fiducial, *dot; struct pj_info info_in; /* Proj structures */ struct pj_info info_out; /* Proj structures */ /* Initialize the GIS calls */ G_gisinit(argv[0]); module = G_define_module(); module->keywords = _("display, cartography"); module->description = _("Overlays a user-specified grid " "in the active display frame on the graphics monitor."); opt2 = G_define_option(); opt2->key = "size"; opt2->key_desc = "value"; opt2->type = TYPE_STRING; opt2->required = YES; opt2->label = _("Size of grid to be drawn"); opt2->description = _("In map units or DDD:MM:SS format. " "Example: \"1000\" or \"0:10\""); opt3 = G_define_option(); opt3->key = "origin"; opt3->type = TYPE_STRING; opt3->key_desc = "easting,northing"; opt3->answer = "0,0"; opt3->multiple = NO; opt3->description = _("Lines of the grid pass through this coordinate"); lwidth = G_define_option(); lwidth->key = "width"; lwidth->type = TYPE_DOUBLE; lwidth->required = NO; lwidth->description = _("Grid line width"); opt1 = G_define_standard_option(G_OPT_C_FG); opt1->answer = "gray"; opt1->label = _("Grid color"); opt1->guisection = _("Color"); opt4 = G_define_standard_option(G_OPT_C_FG); opt4->key = "bordercolor"; opt4->label = _("Border color"); opt4->guisection = _("Color"); tcolor = G_define_standard_option(G_OPT_C_FG); tcolor->key = "textcolor"; tcolor->answer = "gray"; tcolor->label = _("Text color"); tcolor->guisection = _("Color"); fsize = G_define_option(); fsize->key = "fontsize"; fsize->type = TYPE_INTEGER; fsize->required = NO; fsize->answer = "9"; fsize->options = "1-72"; fsize->description = _("Font size for gridline coordinate labels"); geogrid = G_define_flag(); geogrid->key = 'g'; geogrid->description = _("Draw geographic grid (referenced to current ellipsoid)"); wgs84 = G_define_flag(); wgs84->key = 'w'; wgs84->description = _("Draw geographic grid (referenced to WGS84 ellipsoid)"); cross = G_define_flag(); cross->key = 'c'; cross->description = _("Draw '+' marks instead of grid lines"); dot = G_define_flag(); dot->key = 'd'; dot->description = _("Draw '.' marks instead of grid lines"); fiducial = G_define_flag(); fiducial->key = 'f'; fiducial->description = _("Draw fiducial marks instead of grid lines"); nogrid = G_define_flag(); nogrid->key = 'n'; nogrid->description = _("Disable grid drawing"); nogrid->guisection = _("Disable"); noborder = G_define_flag(); noborder->key = 'b'; noborder->description = _("Disable border drawing"); noborder->guisection = _("Disable"); notext = G_define_flag(); notext->key = 't'; notext->description = _("Disable text drawing"); notext->guisection = _("Disable"); /* Check command line */ if (G_parser(argc, argv)) exit(EXIT_FAILURE); /* do some checking */ if (nogrid->answer && noborder->answer) G_fatal_error(_("Both grid and border drawing are disabled")); if (wgs84->answer) geogrid->answer = 1; /* -w implies -g */ if (geogrid->answer && G_projection() == PROJECTION_LL) G_fatal_error(_("Geo-Grid option is not available for LL projection")); if (geogrid->answer && G_projection() == PROJECTION_XY) G_fatal_error(_("Geo-Grid option is not available for XY projection")); if (notext->answer) do_text = FALSE; else do_text = TRUE; if (lwidth->answer) { line_width = atoi(lwidth->answer); if(line_width < 0 || line_width > 1e3) G_fatal_error("Invalid line width."); } else line_width = 0; fontsize = atoi(fsize->answer); mark_type = MARK_GRID; if (cross->answer + fiducial->answer + dot->answer > 1) G_fatal_error(_("Choose a single mark style")); if (cross->answer) mark_type = MARK_CROSS; if (fiducial->answer) mark_type = MARK_FIDUCIAL; if (dot->answer) mark_type = MARK_DOT; /* get grid size */ if (geogrid->answer) { if (!G_scan_resolution(opt2->answer, &gsize, PROJECTION_LL) || gsize <= 0.0) G_fatal_error(_("Invalid geo-grid size <%s>"), opt2->answer); } else { if (!G_scan_resolution(opt2->answer, &size, G_projection()) || size <= 0.0) G_fatal_error(_("Invalid grid size <%s>"), opt2->answer); } /* get grid easting start */ if (!G_scan_easting(opt3->answers[0], &east, G_projection())) { G_usage(); G_fatal_error(_("Illegal east coordinate <%s>"), opt3->answers[0]); } /* get grid northing start */ if (!G_scan_northing(opt3->answers[1], &north, G_projection())) { G_usage(); G_fatal_error(_("Illegal north coordinate <%s>"), opt3->answers[1]); } /* Setup driver and check important information */ if (R_open_driver() != 0) G_fatal_error(_("No graphics device selected")); /* Parse and select grid color */ colorg = D_parse_color(opt1->answer, FALSE); /* Parse and select border color */ colorb = D_parse_color(opt4->answer, FALSE); /* Parse and select text color */ colort = D_parse_color(tcolor->answer, FALSE); D_setup(0); /* draw grid */ if (!nogrid->answer) { if (geogrid->answer) { /* initialzie proj stuff */ init_proj(&info_in, &info_out, wgs84->answer); plot_geogrid(gsize, info_in, info_out, do_text, colorg, colort, fontsize, mark_type, line_width); } else { /* Do the grid plotting */ plot_grid(size, east, north, do_text, colorg, colort, fontsize, mark_type, line_width); } } /* Draw border */ if (!noborder->answer) { /* Set border color */ D_raster_use_color(colorb); /* Do the border plotting */ plot_border(size, east, north); } D_add_to_list(G_recreate_command()); R_close_driver(); exit(EXIT_SUCCESS); }