Bladeren bron

Add a new parameter in the write method of the Vector class, to allow user to manage directly the category

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@55936 15284696-431f-4ddb-bdfa-cd5b030d7da7
Pietro Zambelli 12 jaren geleden
bovenliggende
commit
38db361ed7
1 gewijzigde bestanden met toevoegingen van 23 en 5 verwijderingen
  1. 23 5
      lib/python/pygrass/vector/__init__.py

+ 23 - 5
lib/python/pygrass/vector/__init__.py

@@ -104,8 +104,24 @@ class Vector(Info):
             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 ::
 
@@ -123,6 +139,7 @@ class Vector(Info):
             >>> 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 @@ class Vector(Info):
 
         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 @@ class Vector(Info):
             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: