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

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Feb 14 04:36:27 PST 2013


Author: lucadelu
Date: 2013-02-14 04:36:26 -0800 (Thu, 14 Feb 2013)
New Revision: 55045

Modified:
   grass/trunk/lib/python/pygrass/vector/geometry.py
Log:
pygrass fix vector geometry doctest

Modified: grass/trunk/lib/python/pygrass/vector/geometry.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/geometry.py	2013-02-14 10:33:45 UTC (rev 55044)
+++ grass/trunk/lib/python/pygrass/vector/geometry.py	2013-02-14 12:36:26 UTC (rev 55045)
@@ -127,10 +127,14 @@
 
 
 class Attrs(object):
-    def __init__(self, cat, table, writable=False):
+    def __init__(self, cat, table, writable=None):
         self.cat = cat
         self.table = table
         self.cond = "%s=%d" % (self.table.key, self.cat)
+        # TODO add 
+        #if writable == None:
+        #    self.writable
+        #else:
         self.writable = writable
 
     def __getitem__(self, key):
@@ -157,15 +161,17 @@
         """Set value of a given column of a table attribute. ::
 
             >>> from grass.pygrass.vector import VectorTopo
-            >>> from grass.pygrass.functions import copy
-            >>> copy('schools', 'schools', 'vect')
-            >>> schools = VectorTopo('schools')
+            >>> from grass.pygrass.functions import copy, remove
+            >>> copy('schools', 'myschools', 'vect')
+            >>> schools = VectorTopo('myschools')
             >>> schools.open('r')
             >>> school = schools[1]
-            >>> attrs = Attrs(school.line, schools.table)
+            >>> attrs = Attrs(school.cat, schools.table, True)
             >>> attrs['TAG'] = 'New Label'
             >>> attrs['TAG']
-            'New Label'
+            u'New Label'
+            >>> attrs.table.conn.close()
+            >>> remove('myschools','vect')
         """
         if self.writable:
             #UPDATE {tname} SET {new_col} = {old_col} WHERE {condition}
@@ -180,14 +186,25 @@
             raise GrassError(str_err)
 
     def __dict__(self):
-        """Reurn a dict of the attribute table row."""
+        """Return a dict of the attribute table row."""
         dic = {}
         for key, val in zip(self.keys(), self.values()):
             dic[key] = val
         return dic
 
     def values(self):
-        """Return the values of the attribute table row."""
+        """Return the values of the attribute table row.
+           >>> from grass.pygrass.vector import VectorTopo
+           >>> schools = VectorTopo('schools')
+           >>> schools.open('r')
+           >>> school = schools[1]
+           >>> attrs = Attrs(school.cat, schools.table)
+           >>> attrs.values()                             # doctest: +ELLIPSIS
+           (1,
+           ...
+           None)
+
+        """
         #SELECT {cols} FROM {tname} WHERE {condition}
         cur = self.table.execute(sql.SELECT_WHERE.format(cols='*',
                                                          tname=self.table.name,
@@ -195,7 +212,17 @@
         return cur.fetchone()
 
     def keys(self):
-        """Return the column name of the attribute table."""
+        """Return the column name of the attribute table.
+           >>> from grass.pygrass.vector import VectorTopo
+           >>> schools = VectorTopo('schools')
+           >>> schools.open('r')
+           >>> school = schools[1]
+           >>> attrs = Attrs(school.cat, schools.table)
+           >>> attrs.keys()                             # doctest: +ELLIPSIS
+           (u'cat',
+           ...
+           u'NOTES')        
+        """
         return self.table.columns.names()
 
     def commit(self):
@@ -432,9 +459,9 @@
 
         ::
             >>> pnt = Point(0, 0)
-            >>> area = point.buffer(10)
+            >>> area = pnt.buffer(10)
             >>> area.boundary                              #doctest: +ELLIPSIS
-            Line([Point(-10.000000, 0.000000),...Point(-10.000000, 0.000000)])
+            Line([Point(10.000000, 0.000000),...Point(10.000000, 0.000000)])
             >>> area.centroid
             Point(0.000000, 0.000000)
             >>> area.isles
@@ -1031,9 +1058,10 @@
     def area(self):
         """Return the area of the polygon.
         ::
-            >>> bound = Boundary([(0, 0), (0, 2), (2, 2), (2, 0), (0, 0)])
+            >>> bound = Boundary(points=[(0, 0), (0, 2), (2, 2), (2, 0),
+            ...                          (0, 0)])
             >>> bound.area()
-            4
+            4.0
 
         .."""
         libgis.G_begin_polygon_area_calculations()
@@ -1053,7 +1081,7 @@
         >>> from grass.pygrass.vector import VectorTopo
         >>> geo = VectorTopo('geology')
         >>> geo.open()
-        >>> centroid = Centroid(v_id=1, c_mapinfo=mun.c_mapinfo)
+        >>> centroid = Centroid(v_id=1, c_mapinfo=geo.c_mapinfo)
         >>> centroid
         Centoid(893202.874416, 297339.312795)
 



More information about the grass-commit mailing list