[GRASS-SVN] r58152 - grass/trunk/lib/python/pygrass/vector
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Nov 6 03:26:06 PST 2013
Author: lucadelu
Date: 2013-11-06 03:26:06 -0800 (Wed, 06 Nov 2013)
New Revision: 58152
Modified:
grass/trunk/lib/python/pygrass/vector/__init__.py
Log:
add function to check if vector has color table
Modified: grass/trunk/lib/python/pygrass/vector/__init__.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/__init__.py 2013-11-05 07:26:47 UTC (rev 58151)
+++ grass/trunk/lib/python/pygrass/vector/__init__.py 2013-11-06 11:26:06 UTC (rev 58152)
@@ -6,6 +6,8 @@
"""
import grass.lib.vector as libvect
from vector_type import VTYPE
+from grass.script.core import gisenv
+import os
#
# import pygrass modules
@@ -197,7 +199,39 @@
# return offset into file where the feature starts (on level 1)
geo_obj.offset = result
+ @must_be_open
+ def has_color_table(self):
+ """Return if vector has color table associated in file system;
+ Color table stored in the vector's attribute table well be not checked
+ Examples
+ --------
+ >>> cens = Vector('census')
+ >>> cens.open()
+ >>> cens.has_color_table()
+ False
+
+ >>> cens.close()
+ >>> from grass.pygrass.functions import copy, remove
+ >>> copy('census','mycensus','vect')
+ >>> from grass.pygrass.modules.shortcuts import vector as v
+ >>> v.colors(map='mycensus', color='population', column='TOTAL_POP')
+
+ >>> mycens = Vector('mycensus')
+ >>> mycens.open()
+ >>> mycens.has_color_table()
+ True
+ >>> mycens.close()
+ >>> remove('mycensus', 'vect')
+ """
+ path = os.path.join(gisenv()['GISDBASE'], gisenv()['LOCATION_NAME'],
+ self.mapset, 'vector', self.name, 'colr')
+ if os.path.exists(path):
+ return True
+ else:
+ return False
+
+
#=============================================
# VECTOR WITH TOPOLOGY
#=============================================
More information about the grass-commit
mailing list