AnswerBun.com

Reading a specific overview layer from GeoTIFF file using GDAL / Python

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)

2 Answers

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

Add your own answers!

Related Questions

OpenLayers zoom on a collection of points

1  Asked on June 14, 2021 by jnewman

     

Re-ordering layers before exporting to web map?

2  Asked on June 14, 2021 by jerry-johnson

 

QGIS NetCDF loaded upside down

0  Asked on June 14, 2021 by tbc

     

Loading GeoJSON in OpenLayers?

1  Asked on June 14, 2021 by matixcraft-matixcraft

   

ArcGIS Pro freezes when using Measure tool

0  Asked on June 13, 2021 by arvicola

 

Button on click does not display pie charts

1  Asked on June 13, 2021 by dilettante

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir