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

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Nov 12 07:26:41 PST 2012


Author: zarch
Date: 2012-11-12 07:26:41 -0800 (Mon, 12 Nov 2012)
New Revision: 53774

Modified:
   grass/trunk/lib/python/pygrass/vector/__init__.py
   grass/trunk/lib/python/pygrass/vector/abstract.py
   grass/trunk/lib/python/pygrass/vector/geometry.py
Log:
Fix vector methods: close and build topology

Modified: grass/trunk/lib/python/pygrass/vector/__init__.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/__init__.py	2012-11-12 10:31:29 UTC (rev 53773)
+++ grass/trunk/lib/python/pygrass/vector/__init__.py	2012-11-12 15:26:41 UTC (rev 53774)
@@ -14,9 +14,9 @@
 #
 from pygrass.errors import GrassError
 
-from basic import Bbox
 import geometry
 from abstract import Info
+from basic import Bbox
 
 import grass.script.core as core
 _GRASSENV = core.gisenv()
@@ -27,8 +27,8 @@
           "holes": libvect.Vect_get_num_holes,
           "islands": libvect.Vect_get_num_islands,
           "kernels": libvect.Vect_get_num_kernels,
-          "line_points": libvect.Vect_get_num_line_points,
-          "lines": libvect.Vect_get_num_lines,
+          "lines": libvect.Vect_get_num_line_points,
+          "points": libvect.Vect_get_num_lines,
           "nodes": libvect.Vect_get_num_nodes,
           "updated_lines": libvect.Vect_get_num_updated_lines,
           "updated_nodes": libvect.Vect_get_num_updated_nodes,
@@ -41,7 +41,8 @@
            "islands": geometry.Isle,
            "kernels": None,
            "line_points": None,
-           "lines": geometry.Boundary,
+           "points": geometry.Point,
+           "lines": geometry.Line,
            "nodes": geometry.Node,
            "volumes": None}
 
@@ -125,12 +126,9 @@
                                      c_points=c_points,
                                      c_cats=c_cats)
 
-    def bbox(self):
-        """Return the BBox of the vecor map
-        """
-        bbox = Bbox()
-        libvect.Vect_get_map_box(self.c_mapinfo, bbox.c_bbox)
-        return bbox
+    def rewind(self):
+        if libvect.Vect_rewind(self.c_mapinfo) == -1:
+            raise GrassError("Vect_rewind raise an error.")
 
     def write(self, geo_obj):
         """::
@@ -387,4 +385,12 @@
                                          geo_obj.offset) == -1:
                 raise GrassError("C funtion: Vect_restore_line.")
         else:
-            raise ValueError("The value have not an offset attribute.")
\ No newline at end of file
+            raise ValueError("The value have not an offset attribute.")
+
+    def bbox(self):
+        """Return the BBox of the vecor map
+        """
+        bbox = Bbox()
+        if libvect.Vect_get_map_box(self.c_mapinfo, bbox.c_bbox) == 0:
+            raise GrassError("I can not find the Bbox.")
+        return bbox

Modified: grass/trunk/lib/python/pygrass/vector/abstract.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/abstract.py	2012-11-12 10:31:29 UTC (rev 53773)
+++ grass/trunk/lib/python/pygrass/vector/abstract.py	2012-11-12 15:26:41 UTC (rev 53774)
@@ -226,7 +226,8 @@
             return False
 
     def is_open(self):
-        return bool(self.c_mapinfo.contents.open)
+        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):
         """::
@@ -239,7 +240,6 @@
 
         ..
         """
-        print "Sto aprendo..."
         # check if map exists or not
         if not self.exist() and mode != 'w':
             raise OpenError("Map <%s> not found." % self._name)
@@ -265,7 +265,7 @@
         # initialize the dblinks object
         self.dblinks = DBlinks(self.c_mapinfo)
         # check the C function result.
-        if openvect != self._topo_level:
+        if openvect == -1:
             str_err = "Not able to open the map, C function return %d."
             raise OpenError(str_err % openvect)
 
@@ -282,6 +282,15 @@
         env.remove(vect=self.name)
 
     def build(self):
-        """Build vector Topology"""
-        #TODO: Add function
-        pass
\ No newline at end of file
+        """Close the vector map and build vector Topology"""
+        self.close()
+        libvect.Vect_set_open_level(1)
+        if libvect.Vect_open_old2(self.c_mapinfo, self.name,
+                                  self.mapset, '0') != 1:
+            str_err = 'Error when trying to open the vector map.'
+            raise GrassError(str_err)
+        # Vect_build returns 1 on success and 0 on error (bool approach)
+        if libvect.Vect_build(self.c_mapinfo) != 1:
+            str_err = 'Error when trying build topology with Vect_build'
+            raise GrassError(str_err)
+        libvect.Vect_close(self.c_mapinfo)
\ No newline at end of file

Modified: grass/trunk/lib/python/pygrass/vector/geometry.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/geometry.py	2012-11-12 10:31:29 UTC (rev 53773)
+++ grass/trunk/lib/python/pygrass/vector/geometry.py	2012-11-12 15:26:41 UTC (rev 53774)
@@ -174,11 +174,15 @@
 
     ..
     """
-    def __init__(self, x=0, y=0, z=None, **kargs):
+    def __init__(self, x=0, y=0, z=None, is2D=True, **kargs):
         super(Point, self).__init__(**kargs)
-        self.is2D = True if z is None else False
-        z = z if z is not None else 0
-        libvect.Vect_append_point(self.c_points, x, y, z)
+        if self.id is not None:
+            self.read()
+            self.is2D = is2D
+        else:
+            self.is2D = True if z is None else False
+            z = z if z is not None else 0
+            libvect.Vect_append_point(self.c_points, x, y, z)
 
         # geometry type
         self.gtype = libvect.GV_POINT



More information about the grass-commit mailing list