/*! \brief Set values in 'varray' to 'value' from category string. If category of object of given type is in <em>cstring</em> (string representing category list like: '1,3,5-7'). <em>type</em> may be either: GV_AREA or: GV_POINT | GV_LINE | GV_BOUNDARY | GV_CENTROID Array is not reset to zero before, but old values (if any > 0) are overwritten. Array must be initialised by Vect_new_varray() call. \param Map vector map \param field layer number \param cstring pointer to string with categories \param type feature type \param value value to set up \param[out] varray varray structure to modify \return number of items set \return -1 on error */ int Vect_set_varray_from_cat_string(const struct Map_info *Map, int field, const char *cstring, int type, int value, struct varray * varray) { int ret; struct cat_list *Clist; G_debug(4, "Vect_set_varray_from_cat_string(): cstring = '%s'", cstring); Clist = Vect_new_cat_list(); ret = Vect_str_to_cat_list(cstring, Clist); if (ret > 0) G_warning(_("%d errors in category string"), ret); G_debug(4, " %d ranges in clist", Clist->n_ranges); ret = Vect_set_varray_from_cat_list(Map, field, Clist, type, value, varray); Vect_destroy_cat_list(Clist); return ret; }
/** \brief Select features by id \param[in] Map vector map \param[in] type feature type \param[in] ids ids list \param[in,out] List list of selected features \return number of selected lines */ int sel_by_id(struct Map_info *Map, int type, char *ids, struct ilist *List) { int i; int num, id; struct cat_list *il; /* NOTE: this is not cat list, but list of id's */ struct ilist *List_tmp; if (first_selection) { List_tmp = List; first_selection = 0; } else { List_tmp = Vect_new_list(); } il = Vect_new_cat_list(); Vect_str_to_cat_list(ids, il); num = Vect_get_num_lines(Map); for (i = 0; i < il->n_ranges; i++) { for (id = 1; id <= num; id++) { if (!(Vect_read_line(Map, NULL, NULL, id) & type)) { continue; } if (id >= il->min[i] && id <= il->max[i]) { Vect_list_append(List_tmp, id); } } } G_debug(1, " %d lines selected (by id)", List_tmp->n_values); /* merge lists (only duplicate items) */ if (List_tmp != List) { merge_lists(List, List_tmp); Vect_destroy_list(List_tmp); } Vect_destroy_cat_list(il); return List->n_values; }
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 GParams params; struct Map_info Map; struct Map_info **BgMap; /* backgroud vector maps */ int nbgmaps; /* number of registrated background maps */ enum mode action_mode; FILE *ascii; int i; int move_first, snap; int ret, layer; double move_x, move_y, move_z, thresh[3]; struct line_pnts *coord; struct ilist *List; struct cat_list *Clist; ascii = NULL; List = NULL; BgMap = NULL; nbgmaps = 0; coord = NULL; Clist = NULL; G_gisinit(argv[0]); module = G_define_module(); module->overwrite = TRUE; G_add_keyword(_("vector")); G_add_keyword(_("editing")); G_add_keyword(_("geometry")); module->description = _("Edits a vector map, allows adding, deleting " "and modifying selected vector features."); if (!parser(argc, argv, ¶ms, &action_mode)) exit(EXIT_FAILURE); /* get list of categories */ Clist = Vect_new_cat_list(); if (params.cat->answer && Vect_str_to_cat_list(params.cat->answer, Clist)) { G_fatal_error(_("Unable to get category list <%s>"), params.cat->answer); } /* open input file */ if (params.in->answer) { if (strcmp(params.in->answer, "-") != 0) { ascii = fopen(params.in->answer, "r"); if (ascii == NULL) G_fatal_error(_("Unable to open file <%s>"), params.in->answer); } else { ascii = stdin; } } if (!ascii && action_mode == MODE_ADD) G_fatal_error(_("Required parameter <%s> not set"), params.in->key); if (action_mode == MODE_CREATE) { int overwrite; overwrite = G_check_overwrite(argc, argv); if (G_find_vector2(params.map->answer, G_mapset())) { if (!overwrite) G_fatal_error(_("Vector map <%s> already exists"), params.map->answer); } /* 3D vector maps? */ ret = Vect_open_new(&Map, params.map->answer, WITHOUT_Z); if (Vect_maptype(&Map) == GV_FORMAT_OGR_DIRECT) { int type; type = Vect_option_to_types(params.type); if (type != GV_POINT && type != GV_LINE && type != GV_BOUNDARY) G_fatal_error(_("Supported feature type for OGR layer: " "%s, %s or %s"), "point", "line", "boundary"); V2_open_new_ogr(&Map, type); } if (ret == -1) { G_fatal_error(_("Unable to create vector map <%s>"), params.map->answer); } G_debug(1, "Map created"); if (ascii) { /* also add new vector features */ action_mode = MODE_ADD; } } else { /* open selected vector file */ if (action_mode == MODE_ADD) /* write */ ret = Vect_open_update2(&Map, params.map->answer, G_mapset(), params.fld->answer); else /* read-only -- select features */ ret = Vect_open_old2(&Map, params.map->answer, G_mapset(), params.fld->answer); if (ret < 2) G_fatal_error(_("Unable to open vector map <%s> at topological level %d"), params.map->answer, 2); } G_debug(1, "Map opened"); /* open backgroud maps */ if (params.bmaps->answer) { i = 0; while (params.bmaps->answers[i]) { const char *bmap = params.bmaps->answers[i]; const char *mapset = G_find_vector2(bmap, ""); if (!mapset) G_fatal_error(_("Vector map <%s> not found"), bmap); if (strcmp( G_fully_qualified_name(params.map->answer, G_mapset()), G_fully_qualified_name(bmap, mapset)) == 0) { G_fatal_error(_("Unable to open vector map <%s> as the background map. " "It is given as vector map to be edited."), bmap); } nbgmaps++; BgMap = (struct Map_info **)G_realloc( BgMap, nbgmaps * sizeof(struct Map_info *)); BgMap[nbgmaps - 1] = (struct Map_info *)G_malloc(sizeof(struct Map_info)); if (Vect_open_old(BgMap[nbgmaps - 1], bmap, "") == -1) G_fatal_error(_("Unable to open vector map <%s>"), bmap); G_verbose_message(_("Background vector map <%s> registered"), bmap); i++; } } layer = Vect_get_field_number(&Map, params.fld->answer); i = 0; while (params.maxdist->answers[i]) { switch (i) { case THRESH_COORDS: thresh[THRESH_COORDS] = max_distance(atof(params.maxdist->answers[THRESH_COORDS])); thresh[THRESH_SNAP] = thresh[THRESH_QUERY] = thresh[THRESH_COORDS]; break; case THRESH_SNAP: thresh[THRESH_SNAP] = max_distance(atof(params.maxdist->answers[THRESH_SNAP])); break; case THRESH_QUERY: thresh[THRESH_QUERY] = atof(params.maxdist->answers[THRESH_QUERY]); break; default: break; } i++; } move_first = params.move_first->answer ? 1 : 0; snap = NO_SNAP; if (strcmp(params.snap->answer, "node") == 0) snap = SNAP; else if (strcmp(params.snap->answer, "vertex") == 0) snap = SNAPVERTEX; if (snap != NO_SNAP && thresh[THRESH_SNAP] <= 0) { G_warning(_("Threshold for snapping must be > 0. No snapping applied.")); snap = NO_SNAP; } if (action_mode != MODE_CREATE && action_mode != MODE_ADD) { /* select lines */ List = Vect_new_list(); G_message(_("Selecting features...")); if (action_mode == MODE_COPY && BgMap && BgMap[0]) { List = select_lines(BgMap[0], action_mode, ¶ms, thresh, List); } else { List = select_lines(&Map, action_mode, ¶ms, thresh, List); } } if ((action_mode != MODE_CREATE && action_mode != MODE_ADD && action_mode != MODE_SELECT)) { if (List->n_values < 1) { G_warning(_("No features selected, nothing to edit")); action_mode = MODE_NONE; ret = 0; } else { /* reopen the map for updating */ if (action_mode == MODE_ZBULK && !Vect_is_3d(&Map)) { Vect_close(&Map); G_fatal_error(_("Vector map <%s> is not 3D. Tool '%s' requires 3D vector map. " "Please convert the vector map " "to 3D using e.g. %s."), params.map->answer, params.tool->answer, "v.extrude"); } Vect_close(&Map); Vect_open_update2(&Map, params.map->answer, G_mapset(), params.fld->answer); } } /* coords option -> array */ if (params.coord->answers) { coord = Vect_new_line_struct(); int i = 0; double east, north; while (params.coord->answers[i]) { east = atof(params.coord->answers[i]); north = atof(params.coord->answers[i + 1]); Vect_append_point(coord, east, north, 0.0); i += 2; } } /* perform requested editation */ switch (action_mode) { case MODE_CREATE: break; case MODE_ADD: if (!params.header->answer) Vect_read_ascii_head(ascii, &Map); int num_lines; num_lines = Vect_get_num_lines(&Map); ret = Vect_read_ascii(ascii, &Map); G_message(_("%d features added"), ret); if (ret > 0) { int iline; struct ilist *List_added; List_added = Vect_new_list(); for (iline = num_lines + 1; iline <= Vect_get_num_lines(&Map); iline++) Vect_list_append(List_added, iline); G_verbose_message(_("Threshold value for snapping is %.2f"), thresh[THRESH_SNAP]); if (snap != NO_SNAP) { /* apply snapping */ /* snap to vertex ? */ Vedit_snap_lines(&Map, BgMap, nbgmaps, List_added, thresh[THRESH_SNAP], snap == SNAP ? FALSE : TRUE); } if (params.close->answer) { /* close boundaries */ int nclosed; nclosed = close_lines(&Map, GV_BOUNDARY, thresh[THRESH_SNAP]); G_message(_("%d boundaries closed"), nclosed); } Vect_destroy_list(List_added); } break; case MODE_DEL: ret = Vedit_delete_lines(&Map, List); G_message(_("%d features deleted"), ret); break; case MODE_MOVE: move_x = atof(params.move->answers[0]); move_y = atof(params.move->answers[1]); move_z = atof(params.move->answers[2]); G_verbose_message(_("Threshold value for snapping is %.2f"), thresh[THRESH_SNAP]); ret = Vedit_move_lines(&Map, BgMap, nbgmaps, List, move_x, move_y, move_z, snap, thresh[THRESH_SNAP]); G_message(_("%d features moved"), ret); break; case MODE_VERTEX_MOVE: move_x = atof(params.move->answers[0]); move_y = atof(params.move->answers[1]); move_z = atof(params.move->answers[2]); G_verbose_message(_("Threshold value for snapping is %.2f"), thresh[THRESH_SNAP]); ret = Vedit_move_vertex(&Map, BgMap, nbgmaps, List, coord, thresh[THRESH_COORDS], thresh[THRESH_SNAP], move_x, move_y, move_z, move_first, snap); G_message(_("%d vertices moved"), ret); break; case MODE_VERTEX_ADD: ret = Vedit_add_vertex(&Map, List, coord, thresh[THRESH_COORDS]); G_message(_("%d vertices added"), ret); break; case MODE_VERTEX_DELETE: ret = Vedit_remove_vertex(&Map, List, coord, thresh[THRESH_COORDS]); G_message(_("%d vertices removed"), ret); break; case MODE_BREAK: if (params.coord->answer) { ret = Vedit_split_lines(&Map, List, coord, thresh[THRESH_COORDS], NULL); } else { ret = Vect_break_lines_list(&Map, List, NULL, GV_LINES, NULL); } G_message(_("%d lines broken"), ret); break; case MODE_CONNECT: G_verbose_message(_("Threshold value for snapping is %.2f"), thresh[THRESH_SNAP]); ret = Vedit_connect_lines(&Map, List, thresh[THRESH_SNAP]); G_message(_("%d lines connected"), ret); break; case MODE_MERGE: ret = Vedit_merge_lines(&Map, List); G_message(_("%d lines merged"), ret); break; case MODE_SELECT: ret = print_selected(List); break; case MODE_CATADD: ret = Vedit_modify_cats(&Map, List, layer, 0, Clist); G_message(_("%d features modified"), ret); break; case MODE_CATDEL: ret = Vedit_modify_cats(&Map, List, layer, 1, Clist); G_message(_("%d features modified"), ret); break; case MODE_COPY: if (BgMap && BgMap[0]) { if (nbgmaps > 1) G_warning(_("Multiple background maps were given. " "Selected features will be copied only from " "vector map <%s>."), Vect_get_full_name(BgMap[0])); ret = Vedit_copy_lines(&Map, BgMap[0], List); } else { ret = Vedit_copy_lines(&Map, NULL, List); } G_message(_("%d features copied"), ret); break; case MODE_SNAP: G_verbose_message(_("Threshold value for snapping is %.2f"), thresh[THRESH_SNAP]); ret = snap_lines(&Map, List, thresh[THRESH_SNAP]); break; case MODE_FLIP: ret = Vedit_flip_lines(&Map, List); G_message(_("%d lines flipped"), ret); break; case MODE_NONE: break; case MODE_ZBULK:{ double start, step; double x1, y1, x2, y2; start = atof(params.zbulk->answers[0]); step = atof(params.zbulk->answers[1]); x1 = atof(params.bbox->answers[0]); y1 = atof(params.bbox->answers[1]); x2 = atof(params.bbox->answers[2]); y2 = atof(params.bbox->answers[3]); ret = Vedit_bulk_labeling(&Map, List, x1, y1, x2, y2, start, step); G_message(_("%d lines labeled"), ret); break; } case MODE_CHTYPE:{ ret = Vedit_chtype_lines(&Map, List); if (ret > 0) { G_message(_("%d features converted"), ret); } else { G_message(_("No feature modified")); } break; } default: G_warning(_("Operation not implemented")); ret = -1; break; } Vect_hist_command(&Map); /* build topology only if requested or if tool!=select */ if (!(action_mode == MODE_SELECT || params.topo->answer == 1 || !MODE_NONE)) { Vect_build_partial(&Map, GV_BUILD_NONE); Vect_build(&Map); } if (List) Vect_destroy_list(List); Vect_close(&Map); G_debug(1, "Map closed"); /* close background maps */ for (i = 0; i < nbgmaps; i++) { Vect_close(BgMap[i]); G_free((void *)BgMap[i]); } G_free((void *)BgMap); if (coord) Vect_destroy_line_struct(coord); if (Clist) Vect_destroy_cat_list(Clist); G_done_msg(" "); if (ret > -1) { exit(EXIT_SUCCESS); } else { exit(EXIT_FAILURE); } }
/** \brief Select features according to SQL where statement \param[in] Map vector map \param[in] layer layer number \param[in] type feature type \param[in] where 'where' statement \param[in,out] List list of selected features \return number of selected lines */ int sel_by_where(struct Map_info *Map, int layer, int type, char *where, struct ilist *List) { struct cat_list *cat_list; struct ilist *List_tmp; struct field_info *Fi; dbDriver *driver; dbHandle handle; int *cats, ncats; if (first_selection) { List_tmp = List; first_selection = 0; } else { List_tmp = Vect_new_list(); } cat_list = Vect_new_cat_list(); if (layer < 1) { G_fatal_error(_("Layer must be > 0 for 'where'")); } Fi = Vect_get_field(Map, layer); if (!Fi) { G_fatal_error(_("Database connection not defined for layer %d"), layer); } driver = db_start_driver(Fi->driver); if (!driver) G_fatal_error(_("Unable to start driver <%s>"), Fi->driver); db_init_handle(&handle); db_set_handle(&handle, Fi->database, NULL); if (db_open_database(driver, &handle) != DB_OK) G_fatal_error(_("Unable to open database <%s> by driver <%s>"), Fi->database, Fi->driver); ncats = db_select_int(driver, Fi->table, Fi->key, where, &cats); db_close_database(driver); db_shutdown_driver(driver); Vect_array_to_cat_list(cats, ncats, cat_list); /* free array of cats */ if (ncats >= 0) G_free(cats); sel_by_cat(Map, cat_list, layer, type, NULL, List_tmp); G_debug(1, " %d lines selected (by where)", List_tmp->n_values); /* merge lists (only duplicate items) */ if (List_tmp != List) { merge_lists(List, List_tmp); Vect_destroy_list(List_tmp); } Vect_destroy_cat_list(cat_list); return List->n_values; }
int main(int argc, char *argv[]) { struct GModule *module; struct Map_info Map; FILE *ascii, *att; char *input, *output, *delim, **columns, *where, *field_name, *cats; int format, dp, field, ret, region, old_format, header, type; int ver, pnt; struct cat_list *clist; clist = NULL; G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("vector")); G_add_keyword(_("export")); G_add_keyword("ASCII"); module->label = _("Exports a vector map to a GRASS ASCII vector representation."); module->description = _("By default only features with category are exported. " "To export all features use 'layer=-1'."); parse_args(argc, argv, &input, &output, &format, &dp, &delim, &field_name, &columns, &where, ®ion, &old_format, &header, &cats, &type); if (format == GV_ASCII_FORMAT_STD && columns) { G_warning(_("Parameter '%s' ignored in standard mode"), "column"); } ver = 5; pnt = 0; if (old_format) ver = 4; if (ver == 4 && format == GV_ASCII_FORMAT_POINT) { G_fatal_error(_("Format '%s' is not supported for old version"), "point"); } if (ver == 4 && strcmp(output, "-") == 0) { G_fatal_error(_("Parameter '%s' must be given for old version"), "output"); } /* open with topology only if needed */ if (format == GV_ASCII_FORMAT_WKT || (format == GV_ASCII_FORMAT_STD && (where || clist))) { if (Vect_open_old2(&Map, input, "", field_name) < 2) /* topology required for areas */ G_warning(_("Unable to open vector map <%s> at topology level. " "Areas will not be processed."), input); } else { Vect_set_open_level(1); /* topology not needed */ if (Vect_open_old2(&Map, input, "", field_name) < 0) G_fatal_error(_("Unable to open vector map <%s>"), input); if (Vect_maptype(&Map) != GV_FORMAT_NATIVE) { /* require topological level for external formats centroids are read from topo */ Vect_close(&Map); Vect_set_open_level(2); if (Vect_open_old2(&Map, input, "", field_name) < 0) G_fatal_error(_("Unable to open vector map <%s>"), input); } } field = Vect_get_field_number(&Map, field_name); if (cats) { clist = Vect_new_cat_list(); clist->field = field; if (clist->field < 1) G_fatal_error(_("Layer <%s> not found"), field_name); ret = Vect_str_to_cat_list(cats, clist); if (ret > 0) G_fatal_error(_n("%d error in <%s> option", "%d errors in <%s> option", ret), ret, "cats"); } if (strcmp(output, "-") != 0) { if (ver == 4) { ascii = G_fopen_new("dig_ascii", output); } else if (strcmp(output, "-") == 0) { ascii = stdout; } else { ascii = fopen(output, "w"); } if (ascii == NULL) { G_fatal_error(_("Unable to open file <%s>"), output); } } else { ascii = stdout; } if (format == GV_ASCII_FORMAT_STD) { Vect_write_ascii_head(ascii, &Map); fprintf(ascii, "VERTI:\n"); } /* Open dig_att */ att = NULL; if (ver == 4 && !pnt) { if (G_find_file("dig_att", output, G_mapset()) != NULL) G_fatal_error(_("dig_att file already exist")); if ((att = G_fopen_new("dig_att", output)) == NULL) G_fatal_error(_("Unable to open dig_att file <%s>"), output); } if (where || columns || clist) G_message(_("Fetching data...")); ret = Vect_write_ascii(ascii, att, &Map, ver, format, dp, delim, region, type, field, clist, (const char *)where, (const char **)columns, header); if (ret < 1) { if (format == GV_ASCII_FORMAT_POINT) { G_warning(_("No points found, nothing to be exported")); } else { G_warning(_("No features found, nothing to be exported")); } } if (ascii != NULL) fclose(ascii); if (att != NULL) fclose(att); Vect_close(&Map); if (cats) Vect_destroy_cat_list(clist); exit(EXIT_SUCCESS); }
/*! \brief Set category constraints using 'where' or 'cats' option and layer number. \param Map pointer to Map_info structure \param layer layer number \param where where statement \param catstr category list as string \return pointer to cat_list structure or NULL */ struct cat_list *Vect_cats_set_constraint(struct Map_info *Map, int layer, char *where, char *catstr) { struct cat_list *list = NULL; int ret; if (layer < 1) { G_warning(_("Layer number must be > 0 for category constraints")); /* no valid constraints, all categories qualify */ return list; } /* where has precedence over cats */ if (where) { struct field_info *Fi = NULL; dbDriver *driver = NULL; int ncats, *cats = NULL; int i, j; if (catstr) G_warning(_("'%s' and '%s' parameters were supplied, cats will be ignored"), "where", "cats"); Fi = Vect_get_field(Map, layer); if (!Fi) { G_fatal_error(_("Database connection not defined for layer %d"), layer); } G_verbose_message(_("Loading categories from table <%s>..."), Fi->table); 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); ncats = db_select_int(driver, Fi->table, Fi->key, where, &cats); if (ncats == -1) G_fatal_error(_("Unable select records from table <%s>"), Fi->table); G_verbose_message(n_("One category loaded", "%d categories loaded", ncats), ncats); db_close_database_shutdown_driver(driver); /* sort */ qsort(cats, ncats, sizeof(int), cmp); /* remove duplicates */ j = 1; for (i = 1; i < ncats; i++) { if (cats[i] != cats[j - 1]) { cats[j] = cats[i]; j++; } } ncats = j; /* convert to cat list */ list = Vect_new_cat_list(); ret = Vect_array_to_cat_list(cats, ncats, list); if (ret == 0) G_warning(_("No categories selected with '%s' option"), "where"); if (cats) G_free(cats); } else if (catstr) { list = Vect_new_cat_list(); ret = Vect_str_to_cat_list(catstr, list); if (ret > 0) G_warning(_("%d errors in '%s' option"), ret, "cats"); } if (list) { if (list->n_ranges < 1) { Vect_destroy_cat_list(list); list = NULL; } else list->field = layer; } return list; }
int main(int argc, char **argv) { char *mapset; int ret, level; int i, stat = 0, type, display; int chcat = 0; int r, g, b; int has_color, has_fcolor; struct color_rgb color, fcolor; double size; int default_width; double width_scale; int verbose = FALSE; double minreg, maxreg, reg; char map_name[128]; 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, *xref_opt, *yref_opt; struct Option *attrcol_opt, *maxreg_opt, *minreg_opt; struct Option *width_opt, *wcolumn_opt, *wscale_opt; struct Option *render_opt; struct Flag *verbose_flag; /* please remove before GRASS 7 released */ struct Flag *id_flag, *table_acolors_flag, *cats_acolors_flag, *x_flag, *zcol_flag; struct cat_list *Clist; int *cats, ncat; LATTR lattr; struct Map_info Map; struct field_info *fi; dbDriver *driver; dbHandle handle; struct Cell_head window; BOUND_BOX box; double overlap; /* Initialize the GIS calls */ G_gisinit(argv[0]); module = G_define_module(); module->keywords = _("display, vector"); module->description = _("Displays user-specified vector map " "in the active graphics frame."); map_opt = G_define_standard_option(G_OPT_V_MAP); 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,dir,attr,zcoor"; display_opt->description = _("Display"); display_opt->descriptions = _("shape;Display geometry of features;" "cat;Display category numbers of features;" "topo;Display topology information (nodes, edges);" "dir;Display direction of linear features;" "attr;Display selected attribute based on 'attrcol';" "zcoor;Display z-coordinate of features (only for 3D vector maps)"); /* Query */ type_opt = G_define_standard_option(G_OPT_V_TYPE); type_opt->answer = "point,line,boundary,centroid,area,face"; type_opt->options = "point,line,boundary,centroid,area,face"; type_opt->guisection = _("Selection"); field_opt = G_define_standard_option(G_OPT_V_FIELD); field_opt->label = _("Layer number (if -1, all layers are displayed)"); field_opt->gisprompt = "old_layer,layer,layer_all"; field_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_WHERE); where_opt->guisection = _("Selection"); /* Colors */ color_opt = G_define_option(); color_opt->key = "color"; color_opt->type = TYPE_STRING; color_opt->answer = DEFAULT_FG_COLOR; color_opt->label = _("Feature color"); color_opt->guisection = _("Colors"); color_opt->gisprompt = "old_color,color,color_none"; color_opt->description = _("Either a standard GRASS color, R:G:B triplet, or \"none\""); fcolor_opt = G_define_option(); fcolor_opt->key = "fcolor"; fcolor_opt->type = TYPE_STRING; fcolor_opt->answer = "200:200:200"; fcolor_opt->label = _("Area fill color"); fcolor_opt->guisection = _("Colors"); fcolor_opt->gisprompt = "old_color,color,color_none"; fcolor_opt->description = _("Either a standard GRASS color, R:G:B triplet, or \"none\""); rgbcol_opt = G_define_standard_option(G_OPT_COLUMN); rgbcol_opt->key = "rgb_column"; rgbcol_opt->guisection = _("Colors"); rgbcol_opt->description = _("Name of color definition column (for use with -a flag)"); rgbcol_opt->answer = "GRASSRGB"; zcol_opt = G_define_option(); zcol_opt->key = "zcolor"; zcol_opt->key_desc = "style"; zcol_opt->type = TYPE_STRING; zcol_opt->required = NO; zcol_opt->description = _("Type of color table (for use with -z flag)"); zcol_opt->answer = "terrain"; 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_COLUMN); wcolumn_opt->key = "wcolumn"; wcolumn_opt->guisection = _("Lines"); wcolumn_opt->description = _("Name of column for line widths (these values will be scaled by wscale)"); wscale_opt = G_define_option(); wscale_opt->key = "wscale"; wscale_opt->type = TYPE_DOUBLE; wscale_opt->answer = "1"; wscale_opt->guisection = _("Lines"); wscale_opt->description = _("Scale factor for wcolumn"); /* 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_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_COLUMN); rotcolumn_opt->key = "rot_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"); /* Labels */ lfield_opt = G_define_standard_option(G_OPT_V_FIELD); lfield_opt->key = "llayer"; lfield_opt->guisection = _("Labels"); lfield_opt->description = _("Layer number for labels (default: the given layer number)"); attrcol_opt = G_define_standard_option(G_OPT_COLUMN); attrcol_opt->key = "attrcol"; attrcol_opt->multiple = NO; /* or fix attr.c, around line 102 */ attrcol_opt->guisection = _("Labels"); attrcol_opt->description = _("Name of column to be displayed"); lcolor_opt = G_define_option(); lcolor_opt->key = "lcolor"; lcolor_opt->type = TYPE_STRING; lcolor_opt->answer = "red"; lcolor_opt->label = _("Label color"); lcolor_opt->guisection = _("Labels"); lcolor_opt->gisprompt = "old_color,color,color"; lcolor_opt->description = _("Either a standard color name or R:G:B triplet"); bgcolor_opt = G_define_option(); bgcolor_opt->key = "bgcolor"; bgcolor_opt->type = TYPE_STRING; bgcolor_opt->answer = "none"; bgcolor_opt->guisection = _("Labels"); bgcolor_opt->label = _("Label background color"); bgcolor_opt->gisprompt = "old_color,color,color_none"; bgcolor_opt->description = _("Either a standard GRASS color, R:G:B triplet, or \"none\""); bcolor_opt = G_define_option(); bcolor_opt->key = "bcolor"; bcolor_opt->type = TYPE_STRING; bcolor_opt->answer = "none"; bcolor_opt->guisection = _("Labels"); bcolor_opt->label = _("Label border color"); bcolor_opt->gisprompt = "old_color,color,color_none"; bcolor_opt->description = _("Either a standard GRASS color, R:G:B triplet, or \"none\""); lsize_opt = G_define_option(); lsize_opt->key = "lsize"; 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"); 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"); render_opt = G_define_option(); render_opt->key = "render"; render_opt->type = TYPE_STRING; render_opt->required = NO; render_opt->multiple = NO; render_opt->answer = "c"; render_opt->options = "g,r,d,c,l"; render_opt->description = _("Rendering method for filled polygons"); render_opt->descriptions = _("g;use the libgis render functions (features: clipping);" "r;use the raster graphics library functions (features: polylines);" "d;use the display library basic functions (features: polylines);" "c;use the display library clipping functions (features: clipping);" "l;use the display library culling functions (features: culling, polylines)"); /* please remove before GRASS 7 released */ verbose_flag = G_define_flag(); verbose_flag->key = 'v'; verbose_flag->description = _("Run verbosely"); /* Colors */ table_acolors_flag = G_define_flag(); table_acolors_flag->key = 'a'; table_acolors_flag->guisection = _("Colors"); table_acolors_flag->description = _("Get colors from map table column (of form RRR:GGG:BBB)"); 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"); x_flag = G_define_flag(); x_flag->key = 'x'; x_flag->description = _("Don't add to list of vectors and commands in monitor " "(it won't be drawn if the monitor is refreshed)"); zcol_flag = G_define_flag(); zcol_flag->key = 'z'; zcol_flag->description = _("Colorize polygons according to z height"); zcol_flag->guisection = _("Colors"); /* Check command line */ if (G_parser(argc, argv)) exit(EXIT_FAILURE); if (G_strcasecmp(render_opt->answer, "g") == 0) render = RENDER_GPP; else if (G_strcasecmp(render_opt->answer, "r") == 0) render = RENDER_RPA; else if (G_strcasecmp(render_opt->answer, "d") == 0) render = RENDER_DP; else if (G_strcasecmp(render_opt->answer, "c") == 0) render = RENDER_DPC; else if (G_strcasecmp(render_opt->answer, "l") == 0) render = RENDER_DPL; else render = RENDER_GPP; /* please remove -v flag before GRASS 7 released */ if (verbose_flag->answer) { G_putenv("GRASS_VERBOSE", "3"); G_warning(_("The '-v' flag is superseded and will be removed " "in future. Please use '--verbose' instead.")); } /* but keep this */ if (G_verbose() > G_verbose_std()) verbose = TRUE; G_get_set_window(&window); if (R_open_driver() != 0) G_fatal_error(_("No graphics device selected")); /* Read map options */ /* 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_message(_("Region size is lower than minreg, nothing displayed.")); D_add_to_list(G_recreate_command()); exit(EXIT_SUCCESS); } } if (maxreg_opt->answer) { maxreg = atof(maxreg_opt->answer); if (reg > maxreg) { G_message(_("Region size is greater than maxreg, nothing displayed.")); D_add_to_list(G_recreate_command()); exit(EXIT_SUCCESS); } } G_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 (table_acolors_flag->answer && cats_acolors_flag->answer) { cats_acolors_flag->answer = '\0'; G_warning(_("The '-c' and '-a' flags cannot be used together, " "the '-c' flag will be ignored!")); } color = G_standard_color_rgb(WHITE); ret = G_str_to_color(color_opt->answer, &r, &g, &b); if (ret == 1) { has_color = 1; color.r = r; color.g = g; color.b = b; } else if (ret == 2) { /* none */ has_color = 0; } else if (ret == 0) { /* error */ G_fatal_error(_("Unknown color: [%s]"), color_opt->answer); } fcolor = G_standard_color_rgb(WHITE); ret = G_str_to_color(fcolor_opt->answer, &r, &g, &b); if (ret == 1) { has_fcolor = 1; fcolor.r = r; fcolor.g = g; fcolor.b = b; } else if (ret == 2) { /* none */ has_fcolor = 0; } else if (ret == 0) { /* error */ G_fatal_error(_("Unknown color: '%s'"), fcolor_opt->answer); } size = atof(size_opt->answer); /* Make sure map is available */ mapset = G_find_vector2(map_name, ""); if (mapset == NULL) G_fatal_error(_("Vector map <%s> not found"), map_name); /* 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_old(&Map, map_name, mapset); if (where_opt->answer) { if (Clist->field < 1) G_fatal_error(_("'layer' must be > 0 for 'where'.")); chcat = 1; if ((fi = Vect_get_field(&Map, Clist->field)) == NULL) G_fatal_error(_("Database connection not defined")); if (fi != NULL) { driver = db_start_driver(fi->driver); if (driver == NULL) G_fatal_error(_("Unable to start driver <%s>"), fi->driver); db_init_handle(&handle); db_set_handle(&handle, fi->database, NULL); if (db_open_database(driver, &handle) != DB_OK) G_fatal_error(_("Unable to open database <%s>"), fi->database); ncat = db_select_int(driver, fi->table, fi->key, where_opt->answer, &cats); db_close_database(driver); db_shutdown_driver(driver); Vect_array_to_cat_list(cats, ncat, Clist); } } else if (cat_opt->answer) { if (Clist->field < 1) G_fatal_error(_("'layer' must be > 0 for 'cats'.")); chcat = 1; ret = Vect_str_to_cat_list(cat_opt->answer, Clist); if (ret > 0) G_warning(_("%d errors in cat option"), ret); } type = Vect_option_to_types(type_opt); i = 0; display = 0; while (display_opt->answers[i]) { switch (display_opt->answers[i][0]) { case 's': display |= DISP_SHAPE; break; case 'c': display |= DISP_CAT; break; case 't': display |= DISP_TOPO; break; case 'd': display |= DISP_DIR; break; case 'a': display |= DISP_ATTR; break; case 'z': display |= DISP_ZCOOR; break; } i++; } /* Read label options */ if (lfield_opt->answer != NULL) lattr.field = atoi(lfield_opt->answer); else lattr.field = Clist->field; lattr.color.R = lattr.color.G = lattr.color.B = 255; if (G_str_to_color(lcolor_opt->answer, &r, &g, &b)) { lattr.color.R = r; lattr.color.G = g; lattr.color.B = b; } lattr.has_bgcolor = 0; if (G_str_to_color(bgcolor_opt->answer, &r, &g, &b) == 1) { lattr.has_bgcolor = 1; lattr.bgcolor.R = r; lattr.bgcolor.G = g; lattr.bgcolor.B = b; } lattr.has_bcolor = 0; if (G_str_to_color(bcolor_opt->answer, &r, &g, &b) == 1) { lattr.has_bcolor = 1; lattr.bcolor.R = r; lattr.bcolor.G = g; lattr.bcolor.B = b; } lattr.size = atoi(lsize_opt->answer); lattr.font = font_opt->answer; switch (xref_opt->answer[0]) { case 'l': lattr.xref = LLEFT; break; case 'c': lattr.xref = LCENTER; break; case 'r': lattr.xref = LRIGHT; break; } switch (yref_opt->answer[0]) { case 't': lattr.yref = LTOP; break; case 'c': lattr.yref = LCENTER; break; case 'b': lattr.yref = LBOTTOM; break; } D_setup(0); G_setup_plot(D_get_d_north(), D_get_d_south(), D_get_d_west(), D_get_d_east(), D_move_abs, D_cont_abs); if (verbose) G_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_message(_("The bounding box of the map is outside the current region, " "nothing drawn.")); stat = 0; } 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 (type & GV_AREA) { if (level >= 2) { if (display & DISP_SHAPE) { stat = darea(&Map, Clist, has_color ? &color : NULL, has_fcolor ? &fcolor : NULL, chcat, (int)id_flag->answer, table_acolors_flag->answer, cats_acolors_flag->answer, &window, rgbcol_opt->answer, default_width, wcolumn_opt->answer, width_scale, zcol_flag->answer, zcol_opt->answer); } if (wcolumn_opt->answer) D_line_width(default_width); } else G_warning(_("Unable to display areas, topology not available")); } if (display & DISP_SHAPE) { if (id_flag->answer && level < 2) { G_warning(_("Unable to display lines by id, topology not available")); } else { stat = plot1(&Map, type, Clist, has_color ? &color : NULL, has_fcolor ? &fcolor : NULL, chcat, icon_opt->answer, size, sizecolumn_opt->answer, rotcolumn_opt->answer, (int)id_flag->answer, table_acolors_flag->answer, cats_acolors_flag->answer, rgbcol_opt->answer, default_width, wcolumn_opt->answer, width_scale, zcol_flag->answer, zcol_opt->answer); if (wcolumn_opt->answer) D_line_width(default_width); } } if (has_color) { R_RGB_color(color.r, color.g, color.b); if (display & DISP_DIR) stat = dir(&Map, type, Clist, chcat, size); } /* 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) R_line_width(0); if (display & DISP_CAT) stat = label(&Map, type, Clist, &lattr, chcat); if (display & DISP_ATTR) stat = attr(&Map, type, attrcol_opt->answer, Clist, &lattr, chcat); if (display & DISP_ZCOOR) stat = zcoor(&Map, type, &lattr); if (display & DISP_TOPO) { if (level >= 2) stat = topo(&Map, type, &lattr); else G_warning(_("Unable to display topology, not available")); } } if (!x_flag->answer) { D_add_to_list(G_recreate_command()); D_set_dig_name(G_fully_qualified_name(map_name, mapset)); D_add_to_dig_list(G_fully_qualified_name(map_name, mapset)); } R_close_driver(); if (verbose) G_done_msg(" "); Vect_close(&Map); Vect_destroy_cat_list(Clist); exit(stat); }