Преглед изворни кода

pygrass vector: Fixed vector rewrite test and $MAP in sqlite path substitution

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@69552 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert пре 8 година
родитељ
комит
a52fcb4ce3
2 измењених фајлова са 11 додато и 10 уклоњено
  1. 7 4
      lib/python/pygrass/vector/__init__.py
  2. 4 6
      lib/python/pygrass/vector/table.py

+ 7 - 4
lib/python/pygrass/vector/__init__.py

@@ -535,8 +535,8 @@ class VectorTopo(Vector):
 
         Generate a new vector map
 
-            >>> test_vect = VectorTopo(test_vector_name)
-            >>> test_vect.open('w', tab_name='newvect', tab_cols=cols,
+            >>> test_vect = VectorTopo('newvect_2')
+            >>> test_vect.open('w', tab_name='newvect_2', tab_cols=cols,
             ...                overwrite=True)
 
         import a geometry feature ::
@@ -554,12 +554,14 @@ class VectorTopo(Vector):
             >>> test_vect.write(point0, cat=1, attrs=('pub',))
             >>> test_vect.write(point1, cat=2, attrs=('resturant',))
             >>> test_vect.table.conn.commit()  # save changes in the DB
+            >>> test_vect.table_to_dict()
+            {1: [1, u'pub'], 2: [2, u'resturant']}
             >>> test_vect.close()
 
-        Now rewrite on point of the vector map: ::
+        Now rewrite one point of the vector map: ::
 
             >>> test_vect.open('rw')
-            >>> test_vect.rewrite(point2, cat=1, attrs('Irish Pub'))
+            >>> test_vect.rewrite(point2, cat=1, attrs=('Irish Pub',))
             >>> test_vect.table.conn.commit()  # save changes in the DB
             >>> test_vect.close()
 
@@ -571,6 +573,7 @@ class VectorTopo(Vector):
             >>> test_vect[1].attrs['name'] == 'Irish Pub'
             True
             >>> test_vect.close()
+            >>> test_vect.remove()
         """
         if self.table is not None and attrs:
             self.table.update(key=cat, values=attrs)

+ 4 - 6
lib/python/pygrass/vector/table.py

@@ -48,19 +48,16 @@ def get_path(path, vect_name=None):
     :param path: The path with substitutional parameter
     :param vect_name: The name of the vector map
 
-    >>> path = '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db'
-    >>> new_path = get_path(path)
     >>> from grass.script.core import gisenv
     >>> import os
+    >>> path = '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db'
+    >>> new_path = get_path(path)
     >>> new_path2 = os.path.join(gisenv()['GISDBASE'], gisenv()['LOCATION_NAME'],
     ...                          gisenv()['MAPSET'], 'sqlite', 'sqlite.db')
     >>> new_path.replace("//","/") == new_path2.replace("//","/")
     True
-
     >>> path = '$GISDBASE/$LOCATION_NAME/$MAPSET/vector/$MAP/sqlite.db'
     >>> new_path = get_path(path, "test")
-    >>> from grass.script.core import gisenv
-    >>> import os
     >>> new_path2 = os.path.join(gisenv()['GISDBASE'], gisenv()['LOCATION_NAME'],
     ...                          gisenv()['MAPSET'], 'vector', 'test', 'sqlite.db')
     >>> new_path.replace("//","/") == new_path2.replace("//","/")
@@ -74,7 +71,8 @@ def get_path(path, vect_name=None):
         path = path.replace('$GISDBASE', mapset.gisdbase)
         path = path.replace('$LOCATION_NAME', mapset.location)
         path = path.replace('$MAPSET', mapset.name)
-        path = path.replace('$MAP', vect_name)
+        if vect_name is not None:
+            path = path.replace('$MAP', vect_name)
         return path