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

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 11 08:37:53 PST 2013


Author: zarch
Date: 2013-01-11 08:37:52 -0800 (Fri, 11 Jan 2013)
New Revision: 54590

Modified:
   grass/trunk/lib/python/pygrass/vector/abstract.py
Log:
Modify the open method to create the attribute table

Modified: grass/trunk/lib/python/pygrass/vector/abstract.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/abstract.py	2013-01-11 16:37:45 UTC (rev 54589)
+++ grass/trunk/lib/python/pygrass/vector/abstract.py	2013-01-11 16:37:52 UTC (rev 54590)
@@ -11,7 +11,7 @@
 
 from pygrass import functions
 from pygrass.errors import GrassError, OpenError, must_be_open
-from table import DBlinks
+from table import DBlinks, Link
 
 #=============================================
 # VECTOR ABSTRACT CLASS
@@ -221,7 +221,12 @@
         return (self.c_mapinfo.contents.open != 0 and
                 self.c_mapinfo.contents.open != libvect.VECT_CLOSED_CODE)
 
-    def open(self, mode='r', layer='0', overwrite=None):
+    def open(self, mode='r', layer='0', overwrite=None,
+             # parameters valid only if mode == 'w'
+             tab_name='', tab_cols=['cat', ],
+             link_number=1, link_name=None, link_key='cat',
+             link_db='$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite.db',
+             link_driver='sqlite'):
         """::
 
             >>> mun = Info('boundary_municp_sqlite')
@@ -251,6 +256,18 @@
             #TODO: build topo if new
             openvect = libvect.Vect_open_new(self.c_mapinfo, self.name,
                                              libvect.WITHOUT_Z)
+            # create a link
+            link = Link(link_number,
+                        link_name if link_name else self.name,
+                        tab_name if tab_name else self.name,
+                        link_key, link_db, link_driver)
+            self.dblinks = DBlinks(self.c_mapinfo)
+            # add the new link
+            self.dblinks.add(link)
+            # get the table
+            table = link.table()
+            # create the new columns
+            table.columns.create(tab_cols)
         elif mode == 'rw':
             openvect = libvect.Vect_open_update2(self.c_mapinfo, self.name,
                                                  self.mapset, layer)



More information about the grass-commit mailing list