Geographic Information Systems Asked on December 21, 2020
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)
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
Answered by Bằng Rikimaru on December 21, 2020
The reason to my problem was that I was not calling the function from the right class. GetOverview
is called from the class Band
.
Answered by William on December 21, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP