[GRASS-SVN] r70974 - in grass/trunk/scripts: r.unpack v.unpack

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Apr 28 02:19:12 PDT 2017


Author: martinl
Date: 2017-04-28 02:19:12 -0700 (Fri, 28 Apr 2017)
New Revision: 70974

Modified:
   grass/trunk/scripts/r.unpack/r.unpack.py
   grass/trunk/scripts/v.unpack/v.unpack.py
Log:
[NEWS] r.|v.unpack: new flag (-p) added to print projection info and exit

Modified: grass/trunk/scripts/r.unpack/r.unpack.py
===================================================================
--- grass/trunk/scripts/r.unpack/r.unpack.py	2017-04-28 04:43:41 UTC (rev 70973)
+++ grass/trunk/scripts/r.unpack/r.unpack.py	2017-04-28 09:19:12 UTC (rev 70974)
@@ -5,7 +5,7 @@
 # AUTHOR(S):	Hamish Bowman, Otago University, New Zealand
 #               Converted to Python by Martin Landa <landa.martin gmail.com>
 # PURPOSE:	Unpack up a raster map packed with r.pack
-# COPYRIGHT:	(C) 2004-2008, 2010-2012 by the GRASS Development Team
+# COPYRIGHT:	(C) 2010-2017 by the GRASS Development Team
 #
 #		This program is free software under the GNU General
 #		Public License (>=v2). Read the file COPYING that
@@ -34,6 +34,11 @@
 #% description: Assume that the dataset has same projection as the current location
 #% guisection: Output settings
 #%end
+#%flag
+#% key: p
+#% label: Print projection information of input pack file and exit
+#% guisection: Print
+#%end
 
 import os
 import sys
@@ -76,6 +81,18 @@
     except:
         grass.fatal(_("Pack file unreadable"))
 
+    if flags['p']:
+        # print proj info and exit
+        try:
+            for fname in ['PROJ_INFO', 'PROJ_UNITS']:
+                f = tar.extractfile('{}/{}'.format(data_name, fname))
+                sys.stdout.write(f.read())
+        except KeyError:
+            grass.fatal(_("Pack file unreadable: file '{}' missing".format(fname)))
+        tar.close()
+
+        return 0
+
     if options['output']:
         map_name = options['output']
     else:
@@ -91,6 +108,7 @@
 
     # extract data
     tar.extractall()
+    tar.close()
     os.chdir(data_name)
 
     if os.path.exists('cell'):

Modified: grass/trunk/scripts/v.unpack/v.unpack.py
===================================================================
--- grass/trunk/scripts/v.unpack/v.unpack.py	2017-04-28 04:43:41 UTC (rev 70973)
+++ grass/trunk/scripts/v.unpack/v.unpack.py	2017-04-28 09:19:12 UTC (rev 70974)
@@ -6,7 +6,7 @@
 # AUTHOR(S):    Luca Delucchi
 #
 # PURPOSE:      Unpack up a vector map packed with v.pack
-# COPYRIGHT:    (C) 2010-2013 by the GRASS Development Team
+# COPYRIGHT:    (C) 2010-2017 by the GRASS Development Team
 #
 #               This program is free software under the GNU General
 #               Public License (>=v2). Read the file COPYING that
@@ -36,7 +36,13 @@
 #% description: Assume that the dataset has same projection as the current location
 #% guisection: Output settings
 #%end
+#%flag
+#% key: p
+#% label: Print projection information of input pack file and exit
+#% guisection: Print
+#%end
 
+
 import os
 import sys
 import shutil
@@ -79,6 +85,18 @@
     except:
         grass.fatal(_("Pack file unreadable"))
 
+    if flags['p']:
+        # print proj info and exit
+        try:
+            for fname in ['PROJ_INFO', 'PROJ_UNITS']:
+                f = tar.extractfile(fname)
+                sys.stdout.write(f.read())
+        except KeyError:
+            grass.fatal(_("Pack file unreadable: file '{}' missing".format(fname)))
+        tar.close()
+
+        return 0
+
     # set the output name
     if options['output']:
         map_name = options['output']
@@ -105,6 +123,7 @@
 
     # extract data
     tar.extractall()
+    tar.close()
     if os.path.exists(os.path.join(data_name, 'coor')):
         pass
     elif os.path.exists(os.path.join(data_name, 'cell')):



More information about the grass-commit mailing list