gdal icon indicating copy to clipboard operation
gdal copied to clipboard

support .7z files

Open legrostdg opened this issue 5 years ago • 3 comments

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)

legrostdg avatar Jan 05 '21 12:01 legrostdg

Corresponding request from 2014: https://trac.osgeo.org/gdal/ticket/7068

eddy-geek avatar Dec 03 '21 11:12 eddy-geek

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 ;-)

eddy-geek avatar Dec 03 '21 13:12 eddy-geek

I would really appreciate a support of .7z files, too.

MxNl avatar Feb 10 '22 09:02 MxNl

+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

arredond avatar Sep 30 '22 11:09 arredond