合并/拼接/缝合多个GEOTIFF文件c#

2024-04-29 18:22:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我有多个GEOTIFF文件,我想用C#和bitmracle.LibTiff.NET. 到目前为止,我已经使用类似于this的代码加载了GEOTIFF。但是,当我简单地将这些并排粘贴在一起时,来自每个GEOTIFF文件的高程贴图似乎会偏移一些值(每个GEOTIFF文件的值不同),但是当我解码这些文件的标记时,我会得到以下结果(示例):

GEOTIFF_MODELPIXELSCALETAG double[3]: 0.4, 0.4, 0

GEOTIFF_MODELTIEPOINTTAG double[6]: 0, 0, 0, 503000, 6190000, 0

表示在z方向上没有缩放或偏移(高程值)

当我在python中使用以下代码时,GEOTIFF之间没有偏移,当我加载生成的单个大GEOTIFF时,一切看起来都和我期望的一样:

import rasterio as rio
from rasterio.merge import merge
from rasterio.plot import show
import glob

tiffns = glob.glob(r'c:\GeoTiffs\*.tif')


src_files_to_merged = []

for fp in tiffns:
    tif = rio.open(fp)
    src_files_to_stich.append(tif)

stiched, out_trans = merge(src_files_to_stich)

show(stiched, cmap='terrain')

out_meta = tif.meta.copy()

out_meta.update({"driver": "GTiff","height": stiched.shape[1],"width": stiched.shape[2],"transform": out_trans})

outfn = r'c:\StichedGeoTiffs.tif'
with rio.open(outfn,"w",**out_meta) as dest:
    dest.write(stiched)

所以。。我想在c#中获得同样的结果。 有人有线索吗?你知道吗

(我想一个不完美的选择是计算两个边界上的平均差(-outliers),然后纠正其中一个,但这总是意味着有出错的风险……)


Tags: 文件to代码importsrcfilesmergeout