版权声明:本文为博主原创文章,欢迎署名转载。 https://blog.csdn.net/dou3516/article/details/81535905
Code:
Method1
from osgeo import gdal
# get raster datasource
src_ds = gdal.Open("bigtif larger than 4 GB.tif")
print (src_ds)
# read raster bands
print "[ RASTER BAND COUNT ]: ", src_ds.RasterCount
for band in range( src_ds.RasterCount ):
band += 1
print "[ GETTING BAND ]: ", band
srcband = src_ds.GetRasterBand(band)
if srcband is None:
continue
Method2
You can read the data as Array with:
data = src_ds.ReadAsArray()
And then pass it on the your favourite plotting library.
Alternatively you could simply output to a more common 'picture' format (PNG for example), and use any viewer you like to display the result.
vmin = 0 # minimum value in your data (will be black in the output)
vmax = 1 # minimum value in your data (will be white in the output)
ds = gdal.Translate('fused.png', 'fused.tif', format='PNG', outputType=gdal.GDT_Byte, scaleParams=[[vmin,vmax]])
ds = None
The scaling is necessary to convert your data values to the 8-bit range (0-255) which commonly used for pictures.
Requiremennts:
gdal 2.2.4 +
libtiff 4.0.9 +
Using conda:
conda search gdal
conda install gdal=2.2.4