Chinaunix首页 | 论坛 | 博客
  • 博客访问: 126795
  • 博文数量: 31
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 275
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-08 15:00
文章分类

全部博文(31)

文章存档

2009年(15)

2008年(16)

我的朋友

分类:

2008-11-05 14:47:43

/****************************************************************
 *
 * MODULE:     v.example
 *
 * AUTHOR(S):  GRASS Development Team
 *
 * PURPOSE:    example vector module does something like:
 *               v.llabel -i map=m1 value=1
 *             but the new map is written instead of update of
 *             the old one
 *
 * COPYRIGHT:  (C) 2002-2005 by the GRASS Development Team
 *
 *             This program is free software under the
 *             GNU General Public License (>=v2).
 *             Read the file COPYING that comes with GRASS
 *             for details.
 *
 * TODO:       - add DB support
 ****************************************************************/
#include
#include
#include "gis.h"
#include "Vect.h"
#include "glocale.h"
#include "gisdefs.h"

int main(int argc, char *argv[])
{
    struct Map_info In, Out;
    static struct line_pnts *Points;
    struct line_cats *Cats;
    int i, type, cat;
    char *mapset;
   
 struct GModule                      /* Structure that stores module info  */
 {
  char *label;                    /* Optional short description for GUI */
  char *description;              /* String describing module */
   // /* further items are possible: author(s), version */
  int overwrite; /* overwrite old files */
  char * keywords;
 };
    struct GModule *module;     /* GRASS module for parsing arguments */
    struct Option *old;
    struct Option *new;
 argv[0]="C:";
    /* initialize GIS environment */
    G_gisinit("/usr/include/");  /* reads grass env, stores program name to G_program_name() */
    /* initialize module */
    module = G_define_module();
    //module->keywords = _("vector, keyword2, keyword3");
    module->keywords = "vector, keyword2, keyword3";
    module->description = "My first vector module";
    /* Define the different options as defined in gis.h */
    old = G_define_standard_option(G_OPT_V_INPUT);
    new = G_define_standard_option(G_OPT_V_OUTPUT);
    /* options and flags parser */
    if (G_parser(argc, argv))
 exit(EXIT_FAILURE);
    Points = Vect_new_line_struct();
    Cats = Vect_new_cats_struct();
    Vect_check_input_output_name(new->answer, old->answer, GV_FATAL_EXIT);
    if ((mapset = G_find_vector2(old->answer, "")) == NULL)
 G_fatal_error("Vector map <%s> not found", old->answer);
    Vect_set_open_level(2);
    if (1 > Vect_open_old(&In, old->answer, mapset))
 G_fatal_error("Unable to open vector map <%s>", old->answer);
    if (0 > Vect_open_new(&Out, new->answer, WITHOUT_Z)) {
 Vect_close(&In);
 G_fatal_error("Unable to create vector map <%s>", new->answer);
    }
    Vect_copy_head_data(&In, &Out);
    Vect_hist_copy(&In, &Out);
    Vect_hist_command(&Out);
    i = 1;
    while ((type = Vect_read_next_line(&In, Points, Cats)) > 0) {
 if (type == GV_LINE) {
     if (Vect_cat_get(Cats, 1, &cat) == 0) {
  Vect_cat_set(Cats, 1, i);
  i++;
     }
 }
 Vect_write_line(&Out, type, Points, Cats);
    }
    Vect_build(&Out, stdout);
    Vect_close(&In);
    Vect_close(&Out);
    exit(EXIT_SUCCESS);
}
阅读(1288) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~