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

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jun 20 00:33:09 PDT 2014


Author: zarch
Date: 2014-06-20 00:33:09 -0700 (Fri, 20 Jun 2014)
New Revision: 60880

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 tickets #2311 ans #2320, add support to read and write 3D vector maps in PyGRASS.

Modified: grass/trunk/lib/python/pygrass/vector/__init__.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/__init__.py	2014-06-20 06:33:17 UTC (rev 60879)
+++ grass/trunk/lib/python/pygrass/vector/__init__.py	2014-06-20 07:33:09 UTC (rev 60880)
@@ -98,7 +98,8 @@
 
         ..
         """
-        return read_next_line(self.c_mapinfo, self.table, self.writable)
+        return read_next_line(self.c_mapinfo, self.table, self.writable,
+                              is2D=not self.is_3D())
 
     @must_be_open
     def rewind(self):
@@ -112,7 +113,7 @@
 
         :param geo_obj: a geometry grass object define in
                         grass.pygrass.vector.geometry
-        :type geo_obj: geometry GRASS object        
+        :type geo_obj: geometry GRASS object
         :param attrs: a list with the values that will be insert in the
                       attribute table.
         :type attrs: list
@@ -451,13 +452,16 @@
         libvect.Vect_cidx_find_all(self.c_mapinfo,
                                    layer if layer else self.layer,
                                    Obj.gtype, cat_id, ilist.c_ilist)
+        is2D = not self.is_3D()
         if generator:
             return (read_line(feature_id=v_id, c_mapinfo=self.c_mapinfo,
-                              table=self.table, writable=self.writable)
+                              table=self.table, writable=self.writable,
+                              is2D=is2D)
                     for v_id in ilist)
         else:
             return [read_line(feature_id=v_id, c_mapinfo=self.c_mapinfo,
-                              table=self.table, writable=self.writable)
+                              table=self.table, writable=self.writable,
+                              is2D=is2D)
                     for v_id in ilist]
 
     @must_be_open
@@ -492,7 +496,8 @@
             >>> mun.close()
 
         """
-        return read_line(feature_id, self.c_mapinfo, self.table, self.writable)
+        return read_line(feature_id, self.c_mapinfo, self.table, self.writable,
+                         is2D=not self.is_3D())
 
     @must_be_open
     def is_empty(self):
@@ -516,7 +521,7 @@
             self.table.update(key=line, values=attr)
         elif self.table is None and attrs:
             print "Table for vector {name} does not exist, attributes not" \
-                  " loaded".format(name=self.name) 
+                  " loaded".format(name=self.name)
         libvect.Vect_cat_set(geo_obj.c_cats, self.layer, line)
         result = libvect.Vect_rewrite_line(self.c_mapinfo,
                                            line, geo_obj.gtype,

Modified: grass/trunk/lib/python/pygrass/vector/abstract.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/abstract.py	2014-06-20 06:33:17 UTC (rev 60879)
+++ grass/trunk/lib/python/pygrass/vector/abstract.py	2014-06-20 07:33:09 UTC (rev 60880)
@@ -77,7 +77,7 @@
         >>> cens.close()
 
     """
-    def __init__(self, name, mapset='', layer=None, mode='r'):
+    def __init__(self, name, mapset='', layer=None, mode='r', with_z=False):
         self._name = ''
         self._mapset = ''
         # Set map name and mapset
@@ -90,6 +90,7 @@
         self.date_fmt = '%a %b  %d %H:%M:%S %Y'
         self.layer = layer
         self.mode = mode
+        self.with_z = with_z
 
     def __enter__(self, *args, **kwargs):
         self.open(*args, **kwargs)
@@ -291,7 +292,7 @@
         """Return if the Vector is open"""
         return is_open(self.c_mapinfo)
 
-    def open(self, mode=None, layer=1, overwrite=None,
+    def open(self, mode=None, layer=1, overwrite=None, with_z=None,
              # parameters valid only if mode == 'w'
              tab_name='', tab_cols=None, link_name=None, link_key='cat',
              link_db='$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db',
@@ -306,6 +307,10 @@
         :type layer: int
         :param overwrite: valid only for ``w`` mode
         :type overwrite: bool
+        :param with_z: specify if vector map must be open with third dimension
+                       enabled or not. Valid only for ``w`` mode,
+                       default: False
+        :type with_z: bool
         :param tab_name: define the name of the table that will be generate
         :type tab_name: str
         :param tab_cols: define the name and type of the columns of the
@@ -328,6 +333,8 @@
         methods
         """
         self.mode = mode if mode else self.mode
+        self.with_z = self.with_z if with_z is None else with_z
+        with_z = libvect.WITH_Z if self.with_z else libvect.WITHOUT_Z
         # check if map exists or not
         if not self.exist() and self.mode != 'w':
             raise OpenError("Map <%s> not found." % self._name)
@@ -355,8 +362,7 @@
 
         # If it is opened in write mode
         if self.mode == 'w':
-            openvect = libvect.Vect_open_new(self.c_mapinfo, self.name,
-                                             libvect.WITHOUT_Z)
+            openvect = libvect.Vect_open_new(self.c_mapinfo, self.name, with_z)
             self.dblinks = DBlinks(self.c_mapinfo)
             if tab_cols:
                 # create a link

Modified: grass/trunk/lib/python/pygrass/vector/geometry.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/geometry.py	2014-06-20 06:33:17 UTC (rev 60879)
+++ grass/trunk/lib/python/pygrass/vector/geometry.py	2014-06-20 07:33:09 UTC (rev 60880)
@@ -1528,7 +1528,7 @@
 
 
 def read_next_line(c_mapinfo, table=None, writable=False,
-                   c_points=None, c_cats=None):
+                   c_points=None, c_cats=None, is2D=True):
     """Return the next geometry feature of a vector map."""
     c_points = c_points if c_points else ctypes.pointer(libvect.line_pnts())
     c_cats = c_cats if c_cats else ctypes.pointer(libvect.line_cats())
@@ -1536,7 +1536,7 @@
                                                      c_cats)
     return GV_TYPE[ftype]['obj'](v_id=v_id, c_mapinfo=c_mapinfo,
                                  c_points=c_points, c_cats=c_cats,
-                                 table=table, writable=writable)
+                                 table=table, writable=writable, is2D=is2D)
 
 
 def c_read_line(feature_id, c_mapinfo, c_points, c_cats):
@@ -1553,7 +1553,7 @@
 
 
 def read_line(feature_id, c_mapinfo, table=None, writable=False,
-              c_points=None, c_cats=None):
+              c_points=None, c_cats=None, is2D=True):
     """Return a geometry object given the feature id and the c_mapinfo.
     """
     c_points = c_points if c_points else ctypes.pointer(libvect.line_pnts())
@@ -1563,7 +1563,7 @@
     if GV_TYPE[ftype]['obj'] is not None:
         return GV_TYPE[ftype]['obj'](v_id=feature_id, c_mapinfo=c_mapinfo,
                                      c_points=c_points, c_cats=c_cats,
-                                     table=table, writable=writable)
+                                     table=table, writable=writable, is2D=is2D)
 
 
 



More information about the grass-commit mailing list