Jelajahi Sumber

pygrass: Verify pp_isle[i] is not a NULL pointer before trying to use it to instantiate line coordinates, get Area cat as an attribute from th centroid

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@66665 15284696-431f-4ddb-bdfa-cd5b030d7da7
Pietro Zambelli 9 tahun lalu
induk
melakukan
ece528e9f4
1 mengubah file dengan 11 tambahan dan 6 penghapusan
  1. 11 6
      lib/python/pygrass/vector/geometry.py

+ 11 - 6
lib/python/pygrass/vector/geometry.py

@@ -1147,10 +1147,10 @@ class Line(Geo):
                                   dist_x, dist_y, angle,
                                   int(round_), int(caps), tol,
                                   p_bound, pp_isle, n_isles)
-        return(Line(c_points=p_bound.contents),
-                    self[0],
-                    [Line(c_points=pp_isle[i].contents)
-                           for i in range(n_isles.contents.value)])
+        boundary = Line(c_points=p_bound.contents)
+        isles = [Line(c_points=pp_isle[i].contents)
+                 for i in range(n_isles.contents.value) if pp_isle[i]]
+        return(boundary, self[0], isles)
 
     def reset(self):
         """Reset line, using `Vect_reset_line` C function. ::
@@ -1576,12 +1576,17 @@ class Area(Geo):
         super(Area, self).__init__(**kargs)
 
         # set the attributes
-        if self.attrs and self.cat:
-            self.attrs.cat = self.cat
+        #if self.attrs and self.cat:
+        #    self.attrs.cat = self.cat
 
     def __repr__(self):
         return "Area(%d)" % self.id if self.id else "Area( )"
 
+    @property
+    def cat(self):
+        centroid = self.centroid()
+        return centroid.cat if centroid else None
+
     @mapinfo_must_be_set
     def points(self, line=None):
         """Return a Line object with the outer ring