Browse Source

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

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@66448 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 9 years ago
parent
commit
96f9a4b48a
1 changed files with 21 additions and 4 deletions
  1. 21 4
      scripts/r.import/r.import.py

+ 21 - 4
scripts/r.import/r.import.py

@@ -117,6 +117,7 @@ from grass.exceptions import CalledModuleError
 TMPLOC = None
 SRCGISRC = None
 GISDBASE = None
+TMP_REG_NAME = None
 
 
 def cleanup():
@@ -125,9 +126,13 @@ def cleanup():
         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 @@ def main():
             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 @@ def main():
         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 @@ def main():
             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 @@ def main():
         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))