[GRASS-SVN] r47867 - in grass/trunk: include/vect lib/vector/Vlib vector/v.colors

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Aug 24 07:00:24 EDT 2011


Author: martinl
Date: 2011-08-24 04:00:24 -0700 (Wed, 24 Aug 2011)
New Revision: 47867

Modified:
   grass/trunk/include/vect/dig_defines.h
   grass/trunk/lib/vector/Vlib/color_read.c
   grass/trunk/lib/vector/Vlib/color_remove.c
   grass/trunk/lib/vector/Vlib/color_write.c
   grass/trunk/vector/v.colors/main.c
Log:
vlib: store alternative color tables to `vcolr2/mapset/name`


Modified: grass/trunk/include/vect/dig_defines.h
===================================================================
--- grass/trunk/include/vect/dig_defines.h	2011-08-24 07:44:48 UTC (rev 47866)
+++ grass/trunk/include/vect/dig_defines.h	2011-08-24 11:00:24 UTC (rev 47867)
@@ -12,7 +12,6 @@
 #define GV_FATAL_PRINT   1
 #define GV_FATAL_RETURN  2
 
-/*! \brief Vector directory layout, element names */
 /*! \brief Name of vector directory */
 #define GV_DIRECTORY    "vector"	
 /*! \brief Format description, data location (OGR) */
@@ -33,6 +32,10 @@
 #define GV_CIDX_ELEMENT "cidx"
 /*! \brief External format (OGR), feature index */
 #define GV_FIDX_ELEMENT "fidx"
+/*! \brief Color table */
+#define GV_COLR_ELEMENT "colr"
+/*! \brief Name of directory for alternative color tables */
+#define GV_COLR2_DIRECTORY "vcolr2"
 
 /*! \brief Endian check
 

Modified: grass/trunk/lib/vector/Vlib/color_read.c
===================================================================
--- grass/trunk/lib/vector/Vlib/color_read.c	2011-08-24 07:44:48 UTC (rev 47866)
+++ grass/trunk/lib/vector/Vlib/color_read.c	2011-08-24 11:00:24 UTC (rev 47867)
@@ -14,6 +14,7 @@
 #include <grass/gis.h>
 #include <grass/raster.h>
 #include <grass/vector.h>
+#include <grass/glocale.h>
 
 /*!
   \brief Read color table of vector map
@@ -39,6 +40,7 @@
 int Vect_read_colors(const char *name, const char *mapset,
 		     struct Colors *colors)
 {
+    int ret;
     char buf[GPATH_MAX];
     char xname[GNAME_MAX];
     
@@ -51,15 +53,18 @@
     
     name = xname;
 
-    if (strcmp(mapset, G_mapset()) == 0)
-	/* look for the regular color table */
-	sprintf(buf, "vector/%s/colr", name);
-    else	
+    if (strcmp(mapset, G_mapset()) == 0) {
+        /* look for the regular color table */
+	sprintf(buf, "%s/%s/%s", GV_DIRECTORY, name, GV_COLR_ELEMENT);
+        ret = Rast__read_colors(buf, "", mapset, colors);
+    }
+    else {
 	/* look for secondary color table in current mapset */
-	sprintf(buf, "vector/%s/colr2", name);
-    
-    if (Rast__read_colors(buf, "", mapset, colors) >= 0)
-	return 1;
-    
-    return 0;
+	sprintf(buf, "%s/%s/%s", GV_COLR2_DIRECTORY, mapset, name);
+        ret = Rast__read_colors(buf, "", G_mapset(), colors);
+    }
+    if (ret == -2)
+	return 0;
+
+    return ret;
 }

Modified: grass/trunk/lib/vector/Vlib/color_remove.c
===================================================================
--- grass/trunk/lib/vector/Vlib/color_remove.c	2011-08-24 07:44:48 UTC (rev 47866)
+++ grass/trunk/lib/vector/Vlib/color_remove.c	2011-08-24 11:00:24 UTC (rev 47867)
@@ -14,6 +14,7 @@
 #include <string.h>
 
 #include <grass/gis.h>
+#include <grass/vector.h>
 
 /*!
   \brief Remove color table of raster map
@@ -38,12 +39,12 @@
     }
 
     /* get rid of existing colr2, if any */
-    sprintf(element, "vector/%s", name);
-    stat = G_remove(element, "colr2");
+    sprintf(element, "%s/%s", GV_COLR2_DIRECTORY, mapset);
+    stat = G_remove(element, name);
 
     if (strcmp(mapset, G_mapset()) == 0) {
-	sprintf(element, "vector/%s", name);
-	stat = G_remove(element, "colr");
+	sprintf(element, "%s/%s", GV_DIRECTORY, name);
+	stat = G_remove(element, GV_COLR_ELEMENT);
     }
     
     return stat;

Modified: grass/trunk/lib/vector/Vlib/color_write.c
===================================================================
--- grass/trunk/lib/vector/Vlib/color_write.c	2011-08-24 07:44:48 UTC (rev 47866)
+++ grass/trunk/lib/vector/Vlib/color_write.c	2011-08-24 11:00:24 UTC (rev 47867)
@@ -59,32 +59,32 @@
 void Vect_write_colors(const char *name, const char *mapset,
 		       struct Colors *colors)
 {
-    char element[GPATH_MAX], *cname;
+    char element[GPATH_MAX];
+    const char *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;
+	mapset = xmapset;
     }
-
+    
     /*
-      if mapset is current mapset, remove colr2 file (created by pre 3.0 grass)
-      and then write original color table
+      if mapset is current mapset, 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";
+	cname = GV_COLR_ELEMENT;
+	sprintf(element, "%s/%s", GV_DIRECTORY, name);
     }
     else {
-	cname = "colr2";
+	cname = name;
+	sprintf(element, "%s/%s", GV_COLR2_DIRECTORY, mapset);
     }
-    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);

Modified: grass/trunk/vector/v.colors/main.c
===================================================================
--- grass/trunk/vector/v.colors/main.c	2011-08-24 07:44:48 UTC (rev 47866)
+++ grass/trunk/vector/v.colors/main.c	2011-08-24 11:00:24 UTC (rev 47867)
@@ -190,9 +190,6 @@
     if (!mapset)
 	G_fatal_error(_("Vector map <%s> not found"), name);
     
-    if (strcmp(mapset, G_mapset()) != 0)
-      G_fatal_error(_("Module currently allows to modify only vector maps from the current mapset"));
-
     stat = -1;
     if (remove) {
 	stat = Vect_remove_colors(name, mapset);



More information about the grass-commit mailing list