GeoTiffCOG
GeoTiffCOG copied to clipboard
Wrong pixel value returned ?
So i got it working, it works for the sample geotiff file.
However i wanna use it for my own files... its called "pnv_biome.type_biome00k_c_1km_s0..0cm_2000..2017_v0.1" and contains a value from 0 to 31 for each pixel. Basically natural vegetation and biomes.
When i run the program for my desired geocoordinate, it returns insanly high values. Wrong values. Furhermore, one single "GetElevationAtLAtLong" call generates about 500mb garbage.
Any help here ?
As I did not see the attached file, I searched and arrived at this base: (https://dataverse.harvard.edu/file.xhtml?persistentId=doi:10.7910/DVN/QQHCIK/W8MYQO&version=4.0), is this correct?
Assuming so, I verified that it is an 8-bit geotiff and I see in the code that this type of data was not handled: https://github.com/fabric-io-rodrigues/GeoTiffCOG/blob/efac2b5d68c7fc4912077613f7f35944e419b223/GeoTiffCOG/GeoTiff.cs#L222
case RasterSampleFormat.UNSIGNED_INTEGER:
if (metadata.BitsPerSample == 32)
{
heightValue = BitConverter.ToUInt32(buffer, offset * metadata.BitsPerSample / 8);
}
else // metadata.BitsPerSample == 16
{
heightValue = BitConverter.ToUInt16(buffer, offset * metadata.BitsPerSample / 8);
}
heightValue = heightValue * metadata.Scale + metadata.Offset;
break;
I made a small change, to return the byte value inside the "byteScanline" array.
As a test suppose the following coordinate: 51.0, 8.3 (lat,lon); Which corresponds to the pixel 22596, 4364 (x,y).
nearby at that location indicated on the map.

The value (after commit) will return 9. However, it doesn't work well with some points that I took randomly, returning 255 (null value).
We need to review this part of the code to support 8bit geotiff well.
There is no mystery about 8bit support, in my example the points were very close to the border and the code that transforms coordinates into pixels needed an adjustment, which has now been resolved.
@genaray please confirm if this version solves your problem, if so we can close this ticket.