[GRASS-SVN] r47561 - in grass/trunk: include lib/vector/Vlib
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Aug 11 16:55:24 EDT 2011
Author: martinl
Date: 2011-08-11 13:55:23 -0700 (Thu, 11 Aug 2011)
New Revision: 47561
Added:
grass/trunk/lib/vector/Vlib/color_remove.c
grass/trunk/lib/vector/Vlib/color_write.c
Modified:
grass/trunk/include/vector.h
Log:
vlib: Vect_remove_colors() and Vect_write_colors() implemeneted
Modified: grass/trunk/include/vector.h
===================================================================
--- grass/trunk/include/vector.h 2011-08-11 20:53:18 UTC (rev 47560)
+++ grass/trunk/include/vector.h 2011-08-11 20:55:23 UTC (rev 47561)
@@ -542,5 +542,7 @@
/* Raster color tables */
int Vect_read_colors(const char *, const char *, struct Colors *);
+int Vect_remove_colors(const char *, const char *);
+void Vect_write_colors(const char *, const char *, struct Colors *);
#endif /* GRASS_VECT_H */
Added: grass/trunk/lib/vector/Vlib/color_remove.c
===================================================================
--- grass/trunk/lib/vector/Vlib/color_remove.c (rev 0)
+++ grass/trunk/lib/vector/Vlib/color_remove.c 2011-08-11 20:55:23 UTC (rev 47561)
@@ -0,0 +1,50 @@
+/*!
+ \file lib/vector/Vlib/color_remove.c
+
+ \brief Vector Library - remove color table of vector map
+
+ (C) 2011 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 Martin Landa <landa.martin gmail.com>
+*/
+
+#include <string.h>
+
+#include <grass/gis.h>
+
+/*!
+ \brief Remove color table of raster map
+
+ \param name name of raster map
+ \param mapset name of mapset
+
+ \return -1 on error
+ \return 0 color table not found
+ \return 1 on success
+*/
+int Vect_remove_colors(const char *name, const char *mapset)
+{
+ char element[GPATH_MAX];
+ char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
+ int stat;
+
+ if (G_name_is_fully_qualified(name, xname, xmapset)) {
+ if (strcmp(xmapset, mapset) != 0)
+ return -1;
+ name = xname;
+ }
+
+ /* get rid of existing colr2, if any */
+ sprintf(element, "vector/%s", name);
+ stat = G_remove(element, "colr2");
+
+ if (strcmp(mapset, G_mapset()) == 0) {
+ sprintf(element, "vector/%s", name);
+ stat = G_remove(element, "colr");
+ }
+
+ return stat;
+}
Property changes on: grass/trunk/lib/vector/Vlib/color_remove.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Added: grass/trunk/lib/vector/Vlib/color_write.c
===================================================================
--- grass/trunk/lib/vector/Vlib/color_write.c (rev 0)
+++ grass/trunk/lib/vector/Vlib/color_write.c 2011-08-11 20:55:23 UTC (rev 47561)
@@ -0,0 +1,94 @@
+/*!
+ \file lib/vector/Vlib/color_write.c
+
+ \brief Vector Library - write color table for vector map
+
+ (C) 2011 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 Martin Landa <landa.martin gmail.com>
+*/
+
+#include <grass/gis.h>
+#include <grass/vector.h>
+#include <grass/raster.h>
+#include <grass/glocale.h>
+
+/*!
+ \brief Write color table for vector map
+
+ The color table is written for the vector map <i>name</i> in the
+ specified <i>mapset</i> from the <i>colors</i> structure.
+
+ 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 vector 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 vector 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>vector/name/colr2/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 vector map name
+ \param mapset mapset name
+ \param colors pointer to structure Colors which holds color info
+
+ \return void
+*/
+void Vect_write_colors(const char *name, const char *mapset,
+ struct Colors *colors)
+{
+ char element[GPATH_MAX], *cname;
+ 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
+ */
+ if (strcmp(mapset, G_mapset()) == 0) {
+ /* get rid of existing colr2, if any */
+ sprintf(element, "vector/%s/colr2", name);
+ G_remove(element, name);
+ cname = "colr";
+ }
+ else {
+ cname = "colr2";
+ }
+ sprintf(element, "vector/%s", name);
+ if (!(fd = G_fopen_new(element, cname)))
+ G_fatal_error(_("Unable to create <%s> file for map <%s>"),
+ element, name);
+
+ Rast__write_colors(fd, colors);
+ fclose(fd);
+}
Property changes on: grass/trunk/lib/vector/Vlib/color_write.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
More information about the grass-commit
mailing list