0

I am trying to open an .asc file inside a .tgz.tar archive with Python and osgeo.gdal.

Here is the link to the official description that this is possible by using /vsitar/

#source file name
src_filename = "/evapo_p_downloads/grids_germany_daily_evapo_p_200901.tgz/grids_germany_daily_evapo_p_200901.tar/grids_germany_daily_evapo_p_20090101.asc"

#driver 
driver = gdal.GetDriverByName('AAIGrid')

#open file with gdal
src_ds = gdal.Open("/vsitar/" + src_filename)

but

print(src_ds)

gives me a None. I try several other descriptions for path like /vsitar//path or /vsitar/path with and without "" but nothing seems to be work. What am I doing wrong here?

I Found this solution for opening successfully a tarball

src_filename = "/vsitar/{grids_germany_daily_evapo_p_200901.tgz}/grids_germany_daily_evapo_p_20090101.asc"
src_ds = gdal.Open(src_filename)
print(src_ds)

<osgeo.gdal.Dataset; proxy of <Swig Object of type 'GDALDatasetShadow *' at 0x000001BEEBEDBEA0> >

So it didn't work when I enter the full path like /path/to.tgz/my.tar/file instead I have to remove the .tar path maybe because gdal knows that in a tarball (.tgz.tar) there is only one .tar file allowed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.