support .7z files
Expected behavior and actual behavior.
The ability to load layers from .zip files is great, it would be nice to be able to do the same from .7z files, too.
Additional context
The French IGN just released a lot of their data in open data. Most of their files are compressed with 7z, and the format seems to be used a lot by other GIS providers. I guess QGIS is not supposed to be able to load data from whatever archive format, but adding support for this one would be a nice addition. (In the meantime, repacking the archives to .zip works)
Operating system
Debian sid
GDAL version and provenance
3.2.1 (Debian sid archive)
Corresponding request from 2014: https://trac.osgeo.org/gdal/ticket/7068
As a workaround, here is a minimal python sample to work with the ign data (asc files in 7z)
pip install py7zr
from py7zr import SevenZipFile
from os.path import join as pjoin
import os
def ign_7z_to_tif(zpath, tpath, tmpdir='asc'):
vrt = pjoin(tmpdir, 'tmp.vrt')
with SevenZipFile(zpath, 'r') as zref:
ascpaths = [f for f in zref.getnames() if f.endswith('.asc')]
zref.extract(targets=ascpaths, path=tmpdir)
vrtinputs = ' '.join((pjoin('asc', p) for p in ascpaths))
os.system(f"gdalbuildvrt -overwrite -a_srs EPSG:2154 -vrtnodata -99999 {vrt} {vrtinputs}")
cmd = f"gdal_translate {OPTIONS} {vrt} {tpath}"
print(cmd)
os.system(cmd)
for f in ascpaths:
os.remove(pjoin(tmpdir, f))
ign_7z_to_tif('foo.7z', 'foo.tif')
I used OPTIONS='-co COMPRESS=ZSTD -co PREDICTOR=2 -co ZSTD_LEVEL=6 -co TILED=YES '
In my experience, such a tif file with zstd-lvl6 compression has a similar size to the original while being easier to work with than asc+7z. Maybe someone can tell IGN guys ;-)
I would really appreciate a support of .7z files, too.
+1 for 7z support, ideally in something like /vsi7z/! Seems like there are several reasons:
- Public institutions packaging their data in 7zip files (like @legrostdg's example)
- Opening the door for ESRI Layer Package support (
.lpk), basically 7-zipped Geodatabases or Shapefiles, as stated in the 2014 Trac ticket - I recently encountered an issue reading from a zip that was generated with 7zip, maybe this could unblock it:
ogrinfo /vsizip/myfile.zip/myfile.shp
ERROR 6: A file in the ZIP archive uses a unsupported compression method (14)
ERROR 1: cpl_unzOpenCurrentFile() failed