Quellcode durchsuchen

v.what.strds: backport of flag to Update attribute table of input vector map (trunk, [66326:66332])

git-svn-id: https://svn.osgeo.org/grass/grass/branches/releasebranch_7_0@67220 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Neteler vor 9 Jahren
Ursprung
Commit
ad783b9080
1 geänderte Dateien mit 18 neuen und 1 gelöschten Zeilen
  1. 18 1
      scripts/v.what.strds/v.what.strds.py

+ 18 - 1
scripts/v.what.strds/v.what.strds.py

@@ -33,6 +33,7 @@
 #%end
 
 #%option G_OPT_V_OUTPUT
+#% required: no
 #%end
 
 #%option G_OPT_DB_WHERE
@@ -42,6 +43,12 @@
 #% key: t_where
 #%end
 
+#%flag
+#% key: u
+#% label: Update attribute table of input vector map
+#% description: Instead of creating a new vector map update the attribute table with value(s)
+#%end
+
 import grass.script as grass
 import grass.temporal as tgis
 from grass.pygrass.utils import copy as gcopy
@@ -88,6 +95,13 @@ def main():
     where = options["where"]
     tempwhere = options["t_where"]
 
+    if output and flags['u']:
+        grass.fatal(_("Cannot combine 'output' option and 'u' flag"))
+    elif not output and not flags['u']:
+        grass.fatal(_("'output' option or 'u' flag must be given"))
+    elif not output and flags['u']:
+        grass.warning(_("Attribute table of vector {name} will be updated...").format(name=input))
+
     if where == "" or where == " " or where == "\n":
         where = None
 
@@ -173,7 +187,10 @@ def main():
                 samples.append(s)
 
     # Get the layer and database connections of the input vector
-    gcopy(input, output, 'vect')
+    if output:
+        gcopy(input, output, 'vector')
+    else:
+        output = input
 
     msgr = Messenger()
     perc_curr = 0