I'd like to read an elevation value from a GeoTIFF that I have. It's already working, but I'd like to interpolate the values for better results.
I currently do so like this:
Dataset dataset = gdal.Open(pathToGeoTiffFile, 0);
String projection = dataset.GetProjection();
double[] transform = dataset.GetGeoTransform();
SpatialReference src = new SpatialReference();
src.SetWellKnownGeogCS("WGS84");
SpatialReference dst = new SpatialReference(projection);
CoordinateTransformation coordinateTransformation = new CoordinateTransformation(src, dst);
double[] xy = coordinateTransformation.TransformPoint(lng, lat);
float[] result = new float[1];
int[] band = {1};
int x = (int)(((xy[0] - transform[0]) / transform[1]) - 0.5);
int y = (int)(((xy[1] - transform[3]) / transform[5]) - 0.5);
dataset.ReadRaster(x, y, 1, 1, 1, 1, 6, result, band);
double elevation = result[0];
This basically works, but there is no interpolation. So basically a coordinate gets mapped to a pixel (no matter if it's close to the next pixel or not) and then I take that value. But I'd prefer to interpolate the value. So if I am on. f.e the bottom of a pixel and the next pixel underneath has a different elevation, the value that I return should be interpolated.
I could of course calculate that on my own, but I was wondering if there is a function that I am missing?