Ver código fonte

Add area method to Boundary class

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@54719 15284696-431f-4ddb-bdfa-cd5b030d7da7
Pietro Zambelli 12 anos atrás
pai
commit
bc0e21b926
1 arquivos alterados com 13 adições e 0 exclusões
  1. 13 0
      lib/python/pygrass/vector/geometry.py

+ 13 - 0
lib/python/pygrass/vector/geometry.py

@@ -1004,6 +1004,19 @@ class Boundary(Line):
                                     left, right)
         return left.contents.value, right.contents.value
 
+    def area(self):
+        """Return the area of the polygon.
+        ::
+            >>> bound = Boundary([(0, 0), (0, 2), (2, 2), (2, 0), (0, 0)])
+            >>> bound.area()
+            4
+
+        .."""
+        libgis.G_begin_polygon_area_calculations()
+        return libgis.G_area_of_polygon(self.c_points.contents.x,
+                                        self.c_points.contents.y,
+                                        self.c_points.contents.n_points)
+
 
 class Centroid(Point):
     """The Centroid class inherit from the Point class.