gdal - 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 行代码,因为 GDALRasterIO
可以动态重新采样。
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 绑定的作者)
推荐阅读
- laravel-5 - 如何使 Laravel 中每个新创建的表的所有列默认可填充
- augmented-reality - 您可以在 A-Frame 上使用 raycaster 与在 AR 模式下创建的对象相交吗?
- angular - CORS 起源问题 NestJs
- go - Apple Silicon 上的 GoLand 无法调试 golang 项目
- reactjs - Next.js 使用 Prism 的语法高亮失败
- stripe-payments - Stripe 支付意图数据中的申请费金额能否以百分比表示?
- ios - Firebase 云功能向 iPhone 发送通知
- spring - 使用 nativeJPQL 删除查询时出现异常
- matlab - MATLAB:如何在图中找到不形成面的节点循环?
- java - 这个 Point board = new Point[10] 是 Point 的新实例吗?