[GRASS-SVN] r57330 - grass/trunk/temporal/t.remove
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jul 31 07:20:40 PDT 2013
Author: huhabla
Date: 2013-07-31 07:20:40 -0700 (Wed, 31 Jul 2013)
New Revision: 57330
Added:
grass/trunk/temporal/t.remove/test.t.remove.sh
Modified:
grass/trunk/temporal/t.remove/t.remove.py
Log:
Implemeted recursive deletion of space time datasets and their registered maps
Modified: grass/trunk/temporal/t.remove/t.remove.py
===================================================================
--- grass/trunk/temporal/t.remove/t.remove.py 2013-07-31 09:16:24 UTC (rev 57329)
+++ grass/trunk/temporal/t.remove/t.remove.py 2013-07-31 14:20:40 UTC (rev 57330)
@@ -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 @@
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 @@
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
Added: grass/trunk/temporal/t.remove/test.t.remove.sh
===================================================================
--- grass/trunk/temporal/t.remove/test.t.remove.sh (rev 0)
+++ grass/trunk/temporal/t.remove/test.t.remove.sh 2013-07-31 14:20:40 UTC (rev 57330)
@@ -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
Property changes on: grass/trunk/temporal/t.remove/test.t.remove.sh
___________________________________________________________________
Added: svn:executable
+ *
More information about the grass-commit
mailing list