3

I know how to create the overviews to a specific geoTIFF file using GDAL ( i have tested it in QGIS), but I cannot find any good information on how to read these overviews individually in Python.

gdal.SetConfigOption('HFA_USE_RRD', 'YES')
outData = gdal.Open("test2.tiff",gdal.GA_Update)
outData.BuildOverviews(overviewlist=[2,4,8])

i would expect the answer to be something like:

array = outData.GetOverviews(overviewlist = 2)
Kadir Şahbaz
78.6k57 gold badges260 silver badges407 bronze badges
asked Feb 16, 2016 at 14:47
3
  • 2
    How about outdata.GetOverview(2)? Commented Feb 16, 2016 at 15:02
  • It seems like i dont have that function. i have just installed the OSgeo4w64, is this function not available? Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'Dataset' object has no attribute 'GetOverview' >>> Commented Feb 17, 2016 at 8:12
  • I checked my gdal version. it says: 1.11.3 Commented Feb 17, 2016 at 8:48

2 Answers 2

2

The reason to my problem was that I was not calling the function from the right class. GetOverview is called from the class Band.

Kadir Şahbaz
78.6k57 gold badges260 silver badges407 bronze badges
answered Feb 18, 2016 at 11:18
1

Here is the python gdal code to extract overview from Sentinel 2 JP2 format with overview level 2 (0-index).

import gdal
jp2 = "T32UMD_20190727T104029_TCI_10m.jp2"
dataset = gdal.Open(jp2)
band1 = dataset.GetRasterBand(1);
overview1 = band1.GetOverview(2);
band2 = dataset.GetRasterBand(2);
overview2 = band2.GetOverview(2); 
band3 = dataset.GetRasterBand(3);
overview3 = band3.GetOverview(2);
arr1 = overview1.ReadAsArray()
arr2 = overview2.ReadAsArray()
arr3 = overview3.ReadAsArray()
[cols, rows] = arr1.shape
driver = gdal.GetDriverByName("GTiff")
outdata = driver.Create("test_overview.tiff", rows, cols, 3, gdal.GDT_Byte)
outdata.GetRasterBand(1).WriteArray(arr1)
outdata.GetRasterBand(2).WriteArray(arr2)
outdata.GetRasterBand(3).WriteArray(arr3)
outdata.FlushCache() ##saves to disk!!
outdata = None
band=None
ds=None
Kadir Şahbaz
78.6k57 gold badges260 silver badges407 bronze badges
answered Oct 9, 2020 at 9:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.