Пример #1
0
/*! 
   \brief Writes head information to text file (GV_HEAD_ELEMENT)

   \param Map pointer to Map_info structure

   \return 0 on success
   \return -1 on error
 */
int Vect__write_head(const struct Map_info *Map)
{
    char *path;
    FILE *head_fp;

    path = Vect__get_path(Map);
    head_fp = G_fopen_new(path, GV_HEAD_ELEMENT);
    G_free(path);
    if (head_fp == NULL) {
	G_warning(_("Unable to create header file for vector map <%s>"),
		  Vect_get_full_name(Map));
	return -1;
    }

    fprintf(head_fp, "ORGANIZATION: %s\n", Vect_get_organization(Map));
    fprintf(head_fp, "DIGIT DATE:   %s\n", Vect_get_date(Map));
    fprintf(head_fp, "DIGIT NAME:   %s\n", Vect_get_person(Map));
    fprintf(head_fp, "MAP NAME:     %s\n", Vect_get_map_name(Map));
    fprintf(head_fp, "MAP DATE:     %s\n", Vect_get_map_date(Map));
    fprintf(head_fp, "MAP SCALE:    %d\n", Vect_get_scale(Map));
    fprintf(head_fp, "OTHER INFO:   %s\n", Vect_get_comment(Map));
    if (Vect_get_proj(Map) > 0)
	fprintf(head_fp, "PROJ:         %d\n", Vect_get_proj(Map));
    fprintf(head_fp, "ZONE:         %d\n", Vect_get_zone(Map));
    fprintf(head_fp, "MAP THRESH:   %f\n", Vect_get_thresh(Map));

    fclose(head_fp);

    return 0;
}
Пример #2
0
/*!
 * \brief Write map layer color table
 *
 * The color table is written for the raster map <i>name</i> in the
 * specified <i>mapset</i> from the <i>colors</i> structure.
 *
 * If there is an error, -1 is returned. No diagnostic is
 * printed. Otherwise, 1 is returned.
 *
 * The <i>colors</i> structure must be created properly, i.e.,
 * Rast_init_colors() to initialize the structure and Rast_add_c_color_rule()
 * to set the category colors. These routines are called by
 * higher level routines which read or create entire color tables,
 * such as Rast_read_colors() or Rast_make_ramp_colors().
 *
 * <b>Note:</b> The calling sequence for this function deserves
 * special attention. The <i>mapset</i> parameter seems to imply that
 * it is possible to overwrite the color table for a raster map which
 * is in another mapset. However, this is not what actually
 * happens. It is very useful for users to create their own color
 * tables for raster maps in other mapsets, but without overwriting
 * other users' color tables for the same raster map. If <i>mapset</i>
 * is the current mapset, then the color file for <i>name</i> will be
 * overwritten by the new color table. But if <i>mapset</i> is not the
 * current mapset, then the color table is actually written in the
 * current mapset under the <tt>colr2</tt> element as:
 * <tt>colr2/mapset/name</tt>.
 *
 * The rules are written out using floating-point format, removing
 * trailing zeros (possibly producing integers).  The flag marking the
 * colors as floating-point is <b>not</b> written.
 *
 * If the environment variable FORCE_GRASS3_COLORS is set (to anything at all)
 * then the output format is 3.0, even if the structure contains 4.0 rules.
 * This allows users to create 3.0 color files for export to sites which
 * don't yet have 4.0
 *
 * \param name map name
 * \param mapset mapset name
 * \param colors pointer to structure Colors which holds color info
 *
 * \return void
 */
void Rast_write_colors(const char *name, const char *mapset,
		      struct Colors *colors)
{
    char element[512];
    char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
    FILE *fd;

    if (G_name_is_fully_qualified(name, xname, xmapset)) {
	if (strcmp(xmapset, mapset) != 0)
	    G_fatal_error(_("Qualified name <%s> doesn't match mapset <%s>"),
			  name, mapset);
	name = xname;
    }
    /*
     * if mapset is current mapset, remove colr2 file (created by pre 3.0 grass)
     *    and then write original color table
     * else write secondary color table
     */
    sprintf(element, "colr2/%s", mapset);
    if (strcmp(mapset, G_mapset()) == 0) {
	G_remove(element, name);	/* get rid of existing colr2, if any */
	strcpy(element, "colr");
    }
    if (!(fd = G_fopen_new(element, name)))
	G_fatal_error(_("Unable to create <%s> file for map <%s>"),
		      element, name);

    Rast__write_colors(fd, colors);
    fclose(fd);
}
Пример #3
0
/*!
   \brief Save topology file for vector map

   \param Map pointer to Map_info structure

   \return 1 on success
   \return 0 on error
 */
int Vect_save_topo(struct Map_info *Map)
{
    struct Plus_head *plus;
    char path[GPATH_MAX];
    struct gvfile fp;

    G_debug(1, "Vect_save_topo()");

    /*  write out all the accumulated info to the plus file  */
    plus = &(Map->plus);
    dig_file_init(&fp);

    Vect__get_path(path, Map);
    fp.file = G_fopen_new(path, GV_TOPO_ELEMENT);
    if (fp.file == NULL) {
	G_warning(_("Unable to create topo file for vector map <%s>"), Map->name);
	return 0;
    }

    /* set portable info */
    dig_init_portable(&(plus->port), dig__byte_order_out());

    if (0 > dig_write_plus_file(&fp, plus)) {
	G_warning(_("Error writing out topo file"));
	return 0;
    }

    fclose(fp.file);

    return 1;
}
Пример #4
0
/*!
  \brief Save category index to binary file (cidx)

  \param Map pointer to Map_info structure
  
  \return 0 on success
  \return 1 on error
 */
int Vect_cidx_save(struct Map_info *Map)
{
    struct Plus_head *plus;
    char *path;
    struct gvfile fp;

    G_debug(2, "Vect_cidx_save()");
    check_status(Map);

    plus = &(Map->plus);
    
    dig_file_init(&fp);
    
    path = Vect__get_path(Map);
    fp.file = G_fopen_new(path, GV_CIDX_ELEMENT);
    G_free(path);
    if (fp.file == NULL) {
	G_warning(_("Unable to create category index file for vector map <%s>"),
                  Vect_get_name(Map));
	return 1;
    }

    /* set portable info */
    dig_init_portable(&(plus->cidx_port), dig__byte_order_out());

    if (0 > dig_write_cidx(&fp, plus)) {
	G_warning(_("Error writing out category index file"));
	return 1;
    }

    fclose(fp.file);

    return 0;
}
Пример #5
0
FILE *I_fopen_cam_file_new(char *camera)
{
    FILE *fd;

    fd = G_fopen_new("camera", camera);
    if (!fd)
	error(camera, "can't create ", "");
    return fd;
}
Пример #6
0
static void write_cats(const char *element, const char *name,
		       struct Categories *cats)
{
    FILE *fd;
    int i, fp_map;
    char *descr;
    DCELL val1, val2;
    char str1[100], str2[100];

    fd = G_fopen_new(element, name);
    if (!fd)
	G_fatal_error(_("Unable to open %s file for map <%s>"), element, name);

    /* write # cats - note # indicate 3.0 or later */
    fprintf(fd, "# %ld categories\n", (long)cats->num);

    /* title */
    fprintf(fd, "%s\n", cats->title != NULL ? cats->title : "");

    /* write format and coefficients */
    fprintf(fd, "%s\n", cats->fmt != NULL ? cats->fmt : "");
    fprintf(fd, "%.2f %.2f %.2f %.2f\n",
	    cats->m1, cats->a1, cats->m2, cats->a2);

    /* if the map is integer or if this is a vector map, sort labels */
    if (strncmp(element, "dig", 3) == 0)
	fp_map = 0;
    else
	fp_map = Rast_map_is_fp(name, G_mapset());
    if (!fp_map)
	Rast_sort_cats(cats);

    /* write the cat numbers:label */
    for (i = 0; i < Rast_quant_nof_rules(&cats->q); i++) {
	descr = Rast_get_ith_d_cat(cats, i, &val1, &val2);
	if ((cats->fmt && cats->fmt[0])
	    || (descr && descr[0])) {
	    if (val1 == val2) {
		sprintf(str1, "%.10f", val1);
		G_trim_decimal(str1);
		fprintf(fd, "%s:%s\n", str1, descr != NULL ? descr : "");
	    }
	    else {
		sprintf(str1, "%.10f", val1);
		G_trim_decimal(str1);
		sprintf(str2, "%.10f", val2);
		G_trim_decimal(str2);
		fprintf(fd, "%s:%s:%s\n", str1, str2,
			descr != NULL ? descr : "");
	    }
	}
    }
    fclose(fd);
}
Пример #7
0
/*!
   \brief Writes the raster file header.

   Writes the cell file header information associated with map layer "map"
   into current mapset from the structure "cellhd".

   \param name name of map
   \param cellhd structure holding cell header info

   \return void
 */
void Rast_put_cellhd(const char *name, struct Cell_head *cellhd)
{
    FILE *fp;

    fp = G_fopen_new("cellhd", name);
    if (!fp)
	G_fatal_error(_("Unable to create header file for <%s>"), name);

    G__write_Cell_head(fp, cellhd, 1);
    fclose(fp);
}
Пример #8
0
/*!
 * \brief Write the database region
 *
 * Writes the database region file (WIND) in the user's current mapset
 * from region. 

 * <b>Warning:</b> Since this routine actually changes the database
 * region, it should only be called by modules which the user knows
 * will change the region. It is probably fair to say that only the
 * <tt>g.region</tt> should call this routine.
 *
 * \param[in,out] window pointer to Cell_head
 * \param dir directory name
 * \param name file name
 *
 * \return 1 on success
 * \return -1 on error (no diagnostic message is printed)
 *
 * \sa G_put_window()
 */
int G__put_window(const struct Cell_head *window, const char *dir, const char *name)
{
    FILE *fd;

    if (!(fd = G_fopen_new(dir, name)))
	return -1;

    G__write_Cell_head3(fd, window, 0);
    fclose(fd);

    return 1;
}
Пример #9
0
/**
   \brief Open/Create new vector map.

   \param Map pointer to vector map
   \param name map name
   \param with_z 2D or 3D (unused?)


   \return 0 success
   \return -1 error 
*/
int V1_open_new_nat(struct Map_info *Map, const char *name, int with_z)
{
    char buf[1000];
    struct stat info;

    G_debug(1, "V1_open_new_nat(): name = %s", name);

    sprintf(buf, "%s/%s", GRASS_VECT_DIRECTORY, name);

    /* Set the 'coor' file version */
    Map->head.Version_Major = GV_COOR_VER_MAJOR;
    Map->head.Version_Minor = GV_COOR_VER_MINOR;
    Map->head.Back_Major = GV_COOR_EARLIEST_MAJOR;
    Map->head.Back_Minor = GV_COOR_EARLIEST_MINOR;

    /* TODO open better */
    dig_file_init(&(Map->dig_fp));
    Map->dig_fp.file = G_fopen_new(buf, GRASS_VECT_COOR_ELEMENT);
    if (Map->dig_fp.file == NULL)
	return (-1);
    fclose(Map->dig_fp.file);

    dig_file_init(&(Map->dig_fp));
    Map->dig_fp.file = G_fopen_modify(buf, GRASS_VECT_COOR_ELEMENT);
    if (Map->dig_fp.file == NULL)
	return (-1);

    /* check to see if dig_plus file exists and if so, remove it */
    G__file_name(name_buf, buf, GV_TOPO_ELEMENT, G_mapset());
    if (stat(name_buf, &info) == 0)	/* file exists? */
	unlink(name_buf);

    G__file_name(name_buf, buf, GRASS_VECT_COOR_ELEMENT, G_mapset());

    Map->head.size = 0;
    Map->head.head_size = GV_COOR_HEAD_SIZE;
    Vect__write_head(Map);

    /* set conversion matrices */
    dig_init_portable(&(Map->head.port), dig__byte_order_out());

    if (!(dig__write_head(Map)))
	return (-1);

    return 0;
}
Пример #10
0
/*!
  \brief Write dblinks to file
  
  \param Map pointer to Map_info structure
  
  \return 0 on success
  \return -1 on error
 */
int Vect_write_dblinks(struct Map_info *Map)
{
    int i;
    FILE *fd;
    char *path, buf[1024];
    struct dblinks *dbl;

    if (Map->format != GV_FORMAT_NATIVE)
	/* nothing to write for non-native formats */
	return 0;
    
    G_debug(1, "Vect_write_dblinks(): map = %s, mapset = %s", Map->name,
	    Map->mapset);

    dbl = Map->dblnk;

    path = Vect__get_path(Map);
    fd = G_fopen_new(path, GV_DBLN_ELEMENT);
    G_free(path);
    if (fd == NULL) {		/* This may be correct, no tables defined */
	G_warning(_("Unable to create database definition file for vector map <%s>"),
		  Vect_get_name(Map));
	return -1;
    }

    for (i = 0; i < dbl->n_fields; i++) {
	if (dbl->field[i].name != NULL)
	    sprintf(buf, "%d/%s", dbl->field[i].number, dbl->field[i].name);
	else
	    sprintf(buf, "%d", dbl->field[i].number);

	fprintf(fd, "%s|%s|%s|%s|%s\n", buf, dbl->field[i].table,
		dbl->field[i].key, dbl->field[i].database,
		dbl->field[i].driver);
	G_debug(1, "%s|%s|%s|%s|%s", buf, dbl->field[i].table,
		dbl->field[i].key, dbl->field[i].database,
		dbl->field[i].driver);
    }
    fclose(fd);

    G_debug(1, "Dblinks written");
    
    return 0;
}
Пример #11
0
int G_put_cell_title (char *name, char *title)
{
    char *mapset;
    FILE *in, *out;
    char *tempfile;
    int line ;
    char buf[300];

    mapset = G_mapset() ;
    in = out = 0 ;
    in = G_fopen_old ("cats", name, mapset);
    if (!in)
    {
	sprintf (buf, "category information for [%s] in [%s] missing or invalid", name, mapset);
	G_warning (buf);
	return -1;
    }

    tempfile = G_tempfile();
    out = fopen (tempfile, "w");
    if (!out)
    {
	fclose (in);
        sprintf (buf, "G_put_title - can't create a temp file");
        G_warning (buf);
	return -1;
    }

    for (line = 0; G_getl (buf, sizeof buf, in); line++)
    {
	if (line == 1)
	{
	    strcpy (buf, title);
	    G_strip (buf);
	}
	fprintf (out, "%s\n", buf);
    }
    fclose (in);
    fclose (out);

/* must be #cats line, title line, and label for cat 0 */
    if (line < 3)
    {
	sprintf (buf, "category information for [%s] in [%s] invalid", name, mapset);
	G_warning (buf);
	return -1;
    }

    in = fopen (tempfile, "r");
    if (!in)
    {
	sprintf (buf, "G_put_title - can't reopen temp file");
	G_warning (buf);
	return -1;
    }

    out = G_fopen_new ("cats", name);
    if (!out)
    {
	fclose (in);
        sprintf (buf, "can't write category information for [%s] in [%s]", name, mapset);
        G_warning (buf);
	return -1;
    }

    while (fgets(buf, sizeof buf, in))
	fprintf (out, "%s", buf);

    fclose (in);
    fclose (out);

    return 1;
}
Пример #12
0
/**
 * The main function controls the program flow.
 */
int main(int argc, char *argv[])
{
    struct params p;
    label_t *labels;
    int n_labels, i;
    struct GModule *module;
    FILE *labelf;

    srand((unsigned int)time(NULL));

    G_gisinit(argv[0]);

    module = G_define_module();
    G_add_keyword(_("vector"));
    G_add_keyword(_("paint labels"));
    module->description =
	_("Create optimally placed labels for vector map(s)");

    /* parse options and flags */
    p.map = G_define_standard_option(G_OPT_V_MAP);

    p.type = G_define_standard_option(G_OPT_V_TYPE);
    p.type->options = "point,line,area";
    p.type->answer = "point,line,area";

    p.layer = G_define_standard_option(G_OPT_V_FIELD);

    p.column = G_define_option();
    p.column->key = "column";
    p.column->type = TYPE_STRING;
    p.column->required = YES;
    p.column->description =
	_("Name of attribute column to be used for labels");

    p.labels = G_define_option();
    p.labels->key = "labels";
    p.labels->description = _("Name for new paint-label file");
    p.labels->type = TYPE_STRING;
    p.labels->required = YES;
    p.labels->key_desc = "name";

    p.font = G_define_option();
    p.font->key = "font";
    p.font->type = TYPE_STRING;
    p.font->required = YES;
    p.font->description =
	_("Name of TrueType font (as listed in the fontcap)");
    p.font->guisection = _("Font");
    p.font->gisprompt = "font";

    p.size = G_define_option();
    p.size->key = "size";
    p.size->description = _("Label size (in map-units)");
    p.size->type = TYPE_DOUBLE;
    p.size->answer = "100";
    p.size->guisection = _("Font");

    p.isize = G_define_option();
    p.isize->key = "isize";
    p.isize->description = _("Icon size of point features (in map-units)");
    p.isize->type = TYPE_DOUBLE;
    p.isize->answer = "10";

    p.charset = G_define_option();
    p.charset->key = "charset";
    p.charset->type = TYPE_STRING;
    p.charset->required = NO;
    p.charset->answer = DEFAULT_CHARSET;
    p.charset->description =
	"Character encoding (default: " DEFAULT_CHARSET ")";

    p.color = G_define_option();
    p.color->key = "color";
    p.color->description = _("Text color");
    p.color->type = TYPE_STRING;
    p.color->answer = "black";
    p.color->options = "aqua,black,blue,brown,cyan,gray,green,grey,indigo,"
	"magenta,orange,purple,red,violet,white,yellow";
    p.color->guisection = _("Colors");

    p.hlcolor = G_define_option();
    p.hlcolor->key = "hcolor";
    p.hlcolor->description = _("Highlight color for text");
    p.hlcolor->type = TYPE_STRING;
    p.hlcolor->answer = "none";
    p.hlcolor->options =
	"none,aqua,black,blue,brown,cyan,gray,green,grey,indigo,"
	"magenta,orange,purple,red,violet,white,yellow";
    p.hlcolor->guisection = _("Colors");

    p.hlwidth = G_define_option();
    p.hlwidth->key = "hwidth";
    p.hlwidth->description = _("Width of highlight coloring");
    p.hlwidth->type = TYPE_DOUBLE;
    p.hlwidth->answer = "0";
    p.hlwidth->guisection = _("Colors");

    p.bgcolor = G_define_option();
    p.bgcolor->key = "background";
    p.bgcolor->description = _("Background color");
    p.bgcolor->type = TYPE_STRING;
    p.bgcolor->answer = "none";
    p.bgcolor->options =
	"none,aqua,black,blue,brown,cyan,gray,green,grey,indigo,"
	"magenta,orange,purple,red,violet,white,yellow";
    p.bgcolor->guisection = _("Colors");

    p.opaque = G_define_option();
    p.opaque->key = "opaque";
    p.opaque->description =
	_("Opaque to vector (only relevant if background color is selected)");
    p.opaque->type = TYPE_STRING;
    p.opaque->answer = "yes";
    p.opaque->options = "yes,no";
    p.opaque->key_desc = "yes|no";
    p.opaque->guisection = _("Colors");

    p.bocolor = G_define_option();
    p.bocolor->key = "border";
    p.bocolor->description = _("Border color");
    p.bocolor->type = TYPE_STRING;
    p.bocolor->answer = "none";
    p.bocolor->options =
	"none,aqua,black,blue,brown,cyan,gray,green,grey,indigo,"
	"magenta,orange,purple,red,violet,white,yellow";
    p.bocolor->guisection = _("Colors");

    p.bowidth = G_define_option();
    p.bowidth->key = "width";
    p.bowidth->description = _("Border width (only for ps.map output)");
    p.bowidth->type = TYPE_DOUBLE;
    p.bowidth->answer = "0";
    p.bowidth->guisection = _("Colors");

    if (G_parser(argc, argv))
	exit(EXIT_FAILURE);

    /* initialize labels (get text from database, and get features) */
    labels = labels_init(&p, &n_labels);
    /* start algorithm */
    /*   1. candidate position generation */
    label_candidates(labels, n_labels);
    /*   2. position evaluation */
    label_candidate_overlap(labels, n_labels);
    /*   3. position selection */
    simulate_annealing(labels, n_labels, &p);
    /* write lables to file */
    fprintf(stderr, "Writing labels to file: ...");
    labelf = G_fopen_new("paint/labels", p.labels->answer);
    for (i = 0; i < n_labels; i++) {
	if (labels[i].n_candidates > 0) {
	    print_label(labelf, &labels[i], &p);
	}
	G_percent(i, (n_labels - 1), 1);
    }
    fclose(labelf);

    return EXIT_SUCCESS;
}
Пример #13
0
void make_link(const char *dsn_opt,
	       const char *format,
	       char *option_str, char **options)
{
    int use_ogr;
    char *filename, *dsn;
    FILE *fp;
    
    struct Key_Value *key_val;
    
    key_val = G_create_key_value();

    /* check for weird options */
    if (G_strncasecmp(dsn_opt, "PG:", 3) == 0 &&
        strcmp(format, "PostgreSQL") != 0)
        G_warning(_("Data source starts with \"PG:\" prefix, expecting \"PostgreSQL\" "
                    "format (\"%s\" given)"), format);
    
    /* use OGR ? */
    use_ogr = is_ogr(format);
    if (use_ogr) {
        filename = "OGR";
        G_remove("", "PG");
    }
    else {
        filename = "PG";
        G_remove("", "OGR");
    }
    
    /* be friendly, ignored 'PG:' prefix for GRASS-PostGIS data driver */
    if (!use_ogr && strcmp(format, "PostgreSQL") == 0 &&
	G_strncasecmp(dsn_opt, "PG:", 3) == 0) {
	int i, length;
	
	length = strlen(dsn_opt);
	dsn = (char *) G_malloc(length - 3);
	for (i = 3; i < length; i++)
	    dsn[i-3] = dsn_opt[i];
	dsn[length-3] = '\0';
    }
    else {
	dsn = G_store(dsn_opt);
    }
        
    /* parse options for PG data format */
    if (options && *options && !use_ogr) {
        int i;
        char *key, *value;
        
        i = 0;
        while (options[i]) {
            if (parse_option_pg(options[i++], &key, &value) != 0)
                continue;
            G_set_key_value(key, value, key_val);
        }
    }

    /* datasource section */
    if (dsn) {
	if (use_ogr)
	    G_set_key_value("dsn", dsn, key_val);
	else
	    G_set_key_value("conninfo", dsn, key_val);
    }
    
    if (use_ogr) { /* OGR */
        if (format)
            G_set_key_value("format", format, key_val);
        if (option_str)
            G_set_key_value("options", option_str, key_val);
    }
    else {        /* PG */
        G_set_key_value("format", "PostgreSQL", key_val);
    }
    /* save file - OGR or PG */
    fp = G_fopen_new("", filename);
    if (!fp)
	G_fatal_error(_("Unable to create settings file"));

    if (G_fwrite_key_value(fp, key_val) < 0)
	G_fatal_error(_("Error writing settings file"));

    fclose(fp);

    if (use_ogr)
        G_verbose_message(_("Switched to OGR format (%s)"),
                          G_find_key_value("format", key_val));
    else
        G_verbose_message(_("Switched to PostGIS format"));

    G_free_key_value(key_val);
}
Пример #14
0
int G_put_3dview(const char *fname, const char *mapset,
		 const struct G_3dview *View, const struct Cell_head *Win)
{
    FILE *fp;

    if (NULL == (fp = G_fopen_new("3d.view", fname))) {
	G_warning(_("Unable to open %s for writing"), fname);
	return (-1);
    }

    fprintf(fp, "# %01d.%02d\n", vers_major, vers_minor);
    fprintf(fp, "PGM_ID: %s\n", View->pgm_id);

    if (Win) {
	fprintf(fp, "north: %f\n", Win->north);
	fprintf(fp, "south: %f\n", Win->south);
	fprintf(fp, "east: %f\n", Win->east);
	fprintf(fp, "west: %f\n", Win->west);
	fprintf(fp, "rows: %d\n", Win->rows);
	fprintf(fp, "cols: %d\n", Win->cols);
    }
    else {
	fprintf(fp, "north: %f\n", View->vwin.north);
	fprintf(fp, "south: %f\n", View->vwin.south);
	fprintf(fp, "east: %f\n", View->vwin.east);
	fprintf(fp, "west: %f\n", View->vwin.west);
	fprintf(fp, "rows: %d\n", View->vwin.rows);
	fprintf(fp, "cols: %d\n", View->vwin.cols);
    }

    fprintf(fp, "TO_EASTING: %f\n", View->from_to[1][0]);
    fprintf(fp, "TO_NORTHING: %f\n", View->from_to[1][1]);
    fprintf(fp, "TO_HEIGHT: %f\n", View->from_to[1][2]);
    fprintf(fp, "FROM_EASTING: %f\n", View->from_to[0][0]);
    fprintf(fp, "FROM_NORTHING: %f\n", View->from_to[0][1]);
    fprintf(fp, "FROM_HEIGHT: %f\n", View->from_to[0][2]);
    fprintf(fp, "Z_EXAG: %f\n", View->exag);
    fprintf(fp, "TWIST: %f\n", View->twist);
    fprintf(fp, "FIELD_VIEW: %f\n", View->fov);
    fprintf(fp, "MESH_FREQ: %d\n", View->mesh_freq);
    fprintf(fp, "POLY_RES: %d\n", View->poly_freq);
    fprintf(fp, "DOAVG: %d\n", View->doavg);
    fprintf(fp, "DISPLAY_TYPE: %d\n", View->display_type);
    fprintf(fp, "DOZERO: %d\n", View->dozero);

    fprintf(fp, "COLORGRID: %d\n", View->colorgrid);	/* 1 = use color */
    fprintf(fp, "SHADING: %d\n", View->shading);
    fprintf(fp, "FRINGE: %d\n", View->fringe);
    fprintf(fp, "BG_COL: %s\n", View->bg_col);
    fprintf(fp, "GRID_COL: %s\n", View->grid_col);
    fprintf(fp, "OTHER_COL: %s\n", View->other_col);
    fprintf(fp, "SURFACEONLY: %d\n", View->surfonly);
    fprintf(fp, "LIGHTS_ON: %d\n", View->lightson);
    fprintf(fp, "LIGHTPOS: %f %f %f %f\n", View->lightpos[0],
	    View->lightpos[1], View->lightpos[2], View->lightpos[3]);
    fprintf(fp, "LIGHTCOL: %f %f %f\n", View->lightcol[0], View->lightcol[1],
	    View->lightcol[2]);
    fprintf(fp, "LIGHTAMBIENT: %f\n", View->ambient);
    fprintf(fp, "SHINE: %f\n", View->shine);

    fclose(fp);

    return (1);
}
Пример #15
0
Файл: main.c Проект: caomw/grass
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, &region, &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);
}
Пример #16
0
Файл: main.c Проект: caomw/grass
int main(int argc, char *argv[])
{
    int n, i;
    int skip;
    const char *cur_mapset, *mapset;
    char **ptr;
    char **tokens;
    int no_tokens;
    FILE *fp;
    char path_buf[GPATH_MAX];
    char *path, *fs;
    int operation, nchoices;
    
    char **mapset_name;
    int nmapsets;
    
    struct GModule *module;    
    struct _opt {
        struct Option *mapset, *op, *fs;
        struct Flag *print, *list, *dialog;
    } opt;

    G_gisinit(argv[0]);

    module = G_define_module();
    G_add_keyword(_("general"));
    G_add_keyword(_("settings"));
    G_add_keyword(_("search path"));
    module->label = _("Modifies/prints the user's current mapset search path.");
    module->description = _("Affects the user's access to data existing "
                            "under the other mapsets in the current location.");

    opt.mapset = G_define_standard_option(G_OPT_M_MAPSET);
    opt.mapset->required = YES;
    opt.mapset->multiple = YES;
    opt.mapset->description = _("Name(s) of existing mapset(s) to add/remove or set");
    opt.mapset->guisection = _("Search path");
    
    opt.op = G_define_option();
    opt.op->key = "operation";
    opt.op->type = TYPE_STRING;
    opt.op->required = YES;
    opt.op->multiple = NO;
    opt.op->options = "set,add,remove";
    opt.op->description = _("Operation to be performed");
    opt.op->guisection = _("Search path");
    opt.op->answer = "add";
    
    opt.fs = G_define_standard_option(G_OPT_F_SEP);
    opt.fs->label = _("Field separator for printing (-l and -p flags)");
    opt.fs->answer = "space";
    opt.fs->guisection = _("Print");
    
    opt.list = G_define_flag();
    opt.list->key = 'l';
    opt.list->description = _("List all available mapsets in alphabetical order");
    opt.list->guisection = _("Print");
    opt.list->suppress_required = YES;

    opt.print = G_define_flag();
    opt.print->key = 'p';
    opt.print->description = _("Print mapsets in current search path");
    opt.print->guisection = _("Print");
    opt.print->suppress_required = YES;

    opt.dialog = G_define_flag();
    opt.dialog->key = 's';
    opt.dialog->description = _("Launch mapset selection GUI dialog");
    opt.dialog->suppress_required = YES;
    
    path = NULL;
    mapset_name = NULL;
    nmapsets = nchoices = 0;

    if (G_parser(argc, argv))
        exit(EXIT_FAILURE);

    operation = OP_UKN;
    if (opt.mapset->answer && opt.op->answer) {
        switch(opt.op->answer[0]) {
        case 's':
            operation = OP_SET;
            break;
        case 'a':
            operation = OP_ADD;
            break;
        case 'r':
            operation = OP_REM;
            break;
        default:
            G_fatal_error(_("Unknown operation '%s'"), opt.op->answer);
            break;
        }
    }
    
    fs = G_option_to_separator(opt.fs);

    /* list available mapsets */
    if (opt.list->answer) {
        if (opt.print->answer)
            G_warning(_("Flag -%c ignored"), opt.print->key);
        if (opt.dialog->answer)
            G_warning(_("Flag -%c ignored"), opt.dialog->key);
        if (opt.mapset->answer)
            G_warning(_("Option <%s> ignored"), opt.mapset->key);
        mapset_name = get_available_mapsets(&nmapsets);
        list_available_mapsets((const char **)mapset_name, nmapsets, fs);
        exit(EXIT_SUCCESS);
    }

    if (opt.print->answer) {
        if (opt.dialog->answer)
            G_warning(_("Flag -%c ignored"), opt.dialog->key);
        if (opt.mapset->answer)
            G_warning(_("Option <%s> ignored"), opt.mapset->key);
        list_accessible_mapsets(fs);
        exit(EXIT_SUCCESS);
    }
    
    /* show GUI dialog */
    if (opt.dialog->answer) {
        if (opt.mapset->answer)
            G_warning(_("Option <%s> ignored"), opt.mapset->key);
        sprintf(path_buf, "%s/gui/wxpython/modules/mapsets_picker.py", G_gisbase());
        G_spawn(getenv("GRASS_PYTHON"), "mapsets_picker.py", path_buf, NULL);
        exit(EXIT_SUCCESS);
    }

    cur_mapset = G_mapset();
    
    /* modify search path */
    if (operation == OP_SET) {
        int cur_found;
        
        cur_found = FALSE;
        for (ptr = opt.mapset->answers; *ptr != NULL; ptr++) {
            mapset = substitute_mapset(*ptr);
            if (G__mapset_permissions(mapset) < 0)
                G_fatal_error(_("Mapset <%s> not found"), mapset);
            if (strcmp(mapset, cur_mapset) == 0)
                cur_found = TRUE;
            nchoices++;
            append_mapset(&path, mapset);
        }
        if (!cur_found)
            G_warning(_("Current mapset (<%s>) must always included in the search path"),
                      cur_mapset);
    }
    else if (operation == OP_ADD) {
        /* add to existing search path */
        const char *oldname;
        
        if (path) {
            G_free(path);
            path = NULL;
        }

        /* read existing mapsets from SEARCH_PATH */
        for (n = 0; (oldname = G_get_mapset_name(n)); n++)
            append_mapset(&path, oldname);

        /* fetch and add new mapsets from param list */
        for (ptr = opt.mapset->answers; *ptr != NULL; ptr++) {

            mapset = substitute_mapset(*ptr);

            if (G_is_mapset_in_search_path(mapset)) {
                G_message(_("Mapset <%s> already in the path"), mapset);
                continue;
            }
            
            if (G__mapset_permissions(mapset) < 0)
                G_fatal_error(_("Mapset <%s> not found"), mapset);
            else
                G_verbose_message(_("Mapset <%s> added to search path"),
                                  mapset);

            nchoices++;
            append_mapset(&path, mapset);
        }
    }
    else if (operation == OP_REM) {
        /* remove from existing search path */
        const char *oldname;
        int found;
        
        if (path) {
            G_free(path);
            path = NULL;
        }
        
        /* read existing mapsets from SEARCH_PATH */
        for (n = 0; (oldname = G_get_mapset_name(n)); n++) {
            found = FALSE;
            
            for (ptr = opt.mapset->answers; *ptr && !found; ptr++)

                mapset = substitute_mapset(*ptr);
            
                if (strcmp(oldname, mapset) == 0)
                    found = TRUE;
            
                if (found) {
                    if (strcmp(oldname, cur_mapset) == 0)
                        G_warning(_("Current mapset (<%s>) must always included in the search path"),
                                  cur_mapset);
                    else
                        G_verbose_message(_("Mapset <%s> removed from search path"),
                                          oldname);
                    continue;
                }
                
                nchoices++;
                append_mapset(&path, oldname);
        }
    }
    /* stuffem sets nchoices */

    if (nchoices == 0) {
        G_important_message(_("Search path not modified"));
        if (path)
            G_free(path);
        
        if (nmapsets) {
            for(nmapsets--; nmapsets >= 0; nmapsets--)
                G_free(mapset_name[nmapsets]);
            G_free(mapset_name);
        }
        
        exit(EXIT_SUCCESS);
    }
    
    /* note I'm assuming that mapsets cannot have ' 's in them */
    tokens = G_tokenize(path, " ");

    fp = G_fopen_new("", "SEARCH_PATH");
    if (!fp)
        G_fatal_error(_("Unable to open SEARCH_PATH for write"));

    /*
     * make sure current mapset is specified in the list if not add it
     * to the head of the list
     */
    
    skip = 0;
    for (n = 0; n < nchoices; n++)
        if (strcmp(cur_mapset, tokens[n]) == 0) {
            skip = 1;
            break;
        }
    if (!skip) {
        fprintf(fp, "%s\n", cur_mapset);
    }

    /*
     * output the list, removing duplicates
     */

    no_tokens = G_number_of_tokens(tokens);

    for (n = 0; n < no_tokens; n++) {
        skip = 0;
        for (i = n; i < no_tokens; i++) {
            if (i != n) {
                if (strcmp(tokens[i], tokens[n]) == 0)
                    skip = 1;
            }
        }

        if (!skip)
            fprintf(fp, "%s\n", tokens[n]);
    }

    fclose(fp);
    G_free_tokens(tokens);

    if (path)
        G_free(path);

    if (nmapsets) {
        for(nmapsets--; nmapsets >= 0; nmapsets--)
            G_free(mapset_name[nmapsets]);
        G_free(mapset_name);
    }

    exit(EXIT_SUCCESS);
}
Пример #17
0
FILE *G_oldsites_open_new(const char *name)
{
    return G_fopen_new("site_lists", name);
}