I have a GTiff raster with values from 0 to 255 and I want to reclassify 2 values ( 1 and 2) to 1, and the rest set them to NaN, in order to polygonize later and obtain polygons only for the desired value.
Is there a way of doing this?
driver = gdal.GetDriverByName( 'GTiff') file = gdal.Open( 'area.tif') band = file.GetRasterBand(1) lista = band.ReadAsArray() lista[np.where(lista == 2)] = 1 lista[np.where(lista != 1)] = np.NaN
This fails due to
ValueError: cannot convert float NaN to integer