Просмотр исходного кода

vlib: Vect_read_colors() added
dependency to rasterlib introduced


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@47525 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 13 лет назад
Родитель
Сommit
11e44a917a
4 измененных файлов с 71 добавлено и 2 удалено
  1. 1 1
      include/Make/Grass.make
  2. 3 0
      include/vector.h
  3. 2 1
      lib/vector/Vlib/Makefile
  4. 65 0
      lib/vector/Vlib/color_read.c

+ 1 - 1
include/Make/Grass.make

@@ -221,7 +221,7 @@ SITESDEPS        = $(VECTORLIB) $(DBMILIB) $(GISLIB) $(DATETIMELIB)
 STATSDEPS        = $(RASTERLIB) $(GISLIB) $(MATHLIB)	# NB: doesn't use libgis directly
 STATSDEPS        = $(RASTERLIB) $(GISLIB) $(MATHLIB)	# NB: doesn't use libgis directly
 SYMBDEPS         = $(GISLIB) $(MATHLIB)
 SYMBDEPS         = $(GISLIB) $(MATHLIB)
 TRANSDEPS        = $(MATHLIB)
 TRANSDEPS        = $(MATHLIB)
-VECTORDEPS       = $(DBMILIB) $(GRAPHLIB) $(DIG2LIB) $(LINKMLIB) $(RTREELIB) $(GISLIB) $(GEOSLIBS) $(GDALLIBS) $(MATHLIB) $(BTREE2LIB) $(GPROJLIB)
+VECTORDEPS       = $(DBMILIB) $(GRAPHLIB) $(DIG2LIB) $(LINKMLIB) $(RTREELIB) $(GISLIB) $(GEOSLIBS) $(GDALLIBS) $(MATHLIB) $(BTREE2LIB) $(GPROJLIB) $(RASTERDEP)
 VEDITDEPS        = $(VECTORLIB) $(DBMILIB) $(GISLIB) $(MATHLIB)
 VEDITDEPS        = $(VECTORLIB) $(DBMILIB) $(GISLIB) $(MATHLIB)
 NETADEPS         = $(VECTORLIB) $(DBMILIB) $(GISLIB)
 NETADEPS         = $(VECTORLIB) $(DBMILIB) $(GISLIB)
 
 

+ 3 - 0
include/vector.h

@@ -540,4 +540,7 @@ GEOSCoordSequence *Vect_get_area_points_geos(struct Map_info *, int);
 GEOSCoordSequence *Vect_get_isle_points_geos(struct Map_info *, int);
 GEOSCoordSequence *Vect_get_isle_points_geos(struct Map_info *, int);
 #endif
 #endif
 
 
+    /* Raster color tables */
+int Vect_read_colors(const char *, const char *, struct Colors *);
+
 #endif /* GRASS_VECT_H */
 #endif /* GRASS_VECT_H */

+ 2 - 1
lib/vector/Vlib/Makefile

@@ -7,7 +7,8 @@ LIB = VECTOR
 DEPENDENCIES =  $(ARCH_INCDIR)/Vect.h $(ARCH_INCDIR)/V_.h \
 DEPENDENCIES =  $(ARCH_INCDIR)/Vect.h $(ARCH_INCDIR)/V_.h \
 		$(ARCH_INCDIR)/vect/dig_defines.h \
 		$(ARCH_INCDIR)/vect/dig_defines.h \
 		$(ARCH_INCDIR)/vect/dig_macros.h $(ARCH_INCDIR)/vect/dig_structs.h \
 		$(ARCH_INCDIR)/vect/dig_macros.h $(ARCH_INCDIR)/vect/dig_structs.h \
-		$(ARCH_INCDIR)/vect/dig_externs.h $(ARCH_INCDIR)/vect/dig_globs.h $(GISDEP)
+		$(ARCH_INCDIR)/vect/dig_externs.h $(ARCH_INCDIR)/vect/dig_globs.h \
+		$(GISDEP) $(RASTERDEP)
 
 
 include $(MODULE_TOPDIR)/include/Make/Lib.make
 include $(MODULE_TOPDIR)/include/Make/Lib.make
 
 

+ 65 - 0
lib/vector/Vlib/color_read.c

@@ -0,0 +1,65 @@
+/*!
+  \file lib/vector/Vlib/color_read.c
+ 
+  \brief Vector Library - read 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 <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/vector.h>
+
+/*!
+  \brief Read color table of vector map
+  
+  The color table for the vector map <i>name</i> in the specified
+  <i>mapset</i> is read into the <i>colors</i> structure. 
+  
+  Note: If a secondary color file for map name <i>name</i> exists in
+  the current mapset, that color file is read. This allows the user to
+  define their own color lookup tables for vector maps found in other
+  mapsets.
+  
+  Warning message is printed if the color file is missing or invalid.
+  
+  \param name vector map name
+  \param mapset mapset name ("" for search path)
+  \param[out] colors pointer to Colors structure
+  
+  \return -1 on error
+  \return 0 if color table missing
+  \return 1 on success (color table found)
+*/
+int Vect_read_colors(const char *name, const char *mapset,
+		     struct Colors *colors)
+{
+    char buf[GPATH_MAX];
+    char xname[GNAME_MAX];
+    
+    Rast_init_colors(colors);
+    
+    strcpy(xname, name);
+    mapset = G_find_vector(xname, mapset);
+    if (!mapset)
+	return -1;
+    
+    name = xname;
+
+    if (strcmp(mapset, G_mapset()) == 0)
+	/* look for the regular color table */
+	sprintf(buf, "vector/%s/colr", name);
+    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;
+}