GRASS GIS 7 Programmer's Manual  7.7.svn(2018)-r73600
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
raster/color_write.c File Reference

Raster Library - Write color table of raster map. More...

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <grass/gis.h>
#include <grass/glocale.h>
#include <grass/raster.h>
Include dependency graph for raster/color_write.c:

Go to the source code of this file.

Functions

void Rast_write_colors (const char *name, const char *mapset, struct Colors *colors)
 Write map layer color table. More...
 
void Rast__write_colors (FILE *fd, struct Colors *colors)
 Write map layer color table. More...
 

Detailed Description

Raster Library - Write color table of raster map.

(C) 1999-2009 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.

Author
USACERL and many others

Definition in file raster/color_write.c.

Function Documentation

void Rast__write_colors ( FILE *  fd,
struct Colors colors 
)

Write map layer color table.

Parameters
fdfile descriptor
colorspointer to Colors structure which holds color info

Definition at line 109 of file raster/color_write.c.

References getenv(), and Colors::version.

Referenced by Rast3d_write_colors(), Rast_write_colors(), and Vect_write_colors().

void Rast_write_colors ( const char *  name,
const char *  mapset,
struct Colors colors 
)

Write map layer color table.

The color table is written for the raster map name in the specified mapset from the colors structure.

If there is an error, -1 is returned. No diagnostic is printed. Otherwise, 1 is returned.

The colors 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().

Note: The calling sequence for this function deserves special attention. The mapset 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 mapset is the current mapset, then the color file for name will be overwritten by the new color table. But if mapset is not the current mapset, then the color table is actually written in the current mapset under the colr2 element as: colr2/mapset/name.

The rules are written out using floating-point format, removing trailing zeros (possibly producing integers). The flag marking the colors as floating-point is not 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

Parameters
namemap name
mapsetmapset name
colorspointer to structure Colors which holds color info
Returns
void

Definition at line 72 of file raster/color_write.c.

References _, fclose(), fd, G_fatal_error(), G_fopen_new(), G_mapset(), G_name_is_fully_qualified(), G_remove(), GMAPSET_MAX, GNAME_MAX, and Rast__write_colors().

Referenced by create_raster(), IL_output_2d(), and IL_resample_output_2d().