I modified a script which reclassifies a raster. It is based on the script by Roger in his blog (the second script) and it works pretty well.The problem I am facing is as follows: I would like to reclassify a value (in this case 100) to -9999 and then set -9999 as the nodata value. Below is the list of values to classify and the list to which the corresponding value should be reclassified. Note that value 100 should go to value -9999.
classification_values = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,100] #The interval values to classify classification_output_values = [4,1,2,3,4,5,5,6,7,8,9,11,12,13,14,15,16,17,18,10,14,14,5,16,-9999] #The value assigned to each interval
However, when I view the resultant raster after running the reclass script, value 100 is not -9999, it defaults to 0, but -9999 is set as the nodata value.
In the script I added after line 33 in Roger's script
dst_ds.GetRasterBand(1).SetNoDataValue(-9999)
If I reclass value 100 to 0 and set 0 as the nodata value the resultant raster is correct and everywhere were value 100 used to be there is nodata.
Not sure if the followong info might be of use: Input raster is 8bit unsigned (have tried 16bit signed with no luck); I have changed the numpy array from 8bit to 16bit signed (line 47 in Roger's script); Output raster is 16bit signed.
How would I go about solving this problem?
r = zeros((rows, cols), numpy.uint16)
? That would be an unsigned integer which would explain why any negative value becomes 0 instead. If that is the case trynumpy.int16
.