[GRASS-SVN] r50952 - grass/trunk/temporal/tr.export

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Feb 26 18:00:06 EST 2012


Author: huhabla
Date: 2012-02-26 15:00:05 -0800 (Sun, 26 Feb 2012)
New Revision: 50952

Modified:
   grass/trunk/temporal/tr.export/test.tr.export.sh
   grass/trunk/temporal/tr.export/tr.export.py
Log:
Set r.out.gdal nodata and precision


Modified: grass/trunk/temporal/tr.export/test.tr.export.sh
===================================================================
--- grass/trunk/temporal/tr.export/test.tr.export.sh	2012-02-26 07:40:46 UTC (rev 50951)
+++ grass/trunk/temporal/tr.export/test.tr.export.sh	2012-02-26 23:00:05 UTC (rev 50952)
@@ -6,12 +6,12 @@
 # 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)"
+r.mapcalc --o expr="prec_1 = rand(0, 550.0)"
+r.mapcalc --o expr="prec_2 = rand(0, 80000)"
+r.mapcalc --o expr="prec_3 = rand(-120, 120)"
+r.mapcalc --o expr="prec_4 = rand(0, 255)"
+r.mapcalc --o expr="prec_5 = rand(-1, 60000)"
+r.mapcalc --o expr="prec_6 = rand(0, 256)"
 
 n1=`g.tempfile pid=1 -d` 
 

Modified: grass/trunk/temporal/tr.export/tr.export.py
===================================================================
--- grass/trunk/temporal/tr.export/tr.export.py	2012-02-26 07:40:46 UTC (rev 50951)
+++ grass/trunk/temporal/tr.export/tr.export.py	2012-02-26 23:00:05 UTC (rev 50952)
@@ -99,7 +99,7 @@
 
     sp.select()
        
-    columns = "name,start_time,end_time"
+    columns = "name,start_time,end_time,min,max,datatype"
     rows = sp.get_registered_maps(columns, where, "start_time", None)
 
     if compression == "gzip":
@@ -120,6 +120,9 @@
             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)
@@ -128,7 +131,19 @@
 
 	    # Export the raster map with r.out.gdal as tif
             out_name = name + ".tif"
-            ret = grass.run_command("r.out.gdal", flags="c", input=name, output=out_name, format="GTiff")
+            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()



More information about the grass-commit mailing list