[GRASS-SVN] r53643 - in grass/trunk/temporal: . t.rast.colors t.rename

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Nov 1 17:56:39 PDT 2012


Author: huhabla
Date: 2012-11-01 17:56:39 -0700 (Thu, 01 Nov 2012)
New Revision: 53643

Added:
   grass/trunk/temporal/t.rename/
   grass/trunk/temporal/t.rename/Makefile
   grass/trunk/temporal/t.rename/t.rename.html
   grass/trunk/temporal/t.rename/t.rename.py
   grass/trunk/temporal/t.rename/test.t.rename.sh
Modified:
   grass/trunk/temporal/t.rast.colors/t.rast.colors.html
   grass/trunk/temporal/t.rast.colors/t.rast.colors.py
Log:
New renaming module


Modified: grass/trunk/temporal/t.rast.colors/t.rast.colors.html
===================================================================
--- grass/trunk/temporal/t.rast.colors/t.rast.colors.html	2012-11-02 00:54:33 UTC (rev 53642)
+++ grass/trunk/temporal/t.rast.colors/t.rast.colors.html	2012-11-02 00:56:39 UTC (rev 53643)
@@ -11,7 +11,7 @@
 to the <em>file</em> option of <em>r.colors</em>.
 <p>
 Please have a look at the <a href="r.colors.html">r.colors</a> 
-manpage for further informations.
+manual page for further informations.
 
 <h2>EXAMPLE</h2>
 

Modified: grass/trunk/temporal/t.rast.colors/t.rast.colors.py
===================================================================
--- grass/trunk/temporal/t.rast.colors/t.rast.colors.py	2012-11-02 00:54:33 UTC (rev 53642)
+++ grass/trunk/temporal/t.rast.colors/t.rast.colors.py	2012-11-02 00:56:39 UTC (rev 53643)
@@ -51,7 +51,7 @@
 
 #%flag
 #% key: r
-#% description: Remove existing color table
+#% description: Remove existing color tables
 #%end
 
 #%flag

Added: grass/trunk/temporal/t.rename/Makefile
===================================================================
--- grass/trunk/temporal/t.rename/Makefile	                        (rev 0)
+++ grass/trunk/temporal/t.rename/Makefile	2012-11-02 00:56:39 UTC (rev 53643)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../../
+
+PGM = t.rename
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script $(TEST_DST)

Added: grass/trunk/temporal/t.rename/t.rename.html
===================================================================
--- grass/trunk/temporal/t.rename/t.rename.html	                        (rev 0)
+++ grass/trunk/temporal/t.rename/t.rename.html	2012-11-02 00:56:39 UTC (rev 53643)
@@ -0,0 +1,19 @@
+<h2>DESCRIPTION</h2>
+
+This module renames space time datasets of different types (strds, stvds, str3ds) 
+and updates the space time dataset register entries of the registered maps.
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="t.create.html">t.create</a>,
+<a href="t.support.html">t.support</a>,
+<a href="t.register.html">t.register</a>
+</em>
+
+<h2>AUTHOR</h2>
+
+Sören Gebbert
+
+<p><i>Last changed: $Date: 2012-08-29 14:55:21 +0200 (Mi, 29. Aug 2012) $</i>
+

Added: grass/trunk/temporal/t.rename/t.rename.py
===================================================================
--- grass/trunk/temporal/t.rename/t.rename.py	                        (rev 0)
+++ grass/trunk/temporal/t.rename/t.rename.py	2012-11-02 00:56:39 UTC (rev 53643)
@@ -0,0 +1,102 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+############################################################################
+#
+# MODULE:       t.support
+# AUTHOR(S):    Soeren Gebbert
+#
+# PURPOSE:      Modify the metadata of a space time dataset
+# COPYRIGHT:    (C) 2011 by the GRASS Development Team
+#
+#               This program is free software under the GNU General Public
+#               License (version 2). Read the file COPYING that comes with GRASS
+#               for details.
+#
+#############################################################################
+
+#%module
+#% description: Modifies the metadata of a space time dataset.
+#% keywords: temporal
+#% keywords: support
+#%end
+
+#%option G_OPT_STDS_INPUT
+#%end
+
+#%option G_OPT_STDS_OUTPUT
+#%end
+
+#%option G_OPT_STDS_TYPE
+#% guidependency: input
+#% guisection: Required
+#%end
+
+import grass.temporal as tgis
+import grass.script as grass
+
+############################################################################
+
+
+def main():
+
+    # Get the options
+    input = options["input"]
+    output = options["output"]
+    type = options["type"]
+
+    # Make sure the temporal database exists
+    tgis.init()
+
+    #Get the current mapset to create the id of the space time dataset
+    mapset = grass.gisenv()["MAPSET"]
+
+    if input.find("@") >= 0:
+        old_id = input
+    else:
+        old_id = input + "@" + mapset
+
+    if output.find("@") >= 0:
+        new_id = output
+    else:
+        new_id = output + "@" + mapset
+        
+    # Do not overwrite yourself
+    if new_id == old_id:
+        return
+        
+
+    dbif = tgis.SQLDatabaseInterfaceConnection()
+    dbif.connect()
+
+    stds = tgis.dataset_factory(type, old_id)
+
+    if new_id.split("@")[1] != mapset:
+        grass.fatal(_("Space time %s dataset <%s> can not be renamed. "
+                      "Mapset of the new identifier differs from the current "
+                      "mapset.") % (stds.get_new_map_instance(None).get_type(), 
+                                    old_id))
+        
+    if stds.is_in_db(dbif=dbif) == False:
+        dbif.close()
+        grass.fatal(_("Space time %s dataset <%s> not found") % (
+            stds.get_new_map_instance(None).get_type(), old_id))
+
+    # Check if the new id is in the database
+    new_stds = tgis.dataset_factory(type, new_id)
+
+    if new_stds.is_in_db(dbif=dbif) == True and grass.overwrite() == False:
+        dbif.close()
+        grass.fatal(_("Unable to rename Space time %s dataset <%s>. Name <%s> "
+                      "is in use, please use the overwrite flag.") % (
+            stds.get_new_map_instance(None).get_type(), old_id, new_id))
+    
+    # Remove an already existing space time dataset
+    if new_stds.is_in_db(dbif=dbif) == True:
+        new_stds.delete(dbif=dbif)
+        
+    stds.select(dbif=dbif)
+    stds.rename(ident=new_id, dbif=dbif)
+    
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    main()


Property changes on: grass/trunk/temporal/t.rename/t.rename.py
___________________________________________________________________
Added: svn:executable
   + *

Added: grass/trunk/temporal/t.rename/test.t.rename.sh
===================================================================
--- grass/trunk/temporal/t.rename/test.t.rename.sh	                        (rev 0)
+++ grass/trunk/temporal/t.rename/test.t.rename.sh	2012-11-02 00:56:39 UTC (rev 53643)
@@ -0,0 +1,51 @@
+#!/bin/sh
+# Tests the rename module of space time datasets 
+
+# We need to set a specific region in the
+# @preprocess step of this test. 
+# 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)"
+
+# We need to create three space time dataset
+t.create --v --o type=strds temporaltype=absolute output=precip_abs1 \
+	title="Test" descr="This is the 1 test strds" semantictype=sum
+t.register -i input=precip_abs1 maps=prec_1,prec_2 \
+	start="2001-01-01" increment="1 seconds"
+
+t.create --v --o type=strds temporaltype=absolute output=precip_abs2 \
+	title="Test" descr="This is the 2 test strds" semantictype=sum
+t.register input=precip_abs2 maps=prec_1,prec_2
+
+t.create --v --o type=strds temporaltype=absolute output=precip_abs3 \
+	title="Test" descr="This is the 3 test strds" semantictype=sum
+t.register input=precip_abs3 maps=prec_1,prec_2
+
+
+t.info precip_abs1
+t.info precip_abs2
+t.info precip_abs3
+
+# @test Rename the space time raster dataset by overwritung an old one
+t.rename --o type=strds input=precip_abs1 output=precip_abs2
+t.info precip_abs2
+
+t.info type=rast input=prec_1
+t.info type=rast input=prec_2
+
+t.rename --o type=strds input=precip_abs2 output=precip_abs4
+t.info precip_abs4
+
+t.info type=rast input=prec_1
+t.info type=rast input=prec_2
+
+# Error checking, new dataset has the wrong mapset
+t.rename type=strds input=precip_abs4 output=precip_abs3 at BLABLA
+# Error checking, no overwrite flag set
+t.rename type=strds input=precip_abs4 output=precip_abs3
+
+t.remove --v type=strds input=precip_abs3,precip_abs4
+t.unregister type=rast maps=prec_1,prec_2
+g.remove rast=prec_1,prec_2


Property changes on: grass/trunk/temporal/t.rename/test.t.rename.sh
___________________________________________________________________
Added: svn:executable
   + *



More information about the grass-commit mailing list