[GRASS-SVN] r58041 - grass/trunk/lib/python/temporal

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Oct 18 04:39:35 PDT 2013


Author: huhabla
Date: 2013-10-18 04:39:34 -0700 (Fri, 18 Oct 2013)
New Revision: 58041

Modified:
   grass/trunk/lib/python/temporal/stds_export.py
   grass/trunk/lib/python/temporal/stds_import.py
Log:
Integrated AAIGrid format for export and import of space time raster datasets.


Modified: grass/trunk/lib/python/temporal/stds_export.py
===================================================================
--- grass/trunk/lib/python/temporal/stds_export.py	2013-10-18 08:49:11 UTC (rev 58040)
+++ grass/trunk/lib/python/temporal/stds_export.py	2013-10-18 11:39:34 UTC (rev 58041)
@@ -52,7 +52,7 @@
 ############################################################################
 
 
-def _export_raster_maps_as_geotiff(rows, tar, list_file, new_cwd, fs):
+def _export_raster_maps_as_gdal(rows, tar, list_file, new_cwd, fs, format_):
     for row in rows:
         name = row["name"]
         start = row["start_time"]
@@ -65,24 +65,31 @@
         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"
+
+        if format_ == "GTiff":
+            # 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:
-                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")
+                ret = core.run_command("r.out.gdal", flags="c",
+                                    input=name, output=out_name, format="GTiff")
+        elif format_ == "AAIGrid":
+            # Export the raster map with r.out.gdal as Arc/Info ASCII Grid
+            out_name = name + ".asc"
+            ret = core.run_command("r.out.gdal", flags="c", input=name, output=out_name, format="AAIGrid")
+            
         if ret != 0:
             shutil.rmtree(new_cwd)
             tar.close()
@@ -103,7 +110,6 @@
 
 ############################################################################
 
-
 def _export_raster_maps(rows, tar, list_file, new_cwd, fs):
     for row in rows:
         name = row["name"]
@@ -126,7 +132,6 @@
 
 ############################################################################
 
-
 def _export_vector_maps_as_gml(rows, tar, list_file, new_cwd, fs):
     for row in rows:
         name = row["name"]
@@ -154,7 +159,6 @@
 
 ############################################################################
 
-
 def _export_vector_maps(rows, tar, list_file, new_cwd, fs):
     for row in rows:
         name = row["name"]
@@ -198,7 +202,7 @@
         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
+        # Export the raster 3d map with r3.pack
         ret = core.run_command("r3.pack", input=name, flags="c")
         if ret != 0:
             shutil.rmtree(new_cwd)
@@ -231,6 +235,7 @@
                           of maps from the space time dataset
             @param format_ The export format:
               - "GTiff" Geotiff format, only for raster maps
+              - "AAIGrid" Arc/Info ASCII Grid 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,
@@ -274,9 +279,9 @@
 
     if rows:
         if type_ == "strds":
-            if format_ == "GTiff":
-                _export_raster_maps_as_geotiff(
-                    rows, tar, list_file, new_cwd, fs)
+            if format_ == "GTiff" or format_ == "AAIGrid":
+                _export_raster_maps_as_gdal(
+                    rows, tar, list_file, new_cwd, fs, format_)
             else:
                 _export_raster_maps(rows, tar, list_file, new_cwd, fs)
         elif type_ == "stvds":

Modified: grass/trunk/lib/python/temporal/stds_import.py
===================================================================
--- grass/trunk/lib/python/temporal/stds_import.py	2013-10-18 08:49:11 UTC (rev 58040)
+++ grass/trunk/lib/python/temporal/stds_import.py	2013-10-18 11:39:34 UTC (rev 58041)
@@ -54,7 +54,7 @@
 ############################################################################
 
 
-def _import_raster_maps_from_geotiff(maplist, overr, exp, location, link):
+def _import_raster_maps_from_gdal(maplist, overr, exp, location, link, format_):
     impflags = ""
     if overr:
         impflags += "o"
@@ -62,7 +62,12 @@
         impflags += "e"
     for row in maplist:
         name = row["name"]
-        filename = row["filename"] + ".tif"
+        if format_ == "GTiff":
+            filename = row["filename"] + ".tif"
+        elif format_=="AAIGrid":
+            filename = row["filename"] + ".asc"
+            if not overr:
+                impflags += "o"
 
         if link:
             ret = core.run_command("r.external", input=filename,
@@ -333,33 +338,39 @@
         if line_count != int(init["number_of_maps"]):
             core.fatal(_("Number of maps mismatch in init and list file."))
 
-        _format = "GTiff"
-        _type = "strds"
+        format_ = "GTiff"
+        type_ = "strds"
 
         if "stds_type" in init:
-            _type = init["stds_type"]
+            type_ = init["stds_type"]
         if "format" in init:
-            _format = init["format"]
+            format_ = init["format"]
 
-        if stds_type != _type:
+        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":
+        if format_ == "GTiff":
             for row in maplist:
                 filename = row["filename"] + ".tif"
                 if not os.path.exists(filename):
                     core.fatal(_("Unable to find geotiff raster file "
                                  "<%s> in archive.") % filename)
-        elif _format == "GML":
+        elif format_ == "AAIGrid":
             for row in maplist:
+                filename = row["filename"] + ".asc"
+                if not os.path.exists(filename):
+                    core.fatal(_("Unable to find AAIGrid raster file "
+                                 "<%s> in archive.") % filename)
+        elif format_ == "GML":
+            for row in maplist:
                 filename = row["filename"] + ".xml"
                 if not os.path.exists(filename):
                     core.fatal(_("Unable to find GML vector file "
                                  "<%s> in archive.") % filename)
-        elif _format == "pack":
+        elif format_ == "pack":
             for row in maplist:
-                if _type == "stvds":
+                if type_ == "stvds":
                     filename = str(row["filename"].split(":")[0]) + ".pack"
                 else:
                     filename = row["filename"] + ".pack"
@@ -371,24 +382,24 @@
 
         # Check the space time dataset
         id = output + "@" + mapset
-        sp = dataset_factory(_type, id)
+        sp = dataset_factory(type_, id)
         if sp.is_in_db() and core.overwrite() == False:
             core.fatal(_("Space time %(t)s dataset <%(sp)s> is already in the "
-                         "database. Use the overwrite flag.") % {'t': _type,
+                         "database. Use the overwrite flag.") % {'t': type_,
                                                                  'sp': 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":
+        if type_ == "strds":
+            if format_ == "GTiff" or format_ == "AAIGrid":
+                _import_raster_maps_from_gdal(
+                    maplist, overr, exp, location, link, format_)
+            if format_ == "pack":
                 _import_raster_maps(maplist)
-        elif _type == "stvds":
-            if _format == "GML":
+        elif type_ == "stvds":
+            if format_ == "GML":
                 _import_vector_maps_from_gml(
                     maplist, overr, exp, location, link)
-            if _format == "pack":
+            if format_ == "pack":
                 _import_vector_maps(maplist)
 
         # Create the space time dataset



More information about the grass-commit mailing list