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?

2
  • yes, although by the question's title I did not find this post as an answer to my question. Dec 20, 2019 at 11:27
  • Now the questions are linked, so if anyone searches for the keywords in either title, they will find both.
    – csk
    Dec 20, 2019 at 20:16

1 Answer 1

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)

Not the answer you're looking for? Browse other questions tagged or ask your own question.