浏览代码

[NEWS] r.|v.unpack: new flag (-p) added to print projection info and exit

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@70974 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 8 年之前
父节点
当前提交
596d67db1f
共有 2 个文件被更改,包括 39 次插入2 次删除
  1. 19 1
      scripts/r.unpack/r.unpack.py
  2. 20 1
      scripts/v.unpack/v.unpack.py

+ 19 - 1
scripts/r.unpack/r.unpack.py

@@ -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 @@ def main():
     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 @@ def main():
 
     # extract data
     tar.extractall()
+    tar.close()
     os.chdir(data_name)
 
     if os.path.exists('cell'):

+ 20 - 1
scripts/v.unpack/v.unpack.py

@@ -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,6 +36,12 @@
 #% 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
@@ -79,6 +85,18 @@ def main():
     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 @@ def main():
 
     # 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')):