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

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 11 08:38:02 PST 2013


Author: zarch
Date: 2013-01-11 08:38:02 -0800 (Fri, 11 Jan 2013)
New Revision: 54591

Modified:
   grass/trunk/lib/python/pygrass/vector/geometry.py
Log:
Fix reading attribute table for areas

Modified: grass/trunk/lib/python/pygrass/vector/geometry.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/geometry.py	2013-01-11 16:37:52 UTC (rev 54590)
+++ grass/trunk/lib/python/pygrass/vector/geometry.py	2013-01-11 16:38:02 UTC (rev 54591)
@@ -112,10 +112,10 @@
 
 
 class Attrs(object):
-    def __init__(self, v_id, table, writable=False):
-        self.id = v_id
+    def __init__(self, line, table, writable=False):
+        self.line = line
         self.table = table
-        self.cond = "%s=%d" % (self.table.key, self.id)
+        self.cond = "%s=%d" % (self.table.key, self.line)
         self.writable = writable
 
     def __getitem__(self, key):
@@ -185,6 +185,7 @@
     def __init__(self, v_id=None, c_mapinfo=None, c_points=None, c_cats=None,
                  table=None, writable=False):
         self.id = v_id  # vector id
+        self.line = self.id
         self.c_mapinfo = c_mapinfo
 
         # set c_points
@@ -200,8 +201,8 @@
             self.c_cats = c_cats
 
         # set the attributes
-        if table and self.id:
-            self.attrs = Attrs(self.id, table, writable)
+        if table and self.line:
+            self.attrs = Attrs(self.line, table, writable)
 
     def is_with_topology(self):
         if self.c_mapinfo is not None:
@@ -1092,6 +1093,9 @@
             self.boundary = self.points()
             self.centroid = self.centroid()
             self.isles = self.get_isles()
+            libvect.Vect_read_line(self.c_mapinfo, None, self.c_cats,
+                                   self.centroid.id)
+            self.line = self.c_cats.contents.cat.contents.value
         elif boundary and centroid:
             self.boundary = boundary
             self.centroid = centroid
@@ -1100,6 +1104,11 @@
             str_err = "To instantiate an Area you need at least: Boundary and Centroid"
             raise GrassError(str_err)
 
+        # set the attributes
+        if self.attrs.table and self.line:
+            self.attrs = Attrs(self.line,
+                               self.attrs.table, self.attrs.writable)
+
         # geometry type
         self.gtype = libvect.GV_AREA
 



More information about the grass-commit mailing list