Bläddra i källkod

Implemeted recursive deletion of space time datasets and their registered maps

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@57330 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 11 år sedan
förälder
incheckning
9f41f15b36
2 ändrade filer med 55 tillägg och 1 borttagningar
  1. 34 1
      temporal/t.remove/t.remove.py
  2. 21 0
      temporal/t.remove/test.t.remove.sh

+ 34 - 1
temporal/t.remove/t.remove.py

@@ -44,7 +44,15 @@
 #% required: no
 #%end
 
+#%flag
+#% key: r
+#% description: Remove all registered maps from the temporal and spatial database
+#%end
 
+#%flag
+#% key: f
+#% description: Force recursive removing
+#%end
 import grass.script as grass
 import grass.temporal as tgis
 
@@ -57,9 +65,14 @@ def main():
     datasets = options["inputs"]
     file = options["file"]
     type = options["type"]
+    recursive = flags["r"]
+    force = flags["f"]
+
+    if recursive and not force:
+        grass.fatal(_("The recursive flag works only in conjunction with the force flag: use -rf"))
 
     if datasets and file:
-        core.fatal(_("%s= and %s= are mutually exclusive") % ("input", "file"))
+        grass.fatal(_("%s= and %s= are mutually exclusive") % ("input", "file"))
 
     # Make sure the temporal database exists
     tgis.init()
@@ -109,6 +122,26 @@ def main():
             grass.fatal(_("Space time %s dataset <%s> not found")
                         % (sp.get_new_map_instance(None).get_type(), id))
 
+        if recursive and force:
+            grass.message(_("Removing registered maps"))
+            sp.select(dbif)
+            maps = sp.get_registered_maps_as_objects(dbif=dbif)
+            map_statement = ""
+            count = 1
+            for map in maps:
+                map.select(dbif)
+                grass.run_command("g.remove", rast=map.get_name(), quiet=True)
+                map_statement += map.delete(dbif=dbif, execute=False)
+
+                count += 1
+                # Delete every 100 maps
+                if count%100 == 0:
+                    dbif.execute_transaction(map_statement)
+                    map_statement = ""
+
+            if map_statement:
+                dbif.execute_transaction(map_statement)
+
         statement += sp.delete(dbif=dbif, execute=False)
 
     # Execute the collected SQL statenents

+ 21 - 0
temporal/t.remove/test.t.remove.sh

@@ -0,0 +1,21 @@
+#!/bin/sh
+# We need to set a specific region in the
+# @preprocess step of this test. We generate
+# raster with r.mapcalc and create several space time raster datasets
+# with absolute time
+# The region setting should work for UTM and LL test locations
+g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 res3=10 -p3
+
+r.mapcalc --o expr="prec_1 = rand(0, 550)"
+r.mapcalc --o expr="prec_2 = rand(0, 450)"
+r.mapcalc --o expr="prec_3 = rand(0, 320)"
+r.mapcalc --o expr="prec_4 = rand(0, 510)"
+r.mapcalc --o expr="prec_5 = rand(0, 300)"
+r.mapcalc --o expr="prec_6 = rand(0, 650)"
+
+# The first @test
+t.create --o type=strds temporaltype=absolute output=precip_abs1 title="A test" descr="A test"
+t.register --o -i input=precip_abs1 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="1 seconds"
+t.remove -rf type=strds input=precip_abs1
+# This will produce an error
+t.remove -r type=strds input=precip_abs1