[GRASS-SVN] r52510 - in grass/trunk: lib/python lib/python/temporal temporal temporal/t.rast.export temporal/t.rast.import temporal/t.vect.export temporal/t.vect.import

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Aug 2 18:00:20 PDT 2012


Author: huhabla
Date: 2012-08-02 18:00:19 -0700 (Thu, 02 Aug 2012)
New Revision: 52510

Added:
   grass/trunk/lib/python/temporal/stds_export.py
   grass/trunk/lib/python/temporal/stds_import.py
   grass/trunk/temporal/t.vect.export/
   grass/trunk/temporal/t.vect.export/Makefile
   grass/trunk/temporal/t.vect.export/t.vect.export.html
   grass/trunk/temporal/t.vect.export/t.vect.export.py
   grass/trunk/temporal/t.vect.export/test.t.vect.export.sh
   grass/trunk/temporal/t.vect.import/
   grass/trunk/temporal/t.vect.import/Makefile
   grass/trunk/temporal/t.vect.import/t.vect.import.html
   grass/trunk/temporal/t.vect.import/t.vect.import.py
   grass/trunk/temporal/t.vect.import/test.t.vect.import.sh
Modified:
   grass/trunk/lib/python/core.py
   grass/trunk/lib/python/temporal/Makefile
   grass/trunk/lib/python/temporal/__init__.py
   grass/trunk/lib/python/temporal/aggregation.py
   grass/trunk/lib/python/temporal/space_time_datasets_tools.py
   grass/trunk/temporal/t.rast.export/t.rast.export.py
   grass/trunk/temporal/t.rast.export/test.t.rast.export.sh
   grass/trunk/temporal/t.rast.import/t.rast.import.py
   grass/trunk/temporal/t.rast.import/test.t.rast.import.sh
Log:
Added space time vector import and export. Import and export are
consolidated for space time datasets and moved to the temporal library.
Space time raster and vector datasets export and import modules 
are using the grass packing mechanism (v.pack, v.unpack, r.pack and r.unpack).
Using new projection comparison method.
Some bugfixing.


Modified: grass/trunk/lib/python/core.py
===================================================================
--- grass/trunk/lib/python/core.py	2012-08-02 23:26:50 UTC (rev 52509)
+++ grass/trunk/lib/python/core.py	2012-08-03 01:00:19 UTC (rev 52510)
@@ -580,10 +580,13 @@
     kvdict = KeyValue()
     
     for line in text:
-        key, value = line.split(sep)
-        key = key.strip()
-        value = value.strip()
-        
+        if line.find(sep) >= 0:
+            key, value = line.split(sep)
+            key = key.strip()
+            value = value.strip()
+        else:
+            # Jump over empty values
+            continue
         values = value.split(val_sep)
         value_list = []
         

Modified: grass/trunk/lib/python/temporal/Makefile
===================================================================
--- grass/trunk/lib/python/temporal/Makefile	2012-08-02 23:26:50 UTC (rev 52509)
+++ grass/trunk/lib/python/temporal/Makefile	2012-08-03 01:00:19 UTC (rev 52510)
@@ -8,7 +8,7 @@
 GDIR = $(PYDIR)/grass
 DSTDIR = $(GDIR)/temporal
 
-MODULES = base core abstract_dataset abstract_map_dataset abstract_space_time_dataset space_time_datasets space_time_datasets_tools metadata spatial_extent temporal_extent datetime_math temporal_granularity temporal_relationships unit_tests aggregation extract mapcalc univar_statistics
+MODULES = base core abstract_dataset abstract_map_dataset abstract_space_time_dataset space_time_datasets space_time_datasets_tools metadata spatial_extent temporal_extent datetime_math temporal_granularity temporal_relationships unit_tests aggregation stds_export stds_import extract mapcalc univar_statistics
 
 PYFILES := $(patsubst %,$(DSTDIR)/%.py,$(MODULES) __init__)
 PYCFILES := $(patsubst %,$(DSTDIR)/%.pyc,$(MODULES) __init__)

Modified: grass/trunk/lib/python/temporal/__init__.py
===================================================================
--- grass/trunk/lib/python/temporal/__init__.py	2012-08-02 23:26:50 UTC (rev 52509)
+++ grass/trunk/lib/python/temporal/__init__.py	2012-08-03 01:00:19 UTC (rev 52510)
@@ -14,5 +14,7 @@
 from unit_tests import *
 from aggregation import *
 from extract import *
+from stds_export import *
+from stds_import import *
 from mapcalc import *
 from univar_statistics import *

Modified: grass/trunk/lib/python/temporal/aggregation.py
===================================================================
--- grass/trunk/lib/python/temporal/aggregation.py	2012-08-02 23:26:50 UTC (rev 52509)
+++ grass/trunk/lib/python/temporal/aggregation.py	2012-08-03 01:00:19 UTC (rev 52510)
@@ -42,6 +42,8 @@
     use_overlap = False
     use_contain = False
     use_equal = False
+    use_follows = False
+    use_precedes = False
 
     # Initialize the methods
     if sampling:
@@ -56,6 +58,11 @@
                 use_contain = True
             if name == "equal":
                 use_equal = True
+            if name == "follows":
+                use_follows = True
+            if name == "precedes":
+                use_precedes = True
+
     else:
         use_start = True
 
@@ -65,8 +72,10 @@
         use_overlap = False
         use_contain = False
         use_equal = False
+        use_follows = False
+        use_precedes = False
 
-    where = create_temporal_relation_sql_where_statement(start, end, use_start, use_during, use_overlap, use_contain, use_equal)
+    where = create_temporal_relation_sql_where_statement(start, end, use_start, use_during, use_overlap, use_contain, use_equal, use_follows, use_precedes)
    
     rows = sp.get_registered_maps("id", where, "start_time", dbif)
 

Modified: grass/trunk/lib/python/temporal/space_time_datasets_tools.py
===================================================================
--- grass/trunk/lib/python/temporal/space_time_datasets_tools.py	2012-08-02 23:26:50 UTC (rev 52509)
+++ grass/trunk/lib/python/temporal/space_time_datasets_tools.py	2012-08-03 01:00:19 UTC (rev 52510)
@@ -76,11 +76,11 @@
 	else:
 	    id = name
 
-	if type == "rast":
+	if type == "rast" or type == "raster":
 	    sp = dataset_factory("strds", id)
 	elif type == "rast3d":
 	    sp = dataset_factory("str3ds", id)
-	elif type == "vect":
+	elif type == "vect" or type == "vector":
 	    sp = dataset_factory("stvds", id)
 	else:
 	    core.fatal(_("Unkown map type: %s")%(type))
@@ -333,7 +333,7 @@
 def dataset_factory(type, id):
     """!A factory functions to create space time or map datasets
     
-       @param type: the dataset type: rast, rast3d, vect, strds, str3ds, stvds
+       @param type: the dataset type: rast or raster, rast3d, vect or vector, strds, str3ds, stvds
        @param id: The id of the dataset ("name at mapset")
     """
     if type == "strds":
@@ -342,11 +342,11 @@
         sp = space_time_raster3d_dataset(id)
     elif type == "stvds":
         sp = space_time_vector_dataset(id)
-    elif type == "rast":
+    elif type == "rast" or type == "raster":
         sp = raster_dataset(id)
     elif type == "rast3d":
         sp = raster3d_dataset(id)
-    elif type == "vect":
+    elif type == "vect" or  type == "vector":
         sp = vector_dataset(id)
     else:
         core.error(_("Unknown dataset type: %s") % type)

Added: grass/trunk/lib/python/temporal/stds_export.py
===================================================================
--- grass/trunk/lib/python/temporal/stds_export.py	                        (rev 0)
+++ grass/trunk/lib/python/temporal/stds_export.py	2012-08-03 01:00:19 UTC (rev 52510)
@@ -0,0 +1,347 @@
+"""!@package grass.temporal
+
+ at brief GRASS Python scripting module (temporal GIS functions)
+
+Temporal GIS export functions to be used in temporal modules
+
+Usage:
+
+ at code
+import grass.temporal as tgis
+
+input="temp_1950_2012 at PERMANENT"
+output="/tmp/temp_1950_2012.tar.gz"
+compression="gzip"
+workdir="/tmp"
+where=None
+_format="GTiff"
+_type="strds"
+tgis.export_stds(input, output, compression, workdir, where, _format, _type)
+...
+ at endcode
+
+(C) 2008-2011 by the GRASS Development Team
+This program is free software under the GNU General Public
+License (>=v2). Read the file COPYING that comes with GRASS
+for details.
+
+ at author Soeren Gebbert
+"""
+
+import shutil
+import os
+import tarfile
+import tempfile
+from space_time_datasets_tools import *
+
+proj_file_name = "proj.txt"
+init_file_name = "init.txt"
+metadata_file_name = "metadata.txt"
+read_file_name = "readme.txt"
+list_file_name = "list.txt"
+tmp_tar_file_name = "archive" 
+
+# This global variable is for unique vector map export,
+# since single vector maps may have several layer
+# and therefore several attribute tables
+exported_maps = {}
+
+############################################################################
+def _export_raster_maps_as_geotiff(rows, tar, list_file, new_cwd, fs):
+    for row in rows:
+        name = row["name"]
+        start = row["start_time"]
+        end = row["end_time"]
+        max_val = row["max"]
+        min_val = row["min"]
+        datatype = row["datatype"]
+        if not end:
+            end = start
+        string = "%s%s%s%s%s\n" % (name, fs, start, fs, end)
+        # Write the filename, the start_time and the end_time
+        list_file.write(string) 
+        # Export the raster map with r.out.gdal as tif
+        out_name = name + ".tif"
+        if datatype == "CELL":
+            nodata = max_val + 1
+            if nodata < 256 and min_val >= 0:
+                gdal_type = "Byte" 
+            elif nodata < 65536 and min_val >= 0:
+                gdal_type = "UInt16" 
+            elif min_val >= 0:
+                gdal_type = "UInt32" 
+            else:
+                gdal_type = "Int32" 
+            ret = core.run_command("r.out.gdal", flags="c", input=name, output=out_name, nodata=nodata, type=gdal_type, format="GTiff")
+        else:
+            ret = core.run_command("r.out.gdal", flags="c", input=name, output=out_name, format="GTiff")
+        if ret != 0:
+            shutil.rmtree(new_cwd)
+            tar.close()
+            core.fatal(_("Unable to export raster map <%s>" % name))
+            
+        tar.add(out_name)
+
+        # Export the color rules 
+        out_name = name + ".color"
+        ret = core.run_command("r.colors.out", map=name, rules=out_name)
+        if ret != 0:
+            shutil.rmtree(new_cwd)
+            tar.close()
+            core.fatal(_("Unable to export color rules for raster map <%s> r.out.gdal" % name))
+            
+        tar.add(out_name)
+
+############################################################################
+def _export_raster_maps(rows, tar, list_file, new_cwd, fs):
+    for row in rows:
+        name = row["name"]
+        start = row["start_time"]
+        end = row["end_time"]
+        if not end:
+            end = start
+        string = "%s%s%s%s%s\n" % (name, fs, start, fs, end)
+        # Write the filename, the start_time and the end_time
+        list_file.write(string) 
+        # Export the raster map with r.pack
+        ret = core.run_command("r.pack", input=name, flags="c")
+        if ret != 0:
+            shutil.rmtree(new_cwd)
+            tar.close()
+            core.fatal(_("Unable to export raster map <%s> with r.pack" % name))
+            
+        tar.add(name + ".pack")
+        
+############################################################################
+def _export_vector_maps_as_gml(rows, tar, list_file, new_cwd, fs):
+    for row in rows:
+        name = row["name"]
+        start = row["start_time"]
+        end = row["end_time"]
+        layer = row["layer"]
+        if not layer:
+            layer = 1
+        if not end:
+            end = start
+        string = "%s%s%s%s%s\n" % (name, fs, start, fs, end)
+        # Write the filename, the start_time and the end_time
+        list_file.write(string) 
+        # Export the vector map with v.out.ogr
+        ret = core.run_command("v.out.ogr", input=name, dsn=(name + ".xml"), layer=layer, format="GML")
+        if ret != 0:
+            shutil.rmtree(new_cwd)
+            tar.close()
+            core.fatal(_("Unable to export vector map <%s> as GML with v.out.ogr" % name))
+            
+        tar.add(name + ".xml")
+        tar.add(name + ".xsd")
+                
+############################################################################
+def _export_vector_maps(rows, tar, list_file, new_cwd, fs):
+    for row in rows:
+        name = row["name"]
+        start = row["start_time"]
+        end = row["end_time"]
+        layer = row["layer"]
+        
+        # Export unique maps only
+        if name in exported_maps:
+            continue
+        
+        if not layer:
+            layer = 1
+        if not end:
+            end = start
+        string = "%s:%s%s%s%s%s\n" % (name, layer, fs, start, fs, end)
+        # Write the filename, the start_time and the end_time
+        list_file.write(string)
+        # Export the vector map with v.pack
+        ret = core.run_command("v.pack", input=name, flags="c")
+        if ret != 0:
+            shutil.rmtree(new_cwd)
+            tar.close()
+            core.fatal(_("Unable to export vector map <%s> with v.pack" % name))
+            
+        tar.add(name + ".pack")
+        
+        exported_maps[name] = name
+        
+############################################################################
+def _export_raster3d_maps(rows, tar, list_file, new_cwd, fs):
+    for row in rows:
+        name = row["name"]
+        start = row["start_time"]
+        end = row["end_time"]
+        if not end:
+            end = start
+        string = "%s%s%s%s%s\n" % (name, fs, start, fs, end)
+        # Write the filename, the start_time and the end_time
+        list_file.write(string) 
+        # Export the raster map with r3.pack
+        ret = core.run_command("r3.pack", input=name, flags="c")
+        if ret != 0:
+            shutil.rmtree(new_cwd)
+            tar.close()
+            core.fatal(_("Unable to export raster map <%s> with r3.pack" % name))
+            
+        tar.add(name + ".pack")
+
+############################################################################
+def export_stds(input, output, compression, workdir, where, _format="pack", _type="strds"):
+	"""
+		!Export space time datasets as tar archive with optional compression
+		
+		This method should be used to export space time datasets of type raster and vector
+		as tar archive that can be reimported with the method import_stds().
+		
+		@param input The name of the space time dataset to export
+		@param output The name of the archive file
+		@param compression The compression of the archive file: 
+		  * "no"  no compression
+		  * "gzip" GNU zip compression
+		  * "bzip2" Bzip compression
+		@param workdir The working directory used for extraction and packing
+		@param where The temporal WHERE SQL statement to select a subset of maps from the space time dataset
+		@param _format The export format:
+		  * "GTiff" Geotiff format, only for raster maps
+		  * "pack" The GRASS raster, 3D raster or vector Pack format, this is the default setting
+		  * "GML" GML file export format, only for vector maps, v.out.ogr export option
+		@param type The space time dataset type
+		  * "strds" Space time raster dataset
+		  * "str3ds" Space time 3D raster dataset
+		  * "stvds" Space time vector dataset
+	"""
+	mapset =  core.gisenv()["MAPSET"]
+
+	if input.find("@") >= 0:
+		id = input
+	else:
+		id = input + "@" + mapset
+		
+	sp = dataset_factory(_type, id)
+
+	if sp.is_in_db() == False:
+		core.fatal(_("Space time %s dataset <%s> not found") % (sp.get_new_map_instance(None).get_type(), id))
+
+	# Save current working directory path
+	old_cwd = os.getcwd()
+
+	# Create the temporary directory and jump into it
+	new_cwd = tempfile.mkdtemp(dir=workdir)
+	os.chdir(new_cwd)
+
+	sp.select()
+	   
+	if _type == "strds":
+		columns = "name,start_time,end_time,min,max,datatype"
+	elif _type == "stvds":
+		columns = "name,start_time,end_time,layer"
+	else:
+		columns = "name,start_time,end_time"
+	rows = sp.get_registered_maps(columns, where, "start_time", None)
+
+	if compression == "gzip":
+		flag = "w:gz"
+	elif compression == "bzip2":
+		flag = "w:bz2"
+	else:
+		flag = "w:"
+
+	# Open the tar archive to add the files
+	tar = tarfile.open(tmp_tar_file_name, flag)
+	list_file = open(list_file_name, "w")
+
+	fs = "|"
+
+	if rows:
+		if _type == "strds":
+			if _format == "GTiff":
+				_export_raster_maps_as_geotiff(rows, tar, list_file, new_cwd, fs)
+			else:
+				_export_raster_maps(rows, tar, list_file, new_cwd, fs)
+		elif _type == "stvds":
+			if _format == "GML":
+				_export_vector_maps_as_gml(rows, tar, list_file, new_cwd, fs)
+			else:
+				_export_vector_maps(rows, tar, list_file, new_cwd, fs)
+		elif _type == "str3ds":
+			_export_raster3d_maps(rows, tar, list_file, new_cwd, fs)
+		
+	list_file.close()
+
+	# Write projection and metadata
+	proj = core.read_command("g.proj", flags="j")
+
+	proj_file = open(proj_file_name, "w")
+	proj_file.write(proj)
+	proj_file.close()
+
+	init_file = open(init_file_name, "w")
+	# Create the init string
+	string = ""
+	string += "%s=%s\n" % ("stds_type", sp.get_type()) # This is optional, if not present strds will be assumed for backward compatibility
+	string += "%s=%s\n" % ("format", _format) # This is optional, if not present gtiff will be assumed for backward compatibility
+	string += "%s=%s\n" % ("temporal_type", sp.get_temporal_type())
+	string += "%s=%s\n" % ("semantic_type", sp.get_semantic_type())
+	string += "%s=%s\n" % ("number_of_maps", sp.metadata.get_number_of_maps())
+	north, south, east, west, top, bottom = sp.get_spatial_extent()
+	string += "%s=%s\n" % ("north", north)
+	string += "%s=%s\n" % ("south", south)
+	string += "%s=%s\n" % ("east", east)
+	string += "%s=%s\n" % ("west", west)
+	init_file.write(string)
+	init_file.close()
+
+	metadata = core.read_command("t.info", type=_type, input=id)
+	metadata_file = open(metadata_file_name, "w")
+	metadata_file.write(metadata)
+	metadata_file.close()
+
+	read_file = open(read_file_name, "w")
+	if _type == "strds":
+		read_file.write("This space time raster dataset was exported with t.rast.export of GRASS GIS 7\n")
+	elif _type == "stvds":
+		read_file.write("This space time vector dataset was exported with t.vect.export of GRASS GIS 7\n")
+	elif _type == "str3ds":
+		read_file.write("This space time 3D raster dataset was exported with t.rast3d.export of GRASS GIS 7\n")
+	read_file.write("\n")
+	read_file.write("Files:\n")
+	if _type == "strds":
+		if _format == "GTiff":
+					#123456789012345678901234567890
+			read_file.write("       *.tif  -- GeoTIFF raster files\n")
+			read_file.write("     *.color  -- GRASS GIS raster color rules\n")
+		elif _format == "pack":
+			read_file.write("      *.pack  -- GRASS raster files packed with r.pack\n")
+	elif _type == "stvds":
+					#123456789012345678901234567890
+		if _format == "GML":
+			read_file.write("       *.xml  -- Vector GML files\n")
+		else:
+			read_file.write("      *.pack  -- GRASS vector files packed with v.pack\n")
+	elif _type == "str3ds":
+		read_file.write("      *.pack  -- GRASS 3D raster files packed with r3.pack\n")
+	read_file.write("%13s -- Projection information in PROJ.4 format\n" % (proj_file_name))
+	read_file.write("%13s -- GRASS GIS space time %s dataset information\n" % (init_file_name, sp.get_new_map_instance(None).get_type()))
+	read_file.write("%13s -- Time series file, lists all maps by name with interval\n"  % (list_file_name))
+	read_file.write("                 time stamps in ISO-Format. Field separator is |\n")
+	read_file.write("%13s -- Projection information in PROJ.4 format\n" % (metadata_file_name))
+	read_file.write("%13s -- This file\n" % (read_file_name))
+	read_file.close()
+
+	# Append the file list
+	tar.add(list_file_name)
+	tar.add(proj_file_name)
+	tar.add(init_file_name)
+	tar.add(read_file_name)
+	tar.add(metadata_file_name)
+	tar.close()
+
+	os.chdir(old_cwd)
+
+	# Move the archive to its destination
+	shutil.move(os.path.join(new_cwd, tmp_tar_file_name), output)
+
+	# Remove the temporary created working directory
+	shutil.rmtree(new_cwd)
+

Added: grass/trunk/lib/python/temporal/stds_import.py
===================================================================
--- grass/trunk/lib/python/temporal/stds_import.py	                        (rev 0)
+++ grass/trunk/lib/python/temporal/stds_import.py	2012-08-03 01:00:19 UTC (rev 52510)
@@ -0,0 +1,366 @@
+"""!@package grass.temporal
+
+ at brief GRASS Python scripting module (temporal GIS functions)
+
+Temporal GIS export functions to be used in temporal modules
+
+Usage:
+
+ at code
+import grass.temporal as tgis
+
+input="/tmp/temp_1950_2012.tar.gz"
+output="temp_1950_2012"
+extrdir="/tmp"
+title="My new dataset"
+descr="May new shiny dataset"
+location=None
+link=True
+exp=True
+overr=False
+create=False
+tgis.import_stds(input, output, extrdir, title, descr, location, 
+                link, exp, overr, create, "strds")
+...
+ at endcode
+
+(C) 2008-2011 by the GRASS Development Team
+This program is free software under the GNU General Public
+License (>=v2). Read the file COPYING that comes with GRASS
+for details.
+
+ at author Soeren Gebbert
+"""
+
+import shutil
+import os
+import os.path
+import tarfile
+import tempfile
+import time
+import filecmp
+from space_time_datasets_tools import *
+
+proj_file_name = "proj.txt"
+init_file_name = "init.txt"
+list_file_name = "list.txt"
+
+# This global variable is for unique vector map export,
+# since single vector maps may have several layer
+# and therefore several attribute tables
+imported_maps = {}
+
+############################################################################
+def _import_raster_maps_from_geotiff(maplist, overr, exp, location, link):
+	impflags = ""
+	if overr:
+		impflags += "o"
+	if exp or location:
+		impflags += "e"
+	for row in maplist:
+		name = row["name"]
+		filename = str(row["name"]) + ".tif"
+
+		if link:
+			ret = core.run_command("r.external", input = filename,
+						output = name,
+						flags = impflags,
+						overwrite = core.overwrite())
+		else:
+			ret = core.run_command("r.in.gdal", input = filename,
+						output = name,
+						flags = impflags,
+						overwrite = core.overwrite())
+
+		if ret != 0:
+			core.fatal(_("Unable to import/link raster map <%s>.") % name)
+
+		# Set the color rules if present
+		filename = str(row["name"]) + ".color"
+		if os.path.isfile(filename):
+			ret = core.run_command("r.colors", map = name,
+						rules = filename,
+						overwrite = core.overwrite())
+			if ret != 0:
+				core.fatal(_("Unable to set the color rules for raster map <%s>.") % name)
+                                                        
+############################################################################
+def _import_raster_maps(maplist):
+	# We need to disable the projection check because of its simple implementation
+	impflags = "o"
+	for row in maplist:
+		name = row["name"]
+		filename = str(row["name"]) + ".pack"
+		ret = core.run_command("r.unpack", input = filename,
+						output = name,
+						flags = impflags,
+						overwrite = core.overwrite(),
+						verbose = True)
+
+		if ret != 0:
+			core.fatal(_("Unable to unpack raster map <%s>.") % name)
+
+############################################################################
+def _import_vector_maps_from_gml(maplist, overr, exp, location, link):
+        impflags = "o"
+        if exp or location:
+                impflags += "e"
+        for row in maplist:
+                name = row["name"]
+                filename = str(row["name"]) + ".xml"
+
+                ret = core.run_command("v.in.ogr", dsn = filename,
+                                        output = name,
+                                        flags = impflags,
+                                        overwrite = core.overwrite())
+
+                if ret != 0:
+                        core.fatal(_("Unable to import vector map <%s>.") % name)
+                        
+############################################################################
+def _import_vector_maps(maplist):
+        # We need to disable the projection check because of its simple implementation
+        impflags = "o"
+        for row in maplist:
+        	# Separate the name from the layer
+                name = row["name"].split(":")[0]
+                # Import only unique maps
+                if name in imported_maps:
+                    continue
+                filename = name + ".pack"
+                ret = core.run_command("v.unpack", input = filename,
+                                                output = name,
+                                                flags = impflags,
+                                                overwrite = core.overwrite(),
+                                                verbose = True)
+
+                if ret != 0:
+                        core.fatal(_("Unable to unpack vector map <%s>.") % name)
+                
+                imported_maps[name] = name
+############################################################################
+
+def import_stds(input, output, extrdir, title = None, descr = None, location = None,
+                link = False, exp = False, overr = False, create = False, stds_type = "strds"):
+	"""
+		!Import space time datasets of type raster and vector
+		
+		@param input Name of the input archive file
+		@param output The name of the output space time dataset
+		@param extrdir The extraction directory
+		@param title The title of the new created space time dataset
+		@param description The description of the new created space time dataset
+		@param location The name of the location that should be created, 
+		                maps are imported into this location
+		@param link Switch to link raster maps instead importing them
+		@param exp Extend location extents based on new dataset
+		@param overr Override projection (use location's projection)
+		@param create Create the location specified by the "location" parameter and exit. 
+		              Do not import the space time datasets.
+		@param stds_type The type of the space time dataset that should be imported
+	"""
+
+	core.set_raise_on_error(True)
+
+	# Check if input file and extraction directory exits
+	if not os.path.exists(input):
+		core.fatal(_("Space time raster dataset archive <%s> not found") % input)
+	if not create and not os.path.exists(extrdir):
+		core.fatal(_("Extraction directory <%s> not found") % extrdir)
+
+	tar = tarfile.open(name = input, mode = 'r')
+
+	# Check for important files
+	members = tar.getnames()
+
+	if init_file_name not in members:
+		core.fatal(_("Unable to find init file <%s>") % init_file_name)
+	if list_file_name not in members:
+		core.fatal(_("Unable to find list file <%s>") % list_file_name)
+	if proj_file_name not in members:
+		core.fatal(_("Unable to find projection file <%s>") % proj_file_name)
+
+	tar.extractall(path = extrdir)
+	tar.close()
+
+	# Save current working directory path
+	old_cwd = os.getcwd()
+
+	# Switch into the data directory
+	os.chdir(extrdir)
+
+	# Check projection information
+	if not location:
+		temp_name = core.tempfile()
+		temp_file = open(temp_name, "w")
+
+		p = core.start_command("g.proj", flags = "j", stdout = temp_file)
+		p.communicate()
+		temp_file.close()
+
+		if not core.compare_key_value_text_files(temp_name, proj_file_name, sep="="):
+			if overr:
+				core.warning(_("Projection information does not match. Proceeding..."))
+			else:
+				core.fatal(_("Projection information does not match. Aborting."))
+
+	# Create a new location based on the projection information and switch into it
+	old_env = core.gisenv()
+	if location:
+		try:
+			proj4_string = open(proj_file_name, 'r').read()
+			core.create_location(dbase = old_env["GISDBASE"],
+								  location = location,
+								  proj4 = proj4_string)
+			# Just create a new location and return
+			if create:
+				os.chdir(old_cwd)
+				return
+		except Exception as e:
+				core.fatal(_("Unable to create location %s. Reason: %s") % (location, str(e)))
+		# Switch to the new created location
+		ret = core.run_command("g.mapset", mapset = "PERMANENT",
+					location = location,
+					gisdbase = old_env["GISDBASE"])
+		if ret != 0:
+			core.fatal(_("Unable to switch to location %s") % location)
+		# create default database connection
+		ret = core.run_command("t.connect", flags = "d")
+		if ret != 0:
+			core.fatal(_("Unable to create default temporal database in new location %s") % location)
+
+	try:
+		# Make sure the temporal database exists
+		create_temporal_database()
+
+		fs = "|"
+		maplist = []
+		mapset = core.gisenv()["MAPSET"]
+		list_file = open(list_file_name, "r")
+
+		# Read the map list from file
+		line_count = 0
+		while True:
+			line = list_file.readline()
+			if not line:
+				break
+
+			line_list = line.split(fs)
+
+			mapname = line_list[0].strip()
+			mapid = mapname + "@" + mapset
+
+			row = {}
+			row["name"] = mapname
+			row["id"] = mapid
+			row["start"] = line_list[1].strip()
+			row["end"] = line_list[2].strip()
+
+			maplist.append(row)
+			line_count += 1
+
+		list_file.close()
+
+		# Read the init file
+		fs = "="
+		init = {}
+		init_file = open(init_file_name, "r")
+		while True:
+			line = init_file.readline()
+			if not line:
+				break
+
+			kv = line.split(fs)
+			init[kv[0]] = kv[1].strip()
+
+		init_file.close()
+
+		if not init.has_key("temporal_type") or \
+		   not init.has_key("semantic_type") or \
+		   not init.has_key("number_of_maps"):
+			core.fatal(_("Key words %s, %s or %s not found in init file.") %
+			("temporal_type", "semantic_type", "number_of_maps"))
+
+		if line_count != int(init["number_of_maps"]):
+			core.fatal(_("Number of maps mismatch in init and list file."))
+
+		_format = "GTiff"
+		_type = "strds"
+
+		if init.has_key("stds_type"):
+			_type = init["stds_type"]
+		if init.has_key("format"):
+			_format = init["format"]
+
+		if stds_type != _type:
+			core.fatal(_("The archive file is of wrong space time dataset type"))
+
+		# Check the existence of the files 
+		if _format == "GTiff":
+			for row in maplist:
+				filename = str(row["name"]) + ".tif"
+				if not os.path.exists(filename):
+					core.fatal(_("Unable to find geotiff raster file <%s> in archive.") % filename)
+		elif _format == "GML":
+			for row in maplist:
+				filename = str(row["name"]) + ".xml"
+				if not os.path.exists(filename):
+					core.fatal(_("Unable to find GML vector file <%s> in archive.") % filename)
+		elif _format == "pack":
+			for row in maplist:
+				if _type == "stvds":
+					filename = str(row["name"].split(":")[0]) + ".pack"
+				else:
+					filename = str(row["name"]) + ".pack"
+				if not os.path.exists(filename):
+					core.fatal(_("Unable to find GRASS package file <%s> in archive.") % filename)
+		else:
+			core.fatal(_("Unsupported input format"))
+
+		# Check the space time dataset
+		id = output + "@" + mapset
+		sp = dataset_factory(_type, id)
+		if sp.is_in_db() and core.overwrite() == False:
+			core.fatal(_("Space time %s dataset <%s> is already in the database. Use the overwrite flag.") % (_type, sp.get_id()))
+
+		# Import the maps
+		if _type == "strds":
+			if _format == "GTiff":
+				_import_raster_maps_from_geotiff(maplist, overr, exp, location, link)
+			if _format == "pack":
+				_import_raster_maps(maplist)
+                elif _type == "stvds":
+                        if _format == "GML":
+                                _import_vector_maps_from_gml(maplist, overr, exp, location, link)
+                        if _format == "pack":
+                                _import_vector_maps(maplist)
+
+		# Create the space time dataset
+		if sp.is_in_db() and core.overwrite() == True:
+			core.info(_("Overwrite space time %s dataset <%s> and unregister all maps.") % (sp.get_new_map_instance(None).get_type(), sp.get_id()))
+			sp.delete()
+			sp = sp.get_new_instance(id)
+
+		temporal_type = init["temporal_type"]
+		semantic_type = init["semantic_type"]
+		core.verbose(_("Create space time %s dataset.") % sp.get_new_map_instance(None).get_type())
+
+		sp.set_initial_values(temporal_type = temporal_type, semantic_type = semantic_type, title = title, description = descr)
+		sp.insert()
+
+		# register the maps
+		fs = "|"
+		register_maps_in_space_time_dataset(type = sp.get_new_map_instance(None).get_type(),
+					 name = output, file = list_file_name, start = "file", end = "file", dbif = None, fs = fs)
+
+		os.chdir(old_cwd)
+	except:
+		raise
+
+	# Make sure the location is switched back correctly
+	finally:
+		if location:
+			# Switch to the old location
+			ret = core.run_command("g.mapset", mapset = old_env["MAPSET"],
+						location = old_env["LOCATION_NAME"],
+						gisdbase = old_env["GISDBASE"])

Modified: grass/trunk/temporal/t.rast.export/t.rast.export.py
===================================================================
--- grass/trunk/temporal/t.rast.export/t.rast.export.py	2012-08-02 23:26:50 UTC (rev 52509)
+++ grass/trunk/temporal/t.rast.export/t.rast.export.py	2012-08-03 01:00:19 UTC (rev 52510)
@@ -34,7 +34,6 @@
 #% answer: /tmp
 #%end
 
-
 #%option
 #% key: compression
 #% type: string
@@ -45,182 +44,40 @@
 #% answer: bzip2
 #%end
 
+#%option
+#% key: format
+#% type: string
+#% description: The export format of a single raster map. Supported are GeoTIFF via r.out.gdal and the GRASS package format of r.pack.
+#% required: no
+#% multiple: no
+#% options: GTiff,pack
+#% answer: GTiff
+#%end
+
 #%option G_OPT_T_WHERE
 #%end
 
-import shutil
-import os
-import tarfile
-import tempfile
 import grass.script as grass
 import grass.temporal as tgis
 
-proj_file_name = "proj.txt"
-init_file_name = "init.txt"
-metadata_file_name = "metadata.txt"
-read_file_name = "readme.txt"
-list_file_name = "list.txt"
-tmp_tar_file_name = "archive" 
-
+    
 ############################################################################
-
 def main():
 
-    # Get the options
-    input = options["input"]
-    output = options["output"]
-    compression = options["compression"]
-    workdir = options["workdir"]
-    where = options["where"]
+	# Get the options
+	_input = options["input"]
+	output = options["output"]
+	compression = options["compression"]
+	workdir = options["workdir"]
+	where = options["where"]
+	_format = options["format"]
 
-    # Make sure the temporal database exists
-    tgis.create_temporal_database()
-
-    mapset =  grass.gisenv()["MAPSET"]
-
-    if input.find("@") >= 0:
-        id = input
-    else:
-        id = input + "@" + mapset
-
-    sp = tgis.space_time_raster_dataset(id)
-    
-    if sp.is_in_db() == False:
-        grass.fatal(_("Space time %s dataset <%s> not found") % (sp.get_new_map_instance(None).get_type(), id))
-
-    # Save current working directory path
-    old_cwd = os.getcwd()
-
-    # Create the temporary directory and jump into it
-    new_cwd = tempfile.mkdtemp(dir=workdir)
-    os.chdir(new_cwd)
-
-    sp.select()
-       
-    columns = "name,start_time,end_time,min,max,datatype"
-    rows = sp.get_registered_maps(columns, where, "start_time", None)
-
-    if compression == "gzip":
-        flag = "w:gz"
-    elif compression == "bzip2":
-        flag = "w:bz2"
-    else:
-        flag = "w"
-
-    # Open the tar archive to add the files
-    tar = tarfile.open(tmp_tar_file_name, flag)
-    list_file = open(list_file_name, "w")
-
-    fs = "|"
-
-    if rows:
-        for row in rows:
-            name = row["name"]
-            start = row["start_time"]
-            end = row["end_time"]
-            max_val = row["max"]
-            min_val = row["min"]
-            datatype = row["datatype"]
-            if not end:
-                end = start
-            string = "%s%s%s%s%s\n" % (name, fs, start, fs, end)
-            # Write the filename, the start_time and the end_time
-            list_file.write(string)
-
-	    # Export the raster map with r.out.gdal as tif
-            out_name = name + ".tif"
-            if datatype == "CELL":
-                nodata = max_val + 1
-                if nodata < 256 and min_val >= 0:
-                    gdal_type = "Byte" 
-                elif nodata < 65536 and min_val >= 0:
-                    gdal_type = "UInt16" 
-                elif min_val >= 0:
-                    gdal_type = "UInt32" 
-                else:
-                    gdal_type = "Int32" 
-                ret = grass.run_command("r.out.gdal", flags="c", input=name, output=out_name, nodata=nodata, type=gdal_type, format="GTiff")
-            else:
-                ret = grass.run_command("r.out.gdal", flags="c", input=name, output=out_name, format="GTiff")
-            if ret != 0:
-                shutil.rmtree(new_cwd)
-                tar.close()
-                grass.fatal(_("Unable to export raster map <%s>" % name))
-                
-            tar.add(out_name)
-
-	    # Export the color rules 
-            out_name = name + ".color"
-            ret = grass.run_command("r.colors.out", map=name, rules=out_name)
-            if ret != 0:
-                shutil.rmtree(new_cwd)
-                tar.close()
-                grass.fatal(_("Unable to export color rules for raster map <%s>" % name))
-                
-            tar.add(out_name)
-
-    list_file.close()
-   
-    # Write projection and metadata
-    proj = grass.read_command("g.proj", flags="j")
-
-    proj_file = open(proj_file_name, "w")
-    proj_file.write(proj)
-    proj_file.close()
-
-    init_file = open(init_file_name, "w")
-    # Create the init string
-    string = ""
-    string += "%s=%s\n" % ("temporal_type", sp.get_temporal_type())
-    string += "%s=%s\n" % ("semantic_type", sp.get_semantic_type())
-    string += "%s=%s\n" % ("number_of_maps", sp.metadata.get_number_of_maps())
-    north, south, east, west, top, bottom = sp.get_spatial_extent()
-    string += "%s=%s\n" % ("north", north)
-    string += "%s=%s\n" % ("south", south)
-    string += "%s=%s\n" % ("east", east)
-    string += "%s=%s\n" % ("west", west)
-    init_file.write(string)
-    init_file.close()
-
-    metadata = grass.read_command("t.info", input=id)
-    metadata_file = open(metadata_file_name, "w")
-    metadata_file.write(metadata)
-    metadata_file.close()
-    
-    read_file = open(read_file_name, "w")
-    read_file.write("This space time raster dataset was exported with t.rast.export of GRASS GIS 7\n")
-    read_file.write("\n")
-    read_file.write("Files:\n")
-                    #123456789012345678901234567890
-    read_file.write("       *.tif  -- GeoTIFF time series raster files\n")
-    read_file.write("     *.color  -- GRASS GIS raster color rules\n")
-    read_file.write("%13s -- Projection information in PROJ.4 format\n" % (proj_file_name))
-    read_file.write("%13s -- GRASS GIS space time raster dataset information\n" % (init_file_name))
-    read_file.write("%13s -- Time series file, lists all maps by name with interval\n"  % (list_file_name))
-    read_file.write("                 time stamps in ISO-Format. Field separator is |\n")
-    read_file.write("%13s -- Projection information in PROJ.4 format\n" % (metadata_file_name))
-    read_file.write("%13s -- This file\n" % (read_file_name))
-    read_file.close()
-
-    # Append the file list
-    tar.add(list_file_name)
-    tar.add(proj_file_name)
-    tar.add(init_file_name)
-    tar.add(read_file_name)
-    tar.add(metadata_file_name)
-    tar.close()
-
-    os.chdir(old_cwd)
-
-    # Move the archive to its destination
-    if output.find("/") >= 0 or output.find("\\") >= 0:
-        shutil.move(tmp_tar_file_name, output)
-    else:
-        shutil.move(os.path.join(new_cwd, tmp_tar_file_name), output)
-
-    # Remove the temporary created working directory
-    shutil.rmtree(new_cwd)
-
+	# Make sure the temporal database exists
+	tgis.create_temporal_database()
+	# Export the space time raster dataset
+	tgis.export_stds(_input, output, compression, workdir, where, _format, "strds")
+     
+############################################################################
 if __name__ == "__main__":
     options, flags = grass.parser()
     main()

Modified: grass/trunk/temporal/t.rast.export/test.t.rast.export.sh
===================================================================
--- grass/trunk/temporal/t.rast.export/test.t.rast.export.sh	2012-08-02 23:26:50 UTC (rev 52509)
+++ grass/trunk/temporal/t.rast.export/test.t.rast.export.sh	2012-08-03 01:00:19 UTC (rev 52510)
@@ -28,8 +28,19 @@
 
 # The first @test
 t.register -i type=rast input=precip_abs1 file="${n1}" start="2001-01-01" increment="1 months"
-t.rast.export input=precip_abs1 output=strds_export.tar.bz2 compression=bzip2 workdir=/tmp
+t.rast.export format=GTiff input=precip_abs1 output=strds_export_gtiff.tar.bz2 compression=bzip2 workdir=/tmp
+t.rast.export format=GTiff input=precip_abs1 output=strds_export_gtiff.tar.gz compression=gzip workdir=/tmp
+t.rast.export format=GTiff input=precip_abs1 output=strds_export_gtiff.tar compression=no workdir=/tmp
 
+t.rast.export format=pack input=precip_abs1 output=strds_export_pack.tar.bz2 compression=bzip2 workdir=/tmp
+t.rast.export format=pack input=precip_abs1 output=strds_export_pack.tar.gz compression=gzip workdir=/tmp
+t.rast.export format=pack input=precip_abs1 output=strds_export_pack.tar compression=no workdir=/tmp
+
 t.unregister type=rast maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
 t.remove type=strds input=precip_abs1
-rm strds_export.tar.bz2
+rm strds_export_gtiff.tar.bz2
+rm strds_export_gtiff.tar.gz
+rm strds_export_gtiff.tar
+rm strds_export_pack.tar.bz2
+rm strds_export_pack.tar.gz
+rm strds_export_pack.tar

Modified: grass/trunk/temporal/t.rast.import/t.rast.import.py
===================================================================
--- grass/trunk/temporal/t.rast.import/t.rast.import.py	2012-08-02 23:26:50 UTC (rev 52509)
+++ grass/trunk/temporal/t.rast.import/t.rast.import.py	2012-08-03 01:00:19 UTC (rev 52510)
@@ -2,15 +2,15 @@
 # -*- coding: utf-8 -*-
 ############################################################################
 #
-# MODULE:	t.rast.import
-# AUTHOR(S):	Soeren Gebbert
+# MODULE:        t.rast.import
+# AUTHOR(S):     Soeren Gebbert
 #               
-# PURPOSE:	Import a space time raster dataset
-# COPYRIGHT:	(C) 2011 by the GRASS Development Team
+# PURPOSE:        Import a space time raster 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.
+#                This program is free software under the GNU General Public
+#                License (version 2). Read the file COPYING that comes with GRASS
+#                for details.
 #
 #############################################################################
 
@@ -50,7 +50,7 @@
 #%option
 #% key: location
 #% type: string
-#% description: Create a new location and import the data into it. No not run this module in parallel or interrupt it when a new location should be created.
+#% description: Create a new location and import the data into it. Please do not run this module in parallel or interrupt it when a new location should be created.
 #% required: no
 #% multiple: no
 #%end
@@ -75,224 +75,26 @@
 #% description: Create the location specified by the "location" parameter and exit. Do not import the space time raster datasets.
 #%end
 
-
-
-import shutil
-import os
-import os.path
-import tarfile
-import tempfile
 import grass.script as grass
 import grass.temporal as tgis
-import time
 
-proj_file_name = "proj.txt"
-init_file_name = "init.txt"
-list_file_name = "list.txt"
-
-############################################################################
-
 def main():
 
-    # Get the options
-    input = options["input"]
-    output = options["output"]
-    extrdir = options["extrdir"]
-    title = options["title"]
-    descr = options["description"]
-    location = options["location"]
-    link = flags["l"]
-    exp = flags["e"]
-    overr = flags["o"]
-    create = flags["c"]
-
-    grass.set_raise_on_error(True)
-    
-    # Check if input file and extraction directory exits
-    if not os.path.exists(input): 
-        grass.fatal(_("Space time raster dataset archive <%s> not found") % input)
-    if not os.path.exists(extrdir): 
-        grass.fatal(_("Extraction directory <%s> not found") % extrdir)
-
-    tar = tarfile.open(input)
-    
-    # Check for important files
-    members = tar.getnames()
-
-    if init_file_name not in members: 
-        grass.fatal(_("Unable to find init file <%s>") % init_file_name)
-    if list_file_name not in members: 
-        grass.fatal(_("Unable to find list file <%s>") % list_file_name)
-    if proj_file_name not in members: 
-        grass.fatal(_("Unable to find projection file <%s>") % proj_file_name)
-
-    tar.extractall(path=extrdir)
-    tar.close()
-    
-    # Save current working directory path
-    old_cwd = os.getcwd()
-
-    # Switch into the data directory
-    os.chdir(extrdir)
-    
-    # Create a new location based on the projection information and switch into it
-    old_env = grass.gisenv()
-    if location:
-	try:
-	    proj4_string = open(proj_file_name, 'r').read()
-	    grass.create_location(dbase=old_env["GISDBASE"], 
-	                          location=location, 
-	                          proj4=proj4_string)
-	    # Just create a new location and return
-	    if create:
-		os.chdir(old_cwd)
-		return 
-	except Exception as e:
-		grass.fatal(_("Unable to create location %s. Reason: %s") % (location, str(e)))
-	# Switch to the new created location
-	ret = grass.run_command("g.mapset", mapset="PERMANENT", 
-	                                    location=location, 
-	                                    gisdbase=old_env["GISDBASE"])
-	if ret != 0:                            
-	    grass.fatal(_("Unable to switch to location %s") % location)
-	# create default database connection
-	ret = grass.run_command("t.connect", flags="d")
-	if ret != 0:                            
-	    grass.fatal(_("Unable to create default temporal database in new location %s") % location)
-
-    try:
-	# Make sure the temporal database exists
-	tgis.create_temporal_database()
+	# Get the options
+	input = options["input"]
+	output = options["output"]
+	extrdir = options["extrdir"]
+	title = options["title"]
+	descr = options["description"]
+	location = options["location"]
+	link = flags["l"]
+	exp = flags["e"]
+	overr = flags["o"]
+	create = flags["c"]
 	
-	fs = "|"
-	maplist = []
-	mapset =  grass.gisenv()["MAPSET"]
-	list_file = open(list_file_name, "r")
+	tgis.import_stds(input, output, extrdir, title, descr, location, 
+                link, exp, overr, create, "strds")
 
-	# Read the map list from file
-	line_count = 0
-	while True:
-	    line = list_file.readline()
-	    if not line:
-		break
-
-	    line_list = line.split(fs)
-
-	    mapname = line_list[0].strip()
-	    mapid = mapname + "@" + mapset
-
-	    row = {}
-	    row["name"] = mapname
-	    row["id"] = mapid
-	    row["start"] = line_list[1].strip()
-	    row["end"] = line_list[2].strip()
-
-	    maplist.append(row)
-	    line_count += 1
-
-	list_file.close()
-	
-	# Check if geotiff files exists
-	for row in maplist:
-	    filename = str(row["name"]) + ".tif"
-	    if not os.path.exists(filename): 
-		grass.fatal(_("Unable to find geotiff raster file <%s> in archive.") % filename)
-
-	# Read the init file
-	fs = "="
-	init = {}
-	init_file = open(init_file_name, "r")
-	while True:
-	    line = init_file.readline()
-	    if not line:
-		break
-
-	    kv = line.split(fs)
-	    init[kv[0]] = kv[1].strip()
-	
-	init_file.close()
-
-	if not init.has_key("temporal_type") or \
-	not init.has_key("semantic_type") or \
-	not init.has_key("number_of_maps"):
-	    grass.fatal(_("Key words %s, %s or %s not found in init file.") % ("temporal_type", "semantic_type", "number_of_maps"))
-
-	if line_count != int(init["number_of_maps"]):
-	    grass.fatal(_("Number of maps mismatch in init and list file."))
-
-	# Check the space time dataset
-
-	id = output + "@" + mapset
-
-	sp = tgis.space_time_raster_dataset(id)
-	
-	if sp.is_in_db() and grass.overwrite() == False:
-	    grass.fatal(_("Space time %s dataset <%s> is already in the database. Use the overwrite flag.") % name)
-
-	# Try to import/link the raster files
-	for row in maplist:
-	    name = row["name"]
-	    filename = str(row["name"]) + ".tif"
-	    impflags=""
-	    if overr:
-		impflags += "o"
-	    if exp or location:
-		impflags += "e"
-	    
-	    if link:
-		ret = grass.run_command("r.external", input=filename, 
-		                                      output=name, 
-		                                      flags=impflags, 
-		                                      overwrite=grass.overwrite())
-	    else:
-		ret = grass.run_command("r.in.gdal", input=filename, 
-						     output=name, 
-						     flags=impflags, 
-						     overwrite=grass.overwrite())
-
-	    if ret != 0:
-		grass.fatal(_("Unable to import/link raster map <%s>.") % name)
-	
-	    # Set the color rules if present
-	    filename = str(row["name"]) + ".color"
-	    if os.path.isfile(filename):
-		ret = grass.run_command("r.colors", map=name, 
-						    rules=filename, 
-						    overwrite=grass.overwrite())
-
-		if ret != 0:
-		    grass.fatal(_("Unable to set the color rules for raster map <%s>.") % name)
-
-	# Create the space time raster dataset
-	if sp.is_in_db() and grass.overwrite() == True:
-	    grass.info(_("Overwrite space time %s dataset <%s> and unregister all maps.") % (sp.get_new_map_instance(None).get_type(), name))
-	    sp.delete()
-	    sp = sp.get_new_instance(id)
-
-	temporal_type = init["temporal_type"]
-	semantic_type = init["semantic_type"]
-	grass.verbose(_("Create space time %s dataset.") % sp.get_new_map_instance(None).get_type())
-
-	sp.set_initial_values(temporal_type=temporal_type, semantic_type=semantic_type, title=title, description=descr)
-	sp.insert()
-
-	# register the raster maps
-	fs="|"
-	tgis.register_maps_in_space_time_dataset(type="rast", name=output, file=list_file_name, start="file", end="file", dbif=None, fs=fs)
-
-	
-	os.chdir(old_cwd)
-    except:
-	raise
-    
-    # Make sure the location is switched back correctly
-    finally:
-	if location:
-	    # Switch to the old location
-	    ret = grass.run_command("g.mapset", mapset=old_env["MAPSET"], 
-						location=old_env["LOCATION_NAME"], 
-						gisdbase=old_env["GISDBASE"])
-    
 if __name__ == "__main__":
     options, flags = grass.parser()
     main()

Modified: grass/trunk/temporal/t.rast.import/test.t.rast.import.sh
===================================================================
--- grass/trunk/temporal/t.rast.import/test.t.rast.import.sh	2012-08-02 23:26:50 UTC (rev 52509)
+++ grass/trunk/temporal/t.rast.import/test.t.rast.import.sh	2012-08-03 01:00:19 UTC (rev 52510)
@@ -33,21 +33,15 @@
 
 # The first @test
 t.register -i type=rast input=precip_abs1 file="${n1}" start="2001-01-01" increment="1 months"
-t.rast.export input=precip_abs1 output=strds_export.tar.bz2 compression=bzip2 workdir=test
 
-# Import the data into a new location
-t.rast.import --o location=new_test_1 input=strds_export.tar.bz2 output=precip_abs1 extrdir=test\
-              title="A test" description="Description of a test"
-ls -la $GISDBASE/new_test_1/PERMANENT
+t.rast.export input=precip_abs1 output=strds_export.tar.bz2 compression=bzip2 format=GTiff workdir=test
+t.rast.export input=precip_abs1 output=strds_export.tar.gz compression=gzip format=GTiff workdir=test
+t.rast.export input=precip_abs1 output=strds_export.tar compression=no format=GTiff workdir=test
+t.rast.export input=precip_abs1 output=strds_export_pack.tar compression=no format=pack workdir=test
+t.rast.export input=precip_abs1 output=strds_export_pack.tar.gz compression=gzip format=pack workdir=test
+t.rast.export input=precip_abs1 output=strds_export_pack.tar.bz2 compression=bzip2 format=pack workdir=test
 
-t.rast.import --o location=new_test_2 input=strds_export.tar.bz2 output=precip_abs1 extrdir=test\
-          -l  title="A test" description="Description of a test"
-ls -la $GISDBASE/new_test_2/PERMANENT
-
-t.rast.import --o location=new_test_3 input=strds_export.tar.bz2 output=precip_abs1 extrdir=test\
-          -c  title="A test" description="Description of a test"
-ls -la $GISDBASE/new_test_3/PERMANENT
-
+# Checking different flags
 t.rast.import --o input=strds_export.tar.bz2 output=precip_abs1 extrdir=test\
           -oe title="A test" description="Description of a test"
 t.rast.import --o input=strds_export.tar.bz2 output=precip_abs1 extrdir=test\
@@ -57,13 +51,31 @@
 t.rast.import --o input=strds_export.tar.bz2 output=precip_abs1 extrdir=test\
           -l  title="A test" description="Description of a test"
 
+# Import using different compression and formats
+t.rast.import --o input=strds_export.tar.gz output=precip_abs1 extrdir=test\
+              title="A test" description="Description of a test"
+r.info prec_1
+t.rast.import --o input=strds_export.tar output=precip_abs1 extrdir=test\
+              title="A test" description="Description of a test"
+r.info prec_1
+t.rast.import --o input=strds_export_pack.tar output=precip_abs1 extrdir=test\
+              title="A test" description="Description of a test"
+r.info prec_1
+t.rast.import --o input=strds_export_pack.tar.gz output=precip_abs1 extrdir=test\
+              title="A test" description="Description of a test"
+r.info prec_1
+t.rast.import --o input=strds_export_pack.tar.bz2 output=precip_abs1 extrdir=test\
+              title="A test" description="Description of a test"
+r.info prec_1
 
+# Cleaning up
 t.unregister type=rast maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
 t.remove type=strds input=precip_abs1
 g.remove rast=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
 rm -rf test
-rm strds_export.tar.bz2
-# Remove the newly created locations
-rm -rf $GISDBASE/new_test_1
-rm -rf $GISDBASE/new_test_2
-rm -rf $GISDBASE/new_test_3
+#rm strds_export.tar.bz2
+#rm strds_export.tar.gz
+#rm strds_export.tar
+#rm strds_export_pack.tar  
+#rm strds_export_pack.tar.gz
+#rm strds_export_pack.tar.bz2

Added: grass/trunk/temporal/t.vect.export/Makefile
===================================================================
--- grass/trunk/temporal/t.vect.export/Makefile	                        (rev 0)
+++ grass/trunk/temporal/t.vect.export/Makefile	2012-08-03 01:00:19 UTC (rev 52510)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../../
+
+PGM = t.vect.export
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script $(TEST_DST)

Added: grass/trunk/temporal/t.vect.export/t.vect.export.html
===================================================================
Added: grass/trunk/temporal/t.vect.export/t.vect.export.py
===================================================================
--- grass/trunk/temporal/t.vect.export/t.vect.export.py	                        (rev 0)
+++ grass/trunk/temporal/t.vect.export/t.vect.export.py	2012-08-03 01:00:19 UTC (rev 52510)
@@ -0,0 +1,83 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+############################################################################
+#
+# MODULE:	t.vect.export
+# AUTHOR(S):	Soeren Gebbert
+#               
+# PURPOSE:	Export a space time vector dataset.as GRASS specific archive file
+# 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: Export a space time vector dataset.as GRASS specific archive file
+#% keywords: temporal
+#% keywords: export
+#%end
+
+#%option G_OPT_STVDS_INPUT
+#%end
+
+#%option G_OPT_F_OUTPUT
+#% description: Name of a space time vector dataset archive
+#%end
+
+#%option G_OPT_M_DIR
+#% key: workdir
+#% description: Path to the work directory, default is /tmp
+#% required: no
+#% answer: /tmp
+#%end
+
+#%option
+#% key: compression
+#% type: string
+#% description: Compression method of the tar archive
+#% required: no
+#% multiple: no
+#% options: no,gzip,bzip2
+#% answer: bzip2
+#%end
+
+#%option
+#% key: format
+#% type: string
+#% description: The export format of a single raster map. Supported are GML via v.out.ogr and the GRASS package format of v.pack.
+#% required: no
+#% multiple: no
+#% options: GML,pack
+#% answer: GML
+#%end
+
+#%option G_OPT_T_WHERE
+#%end
+
+import grass.script as grass
+import grass.temporal as tgis
+
+    
+############################################################################
+def main():
+
+	# Get the options
+	_input = options["input"]
+	output = options["output"]
+	compression = options["compression"]
+	workdir = options["workdir"]
+	where = options["where"]
+	_format = options["format"]
+
+	# Make sure the temporal database exists
+	tgis.create_temporal_database()
+	# Export the space time raster dataset
+	tgis.export_stds(_input, output, compression, workdir, where, _format, "stvds")
+     
+############################################################################
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    main()


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

Added: grass/trunk/temporal/t.vect.export/test.t.vect.export.sh
===================================================================
--- grass/trunk/temporal/t.vect.export/test.t.vect.export.sh	                        (rev 0)
+++ grass/trunk/temporal/t.vect.export/test.t.vect.export.sh	2012-08-03 01:00:19 UTC (rev 52510)
@@ -0,0 +1,40 @@
+#!/bin/sh
+# Export of space time vector 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
+
+v.random --o -z output=soil_1 n=100 zmin=0 zmax=100 column=height  seed=1
+v.random --o -z output=soil_2 n=100 zmin=0 zmax=100 column=height seed=2
+v.random --o -z output=soil_3 n=100 zmin=0 zmax=100 column=height seed=3
+
+n1=`g.tempfile pid=1 -d` 
+
+cat > "${n1}" << EOF
+soil_1
+soil_2
+soil_3
+EOF
+
+t.create --o type=stvds temporaltype=absolute output=soil_abs1 title="A test" descr="A test"
+t.register -i type=vect input=soil_abs1 file="${n1}" start='2001-01-01' increment="1 months"
+
+# The first @test
+t.vect.export format=GML input=soil_abs1 output=stvds_export_gml.tar.bz2 compression=bzip2 workdir=/tmp
+t.vect.export format=GML input=soil_abs1 output=stvds_export_gml.tar.gz compression=gzip workdir=/tmp
+t.vect.export format=GML input=soil_abs1 output=stvds_export_gml.tar compression=no workdir=/tmp
+
+t.vect.export format=pack input=soil_abs1 output=stvds_export_pack.tar.bz2 compression=bzip2 workdir=/tmp
+t.vect.export format=pack input=soil_abs1 output=stvds_export_pack.tar.gz compression=gzip workdir=/tmp
+t.vect.export format=pack input=soil_abs1 output=stvds_export_pack.tar compression=no workdir=/tmp
+
+t.unregister type=vect file="${n1}"
+t.remove type=stvds input=soil_abs1
+rm stvds_export_gml.tar.bz2
+rm stvds_export_gml.tar.gz
+rm stvds_export_gml.tar
+rm stvds_export_pack.tar.bz2
+rm stvds_export_pack.tar.gz
+rm stvds_export_pack.tar


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

Added: grass/trunk/temporal/t.vect.import/Makefile
===================================================================
--- grass/trunk/temporal/t.vect.import/Makefile	                        (rev 0)
+++ grass/trunk/temporal/t.vect.import/Makefile	2012-08-03 01:00:19 UTC (rev 52510)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../../
+
+PGM = t.vect.import
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script $(TEST_DST)

Added: grass/trunk/temporal/t.vect.import/t.vect.import.html
===================================================================
Added: grass/trunk/temporal/t.vect.import/t.vect.import.py
===================================================================
--- grass/trunk/temporal/t.vect.import/t.vect.import.py	                        (rev 0)
+++ grass/trunk/temporal/t.vect.import/t.vect.import.py	2012-08-03 01:00:19 UTC (rev 52510)
@@ -0,0 +1,94 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+############################################################################
+#
+# MODULE:        t.vect.import
+# AUTHOR(S):     Soeren Gebbert
+#               
+# PURPOSE:        Import a space time vector dataset archive file
+# 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: Import a space time vector dataset archive file
+#% keywords: temporal
+#% keywords: import
+#%end
+
+#%option G_OPT_F_INPUT
+#%end
+
+#%option G_OPT_STVDS_OUTPUT
+#%end
+
+#%option G_OPT_M_DIR
+#% key: extrdir
+#% description: Path to the extraction directory
+#%end
+
+#%option
+#% key: title
+#% type: string
+#% description: Title of the new space time dataset
+#% required: no
+#% multiple: no
+#%end
+
+#%option
+#% key: description
+#% type: string
+#% description: Description of the new space time dataset
+#% required: no
+#% multiple: no
+#%end
+
+#%option
+#% key: location
+#% type: string
+#% description: Create a new location and import the data into it. Please do not run this module in parallel or interrupt it when a new location should be created.
+#% required: no
+#% multiple: no
+#%end
+
+#%flag
+#% key: e
+#% description: Extend location extents based on new dataset
+#%end
+
+#%flag
+#% key: o
+#% description: Override projection (use location's projection)
+#%end
+
+#%flag
+#% key: c
+#% description: Create the location specified by the "location" parameter and exit. Do not import the space time vector datasets.
+#%end
+
+import grass.script as grass
+import grass.temporal as tgis
+
+def main():
+
+	# Get the options
+	input = options["input"]
+	output = options["output"]
+	extrdir = options["extrdir"]
+	title = options["title"]
+	descr = options["description"]
+	location = options["location"]
+	exp = flags["e"]
+	overr = flags["o"]
+	create = flags["c"]
+	
+	tgis.import_stds(input, output, extrdir, title, descr, location, 
+                None, exp, overr, create, "stvds")
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    main()


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

Added: grass/trunk/temporal/t.vect.import/test.t.vect.import.sh
===================================================================
--- grass/trunk/temporal/t.vect.import/test.t.vect.import.sh	                        (rev 0)
+++ grass/trunk/temporal/t.vect.import/test.t.vect.import.sh	2012-08-03 01:00:19 UTC (rev 52510)
@@ -0,0 +1,70 @@
+#!/bin/sh
+# Test the import of space time vector 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
+
+mkdir test
+
+v.random --o -z output=soil_1 n=100 zmin=0 zmax=100 column=height seed=1
+v.random --o -z output=soil_2 n=100 zmin=0 zmax=100 column=height seed=2
+v.random --o -z output=soil_3 n=100 zmin=0 zmax=100 column=height seed=3
+
+n1=`g.tempfile pid=1 -d` 
+
+cat > "${n1}" << EOF
+soil_1
+soil_2
+soil_3
+EOF
+
+t.create --o type=stvds temporaltype=absolute output=soil_abs1 title="A test" descr="A test"
+t.register -i type=vect input=soil_abs1 file="${n1}" start='2001-01-01' increment="1 months"
+
+# The first @test
+t.vect.export format=GML input=soil_abs1 output=stvds_export_gml.tar.bz2 compression=bzip2 workdir=/tmp
+t.vect.export format=GML input=soil_abs1 output=stvds_export_gml.tar.gz compression=gzip workdir=/tmp
+t.vect.export format=GML input=soil_abs1 output=stvds_export_gml.tar compression=no workdir=/tmp
+
+t.vect.export format=pack input=soil_abs1 output=stvds_export_pack.tar.bz2 compression=bzip2 workdir=/tmp
+t.vect.export format=pack input=soil_abs1 output=stvds_export_pack.tar.gz compression=gzip workdir=/tmp
+t.vect.export format=pack input=soil_abs1 output=stvds_export_pack.tar compression=no workdir=/tmp
+
+# Checking different flags
+t.vect.import --o input=stvds_export_gml.tar.bz2 output=precip_abs1 extrdir=test\
+          -oe title="A test" description="Description of a test"
+t.vect.import --o input=stvds_export_gml.tar.bz2 output=precip_abs1 extrdir=test\
+          -o title="A test" description="Description of a test"
+t.vect.import --o input=stvds_export_gml.tar.bz2 output=precip_abs1 extrdir=test\
+              title="A test" description="Description of a test"
+
+# Import using different compression and formats
+t.vect.import --o input=stvds_export_gml.tar.gz output=soil_abs2 extrdir=test\
+              title="A test" description="Description of a test"
+v.info soil_1
+t.vect.import --o input=stvds_export_gml.tar output=soil_abs2 extrdir=test\
+              title="A test" description="Description of a test"
+v.info soil_1
+t.vect.import --o input=stvds_export_pack.tar output=soil_abs2 extrdir=test\
+              title="A test" description="Description of a test"
+v.info soil_1
+t.vect.import --o input=stvds_export_pack.tar.gz output=soil_abs2 extrdir=test\
+              title="A test" description="Description of a test"
+v.info soil_1
+t.vect.import --o input=stvds_export_pack.tar.bz2 output=soil_abs2 extrdir=test\
+              title="A test" description="Description of a test"
+v.info soil_1
+
+# Cleaning up
+rm -rf test
+g.remove vect=soil_1,soil_2,soil_3
+t.unregister type=vect file="${n1}"
+t.remove type=stvds input=soil_abs1,soil_abs2
+rm stvds_export_gml.tar.bz2
+rm stvds_export_gml.tar.gz
+rm stvds_export_gml.tar
+rm stvds_export_pack.tar.bz2
+rm stvds_export_pack.tar.gz
+rm stvds_export_pack.tar
\ No newline at end of file


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



More information about the grass-commit mailing list