فهرست منبع

Fix tickets https://trac.osgeo.org/grass/ticket/2311 ans https://trac.osgeo.org/grass/ticket/2320, add support to read and write 3D vector maps in PyGRASS.

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@60880 15284696-431f-4ddb-bdfa-cd5b030d7da7
Pietro Zambelli 11 سال پیش
والد
کامیت
2f2350afe2
3فایلهای تغییر یافته به همراه25 افزوده شده و 14 حذف شده
  1. 11 6
      lib/python/pygrass/vector/__init__.py
  2. 10 4
      lib/python/pygrass/vector/abstract.py
  3. 4 4
      lib/python/pygrass/vector/geometry.py

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

@@ -98,7 +98,8 @@ class Vector(Info):
 
 
         ..
         ..
         """
         """
-        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
     @must_be_open
     def rewind(self):
     def rewind(self):
@@ -112,7 +113,7 @@ class Vector(Info):
 
 
         :param geo_obj: a geometry grass object define in
         :param geo_obj: a geometry grass object define in
                         grass.pygrass.vector.geometry
                         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
         :param attrs: a list with the values that will be insert in the
                       attribute table.
                       attribute table.
         :type attrs: list
         :type attrs: list
@@ -451,13 +452,16 @@ class VectorTopo(Vector):
         libvect.Vect_cidx_find_all(self.c_mapinfo,
         libvect.Vect_cidx_find_all(self.c_mapinfo,
                                    layer if layer else self.layer,
                                    layer if layer else self.layer,
                                    Obj.gtype, cat_id, ilist.c_ilist)
                                    Obj.gtype, cat_id, ilist.c_ilist)
+        is2D = not self.is_3D()
         if generator:
         if generator:
             return (read_line(feature_id=v_id, c_mapinfo=self.c_mapinfo,
             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)
                     for v_id in ilist)
         else:
         else:
             return [read_line(feature_id=v_id, c_mapinfo=self.c_mapinfo,
             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]
                     for v_id in ilist]
 
 
     @must_be_open
     @must_be_open
@@ -492,7 +496,8 @@ class VectorTopo(Vector):
             >>> mun.close()
             >>> 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
     @must_be_open
     def is_empty(self):
     def is_empty(self):
@@ -516,7 +521,7 @@ class VectorTopo(Vector):
             self.table.update(key=line, values=attr)
             self.table.update(key=line, values=attr)
         elif self.table is None and attrs:
         elif self.table is None and attrs:
             print "Table for vector {name} does not exist, attributes not" \
             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)
         libvect.Vect_cat_set(geo_obj.c_cats, self.layer, line)
         result = libvect.Vect_rewrite_line(self.c_mapinfo,
         result = libvect.Vect_rewrite_line(self.c_mapinfo,
                                            line, geo_obj.gtype,
                                            line, geo_obj.gtype,

+ 10 - 4
lib/python/pygrass/vector/abstract.py

@@ -77,7 +77,7 @@ class Info(object):
         >>> cens.close()
         >>> 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._name = ''
         self._mapset = ''
         self._mapset = ''
         # Set map name and mapset
         # Set map name and mapset
@@ -90,6 +90,7 @@ class Info(object):
         self.date_fmt = '%a %b  %d %H:%M:%S %Y'
         self.date_fmt = '%a %b  %d %H:%M:%S %Y'
         self.layer = layer
         self.layer = layer
         self.mode = mode
         self.mode = mode
+        self.with_z = with_z
 
 
     def __enter__(self, *args, **kwargs):
     def __enter__(self, *args, **kwargs):
         self.open(*args, **kwargs)
         self.open(*args, **kwargs)
@@ -291,7 +292,7 @@ class Info(object):
         """Return if the Vector is open"""
         """Return if the Vector is open"""
         return is_open(self.c_mapinfo)
         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'
              # parameters valid only if mode == 'w'
              tab_name='', tab_cols=None, link_name=None, link_key='cat',
              tab_name='', tab_cols=None, link_name=None, link_key='cat',
              link_db='$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db',
              link_db='$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db',
@@ -306,6 +307,10 @@ class Info(object):
         :type layer: int
         :type layer: int
         :param overwrite: valid only for ``w`` mode
         :param overwrite: valid only for ``w`` mode
         :type overwrite: bool
         :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
         :param tab_name: define the name of the table that will be generate
         :type tab_name: str
         :type tab_name: str
         :param tab_cols: define the name and type of the columns of the
         :param tab_cols: define the name and type of the columns of the
@@ -328,6 +333,8 @@ class Info(object):
         methods
         methods
         """
         """
         self.mode = mode if mode else self.mode
         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
         # check if map exists or not
         if not self.exist() and self.mode != 'w':
         if not self.exist() and self.mode != 'w':
             raise OpenError("Map <%s> not found." % self._name)
             raise OpenError("Map <%s> not found." % self._name)
@@ -355,8 +362,7 @@ class Info(object):
 
 
         # If it is opened in write mode
         # If it is opened in write mode
         if self.mode == 'w':
         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)
             self.dblinks = DBlinks(self.c_mapinfo)
             if tab_cols:
             if tab_cols:
                 # create a link
                 # create a link

+ 4 - 4
lib/python/pygrass/vector/geometry.py

@@ -1528,7 +1528,7 @@ def c_read_next_line(c_mapinfo, c_points, c_cats):
 
 
 
 
 def read_next_line(c_mapinfo, table=None, writable=False,
 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."""
     """Return the next geometry feature of a vector map."""
     c_points = c_points if c_points else ctypes.pointer(libvect.line_pnts())
     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())
     c_cats = c_cats if c_cats else ctypes.pointer(libvect.line_cats())
@@ -1536,7 +1536,7 @@ def read_next_line(c_mapinfo, table=None, writable=False,
                                                      c_cats)
                                                      c_cats)
     return GV_TYPE[ftype]['obj'](v_id=v_id, c_mapinfo=c_mapinfo,
     return GV_TYPE[ftype]['obj'](v_id=v_id, c_mapinfo=c_mapinfo,
                                  c_points=c_points, c_cats=c_cats,
                                  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):
 def c_read_line(feature_id, c_mapinfo, c_points, c_cats):
@@ -1553,7 +1553,7 @@ def c_read_line(feature_id, c_mapinfo, c_points, c_cats):
 
 
 
 
 def read_line(feature_id, c_mapinfo, table=None, writable=False,
 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.
     """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())
     c_points = c_points if c_points else ctypes.pointer(libvect.line_pnts())
@@ -1563,7 +1563,7 @@ def read_line(feature_id, c_mapinfo, table=None, writable=False,
     if GV_TYPE[ftype]['obj'] is not None:
     if GV_TYPE[ftype]['obj'] is not None:
         return GV_TYPE[ftype]['obj'](v_id=feature_id, c_mapinfo=c_mapinfo,
         return GV_TYPE[ftype]['obj'](v_id=feature_id, c_mapinfo=c_mapinfo,
                                      c_points=c_points, c_cats=c_cats,
                                      c_points=c_points, c_cats=c_cats,
-                                     table=table, writable=writable)
+                                     table=table, writable=writable, is2D=is2D)