2

Is there a similar way as in ArcPy

import arcpy

desc=arcpy.Describe('rasterName')
print desc.noDataValue

to access the no data value using GDAL?

Vince
  • 20,017
  • 15
  • 45
  • 64
Roger Almengor
  • 405
  • 4
  • 10

1 Answers1

4

The answer is given in Python:Alternatives to using Arcpy

from osgeo import gdal
srs = gdal.Open("dem_maido_tipe.tif")
srs.RasterCount
1
print(srs.GetRasterBand(1).GetNoDataValue())
-32768.0

srs = gdal.Open("geol_map.tif")
srs.RasterCount
3
print(srs.GetRasterBand(1).GetNoDataValue())
None
for i in range(srs.RasterCount):
     print(srs.GetRasterBand(i+1).GetNoDataValue())
None
None
None

And you can also use rasterio, more user-friendly library of GDAL data model

import rasterio
src = rasterio.open("dem_maido_tipe.tif")
print(src.nodatavals)
(-32768.0,)
src = rasterio.open("geol_map.tif")
print(src.nodatavals)
(None, None, None)
gene
  • 54,868
  • 3
  • 110
  • 187