[GRASS-SVN] r55936 - grass/trunk/lib/python/pygrass/vector

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Apr 20 10:17:12 PDT 2013


Author: zarch
Date: 2013-04-20 10:17:12 -0700 (Sat, 20 Apr 2013)
New Revision: 55936

Modified:
   grass/trunk/lib/python/pygrass/vector/__init__.py
Log:
Add a new parameter in the write method of the Vector class, to allow user to manage directly the category

Modified: grass/trunk/lib/python/pygrass/vector/__init__.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/__init__.py	2013-04-20 15:34:46 UTC (rev 55935)
+++ grass/trunk/lib/python/pygrass/vector/__init__.py	2013-04-20 17:17:12 UTC (rev 55936)
@@ -104,9 +104,25 @@
             raise GrassError("Vect_rewind raise an error.")
 
     @must_be_open
-    def write(self, geo_obj, attrs=None):
-        """Write geometry features and attributes
+    def write(self, geo_obj, attrs=None, set_cats=True):
+        """Write geometry features and attributes.
 
+        Parameters
+        ----------
+
+        geo_obj : geometry GRASS object
+            A geometry grass object define in grass.pygrass.vector.geometry.
+        attrs: list, optional
+            A list with the values that will be insert in the attribute table.
+        set_cats, bool, optional
+            If True, the category of the geometry feature is set using the
+            default layer of the vector map and a progressive category value
+            (default), otherwise the c_cats attribute of the geometry object
+            will be used.
+
+        Examples
+        --------
+
         Open a new vector map ::
 
             >>> new = VectorTopo('newvect')
@@ -123,6 +139,7 @@
             >>> new.open('w', tab_name='newvect', tab_cols=cols)
 
         import a geometry feature ::
+
             >>> from grass.pygrass.vector.geometry import Point
 
         create two points ::
@@ -132,8 +149,8 @@
 
         then write the two points on the map, with ::
 
-            >>> new.write2(point0, ('pub', ))
-            >>> new.write2(point1, ('resturnat', ))
+            >>> new.write(point0, ('pub', ))
+            >>> new.write(point1, ('resturnat', ))
 
         close the vector map ::
 
@@ -165,7 +182,8 @@
             cur.execute(self.table.columns.insert_str, attr)
             cur.close()
 
-        libvect.Vect_cat_set(geo_obj.c_cats, self.layer, self.n_lines)
+        if set_cats:
+            libvect.Vect_cat_set(geo_obj.c_cats, self.layer, self.n_lines)
         result = libvect.Vect_write_line(self.c_mapinfo, geo_obj.gtype,
                                          geo_obj.c_points, geo_obj.c_cats)
         if result == -1:



More information about the grass-commit mailing list