[GRASS-SVN] r66448 - grass/trunk/scripts/r.import

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Oct 9 08:49:08 PDT 2015


Author: annakrat
Date: 2015-10-09 08:49:08 -0700 (Fri, 09 Oct 2015)
New Revision: 66448

Modified:
   grass/trunk/scripts/r.import/r.import.py
Log:
r.import: fix temporary vector handling (need to remove it for multi bands import, cleanup), improve messages about resolution, with e flag report for all bands

Modified: grass/trunk/scripts/r.import/r.import.py
===================================================================
--- grass/trunk/scripts/r.import/r.import.py	2015-10-09 14:32:32 UTC (rev 66447)
+++ grass/trunk/scripts/r.import/r.import.py	2015-10-09 15:49:08 UTC (rev 66448)
@@ -117,6 +117,7 @@
 TMPLOC = None
 SRCGISRC = None
 GISDBASE = None
+TMP_REG_NAME = None
 
 
 def cleanup():
@@ -125,9 +126,13 @@
         grass.try_rmdir(os.path.join(GISDBASE, TMPLOC))
     if SRCGISRC:
         grass.try_remove(SRCGISRC)
+    if TMP_REG_NAME:
+        grass.run_command('g.remove', type='vector', name=TMP_REG_NAME,
+                          flags='f', quiet=True)
 
+
 def main():
-    global TMPLOC, SRCGISRC, GISDBASE
+    global TMPLOC, SRCGISRC, GISDBASE, TMP_REG_NAME
 
     GDALdatasource = options['input']
     output = options['output']
@@ -274,7 +279,7 @@
             grass.run_command('g.region', n=n, s=s, e=e, w=w)
 
         # v.in.region in tgt
-        vreg = 'vreg_' + str(os.getpid())
+        vreg = TMP_REG_NAME = 'vreg_tmp_' + str(os.getpid())
         grass.run_command('v.in.region', output=vreg, quiet=True)
 
         grass.del_temp_region()
@@ -297,14 +302,17 @@
         cells = grass.region()['cells']
 
         estres = math.sqrt((n - s) * (e - w) / cells)
+        # remove from source location for multi bands import
+        grass.run_command('g.remove', type='vector', name=vreg,
+                          flags='f', quiet=True)
 
         os.environ['GISRC'] = str(tgtgisrc)
         grass.run_command('g.remove', type='vector', name=vreg,
                           flags='f', quiet=True)
 
-        grass.message(_("Estimated target resolution for input band <%s>: %g") % (outfile, estres))
+        grass.message(_("Estimated target resolution for input band <{out}>: {res}").format(out=outfile, res=estres))
         if flags['e']:
-            return 0
+            continue
 
         if options['extent'] == 'input':
             grass.use_temp_region()
@@ -315,6 +323,12 @@
             res = estres
         elif tgtres == 'value':
             res = tgtres_value
+            grass.message(_("Using given resolution for input band <{out}>: {res}").format(out=outfile, res=res))
+        else:
+            curr_reg = grass.region()
+            grass.message(_("Using current region resolution for input band "
+                            "<{out}>: nsres={ns}, ewres={ew}").format(out=outfile, ns=curr_reg['nsres'],
+                                                                      ew=curr_reg['ewres']))
 
         # r.proj
         grass.message(_("Reprojecting <%s>...") % outfile)
@@ -332,6 +346,9 @@
         if options['extent'] == 'input':
             grass.del_temp_region()
 
+    if flags['e']:
+        return 0
+
     if group:
         grass.run_command('i.group', group=output, input=','.join(outfiles))
 



More information about the grass-commit mailing list