gdallocationinfo的插值结果



这:

gdallocationinfo -valonly -wgs84 file longitude latitude 

提供文件中解析像素处的值。

是否有gdal函数可以提供来自相邻像素的插值

例如,这些电话显示伦敦格林威治公园的海拔高度:

gdallocationinfo -wgs84 srtm_36_02.tif 0 51.4779
47
gdallocationinfo -wgs84 srtm_36_02.tif 0 51.4780
37

对于0.0001°的运动来说,这是海拔下降10米;,以北约11米。

文件中的像素相当粗糙,相当于地面上大约80米。我想得到更平滑的值,而不是突然的大跳跃。

我目前使用的解决方法是使用以下转换以分辨率的四倍对源文件重新采样:

gdalwarp -ts 24004 24004 -r cubicspline srtm_36_02.tif srtm_36_02_cubicspline_x4.tiff

高程要求与以前使用新文件的位置相同

gdallocationinfo -wgs84 srtm_36_02_cubicspline_x4.tiff 0 51.4779
43
gdallocationinfo -wgs84 srtm_36_02_cubicspline_x4.tiff 0 51.4780
41

这要好得多,因为那只是一个2米的跳跃。

这种方法的缺点是生成更高分辨率的文件需要几分钟的时间,但主要问题是文件大小从69MB变为1.1GB

我很惊讶重新采样不是gdallocationinfo的直接选项,或者我可以使用其他方法?

您可以编写Python或Node.js脚本来实现这一点,这将是4或5行代码,因为GDAL的RasterIO可以实时重新采样。

Node.js是这样的:

const cellSize = 4; // This is your resampling factor
const gdal = require('gdal-async');
const ds = gdal.open('srtm_36_02.tif');
// Transform from WGS84 to raster coordinates
const xform = new gdal.CoordinateTransformation(
gdal.SpatialReference.fromEPSG(4326), ds);
const coords = xform.transformPoint({x, y}); 
ds.bands.get(1).pixels.read(
coords.x - cellSize/2,
coords.y - cellSize/2,
cellSize,
cellSize,
undefined, // Let GDAL allocate an output buffer
{  buffer_width: 1, buffer_height: 1 } // of this size
);
console.log(data);

为了简洁起见,我省略了当你靠近边缘时对坐标的夹紧,在这种情况下你必须减小尺寸。

(免责声明:我是GDAL Node.js绑定的作者(

您可以尝试从gdalwarp获得一个1像素光栅。这将使用所有曲速重采样机制,对ram/cmpu/disk的影响最小。我正在使用这个(在Python程序中,因为对于shell脚本来说,计算可能有点太复杂了(。它确实有效。

最新更新