Jelajahi Sumber

r.pack/r.unpack: fix packing/unpacking vrt map if some of tiled rasters doesn't have color table (#1116)

* r.pack: fix packing vrt map if some of tiled rasters doesn't have color table
* r.unpack: fix unpacking vrt map with tiled raster maps
Tomas Zigo 4 tahun lalu
induk
melakukan
30b77ddcf9
2 mengubah file dengan 17 tambahan dan 27 penghapusan
  1. 10 9
      scripts/r.pack/r.pack.py
  2. 7 18
      scripts/r.unpack/r.unpack.py

+ 10 - 9
scripts/r.pack/r.pack.py

@@ -123,15 +123,16 @@ def main():
                 if not os.path.exists(f_tmp_dir):
                     os.mkdir(f_tmp_dir)
                 path = os.path.join(vrt_files[f], element, f)
-                grass.debug("copying vrt file {}".format(path))
-                if os.path.isfile(path):
-                    shutil.copyfile(
-                        path, os.path.join(f_tmp_dir, element),
-                    )
-                else:
-                    shutil.copytree(
-                        path, os.path.join(f_tmp_dir, element),
-                    )
+                if os.path.exists(path):
+                    grass.debug("copying vrt file {}".format(path))
+                    if os.path.isfile(path):
+                        shutil.copyfile(
+                            path, os.path.join(f_tmp_dir, element),
+                        )
+                    else:
+                        shutil.copytree(
+                            path, os.path.join(f_tmp_dir, element),
+                        )
 
     if not os.listdir(tmp_dir):
         grass.fatal(_("No raster map components found"))

+ 7 - 18
scripts/r.unpack/r.unpack.py

@@ -85,7 +85,7 @@ def main():
         # print proj info and exit
         try:
             for fname in ['PROJ_INFO', 'PROJ_UNITS']:
-                f = tar.extractfile('{}/{}'.format(data_name, fname))
+                f = tar.extractfile('{}/{}'.format(data_names[0], fname))
                 sys.stdout.write(f.read().decode())
         except KeyError:
             grass.fatal(_("Pack file unreadable: file '{}' missing".format(fname)))
@@ -165,22 +165,13 @@ def main():
                               " use the -o flag to ignore them and use"
                               " current location definition."))
 
-    # Vrt raster map, raster maps postfix e.g. 'map-000-001'
-    r = re.compile(r"[-]\d+(?:\.\d+)?[-]\d+(?:\.\d+)?$")
-
     maps = []
     vrt_file = None
-    # install in $MAPSET
     for index, data in enumerate(data_names):
-        map_postfix = ''
 
-        if index > 0 and data == map_name:
+        if index > 0:
             map_name = data
 
-        match = re.search(r, data)
-        if match:
-            map_postfix = data[match.span(0)[0]:match.span(0)[1]]
-
         for element in [
                 'cats', 'cell', 'cellhd', 'cell_misc', 'colr', 'fcell',
                 'hist'
@@ -196,14 +187,13 @@ def main():
             if element == 'cell_misc':
                 if index > 0:
                     maps.append(
-                        "{map_name}{postfix}@{mapset}".format(
-                            map_name=map_name, postfix=map_postfix,
-                            mapset=gisenv['MAPSET'],
+                        "{map_name}@{mapset}".format(
+                            map_name=map_name, mapset=gisenv['MAPSET'],
                         ),
                     )
 
                 path = os.path.join(
-                    mset_dir, element, map_name + map_postfix,
+                    mset_dir, element, map_name,
                 )
                 if index == 0:
                     vrt_file = os.path.join(path, 'vrt')
@@ -213,10 +203,9 @@ def main():
                 shutil.copytree(src_path, path)
             else:
                 shutil.copyfile(
-                    src_path, os.path.join(
-                        mset_dir, element, map_name + map_postfix,
-                    )
+                    src_path, os.path.join(mset_dir, element, map_name),
                 )
+
     # Update vrt file
     if maps:
         if vrt_file and os.path.exists(vrt_file):