This:
gdallocationinfo -valonly -wgs84 file longitude latitude
provides the value from the file at the resolved pixel.
Is there a gdal
function that can provide an interpolated value from the neighbouring pixels?
For example these calls read elevation from Greenwich Park in London:
gdallocationinfo -wgs84 srtm_36_02.tif 0 51.4779
47
gdallocationinfo -wgs84 srtm_36_02.tif 0 51.4780
37
That's a 10 metre drop in elevation for a movement of 0.0001°, about 11 metres north.
The pixels in the file are quite coarse - corresponding to about 80 metres on the ground. I want to get smoother values out rather than sudden big jumps.
The workaround I'm currently using is to resample the source file at four times the resolution using this transformation:
gdalwarp -ts 24004 24004 -r cubicspline srtm_36_02.tif srtm_36_02_cubicspline_x4.tiff
The elevations requests for the same locations as previously using the new file:
gdallocationinfo -wgs84 srtm_36_02_cubicspline_x4.tiff 0 51.4779
43
gdallocationinfo -wgs84 srtm_36_02_cubicspline_x4.tiff 0 51.4780
41
which is much better as that is only a 2 metre jump.
The downside of this approach is that it takes a few minutes to generate the higher resolution file, but the main problem is that the file size goes from 69MB to 1.1GB.
I'm surprised that resampling is not a direct option to gdallocationinfo
, or maybe there is another approach I can use?