浏览代码

Set r.out.gdal nodata and precision

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@50952 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 13 年之前
父节点
当前提交
e21ae2e80d
共有 2 个文件被更改,包括 23 次插入8 次删除
  1. 6 6
      temporal/tr.export/test.tr.export.sh
  2. 17 2
      temporal/tr.export/tr.export.py

+ 6 - 6
temporal/tr.export/test.tr.export.sh

@@ -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` 
 

+ 17 - 2
temporal/tr.export/tr.export.py

@@ -99,7 +99,7 @@ def main():
 
     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 @@ def main():
             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 @@ def main():
 
 	    # 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()