GRASS GIS 7 Programmer's Manual  7.5.svn(2017)-r71759
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vector/Vlib/color_read.c
Go to the documentation of this file.
1 /*!
2  \file lib/vector/Vlib/color_read.c
3 
4  \brief Vector Library - read color table of vector map
5 
6  (C) 2011 by the GRASS Development Team
7 
8  This program is free software under the GNU General Public License
9  (>=v2). Read the file COPYING that comes with GRASS for details.
10 
11  \author Martin Landa <landa.martin gmail.com>
12 */
13 
14 #include <string.h>
15 
16 #include <grass/gis.h>
17 #include <grass/raster.h>
18 #include <grass/vector.h>
19 #include <grass/glocale.h>
20 
21 /*!
22  \brief Read color table of vector map
23 
24  The color table for the vector map <i>name</i> in the specified
25  <i>mapset</i> is read into the <i>colors</i> structure.
26 
27  Note: If a secondary color file for map name <i>name</i> exists in
28  the current mapset, that color file is read. This allows the user to
29  define their own color lookup tables for vector maps found in other
30  mapsets.
31 
32  Warning message is printed if the color file is missing or invalid.
33 
34  \param name vector map name
35  \param mapset mapset name ("" for search path)
36  \param[out] colors pointer to Colors structure (can be NULL)
37 
38  \return -1 on error
39  \return 0 if color table missing
40  \return 1 on success (color table found)
41 */
42 int Vect_read_colors(const char *name, const char *mapset,
43  struct Colors *colors)
44 {
45  int ret;
46  char buf[GPATH_MAX];
47  char xname[GNAME_MAX];
48 
49  if (colors)
50  Rast_init_colors(colors);
51 
52  strcpy(xname, name);
53  mapset = G_find_vector(xname, mapset);
54  if (!mapset)
55  return -1;
56 
57  name = xname;
58 
59  if (strcmp(mapset, G_mapset()) == 0) {
60  /* look for the regular color table */
61  sprintf(buf, "%s/%s", GV_DIRECTORY, name);
62  ret = Rast__read_colors(buf, GV_COLR_ELEMENT, mapset, colors);
63  }
64  else {
65  /* look for secondary color table in current mapset */
66  sprintf(buf, "%s/%s", GV_COLR2_DIRECTORY, mapset);
67  ret = Rast__read_colors(buf, name, G_mapset(), colors);
68  }
69  if (ret == -2)
70  return 0;
71 
72  return ret;
73 }
#define GV_DIRECTORY
Name of vector directory.
Definition: dig_defines.h:8
const char * G_find_vector(char *name, const char *mapset)
Finds a vector map.
Definition: find_vect.c:41
int Vect_read_colors(const char *name, const char *mapset, struct Colors *colors)
Read color table of vector map.
void Rast_init_colors(struct Colors *colors)
Initialize color structure.
Definition: color_init.c:25
#define GPATH_MAX
Definition: gis.h:151
int Rast__read_colors(const char *element, const char *name, const char *mapset, struct Colors *colors)
#define GV_COLR2_DIRECTORY
Name of directory for alternative color tables.
Definition: dig_defines.h:30
Definition: gis.h:626
#define GNAME_MAX
Definition: gis.h:148
#define GV_COLR_ELEMENT
Color table.
Definition: dig_defines.h:28
const char * G_mapset(void)
Get current mapset name.
Definition: gis/mapset.c:33
const char * name
Definition: named_colr.c:7