gpt4 book ai didi

mesh - 给定最小的 ESRI ASCII 文件,在 libtiff 或 libgeotiff 中设置的相应字段是什么?

转载 作者:行者123 更新时间:2023-12-04 15:29:22 24 4
gpt4 key购买 nike

我有一个 ESRI ASCII 文件,格式如下:

ncols         5 
nrows 4
xllcorner 0
yllcorner 0
cellsize 10
NODATA_value -9999
25.4 26.1 27 28.6 27.7
25 26 26.4 27.9 27.4
25.1 25.8 26.8 28.6 27.6
27.5 28 27.7 30.6 28.3

而且我需要使用 libtiff.net(或其 C++ 等效项、libtiff、libgeotiff、GDAL 或任何其他 C# 或 C++ 库)将其转换为 geotiff 文件。

但是我根本不知道要设置哪些字段,有很多字段比如 TIFFTAG_IMAGEWIDTH , TIFFTAG_SAMPLESPERPIXELTIFFTAG_BITSPERSAMPLE我不知道它们是否相关。

给定上面的 ESRI ASCII 文件,如何使用 libtiff.net 或 libtiff 库来创建 geotiff 文件?

我为什么要这样做?

在我的应用程序中,我有一个网格,我必须将网格转换为光栅文件。我想直接从网格采样创建这样的 geotiff 光栅文件,而不是先创建中间 ASCII 文件,因为与最终的 geotiff 输出文件相比,中间文件的大小非常大。

我能想到的唯一方法是在获取网格上的网格点时使用 libtiff.net 直接操作 geotiff 文件。

如何做到这一点,或者有更好的方法吗?

最佳答案

实际上,这项任务可以通过使用 GDAL 库(或其 .Net 等效项 GDAL.Net)轻松完成。甚至还有an example here在 Python 中:

ncols         174
nrows 115
xllcorner 14.97
yllcorner -34.54
cellsize 0.11

和 Python 脚本:
if __name__ == '__main__':
# Import libs
import numpy, os
from osgeo import osr, gdal

# Set file vars
output_file = "out.tif"

# Create gtif
driver = gdal.GetDriverByName("GTiff")
dst_ds = driver.Create(output_file, 174, 115, 1, gdal.GDT_Byte )
raster = numpy.zeros( (174, 115) )

# top left x, w-e pixel resolution, rotation, top left y, rotation, n-s pixel resolution
dst_ds.SetGeoTransform( [ 14.97, 0.11, 0, -34.54, 0, 0.11 ] )

# set the reference info
srs = osr.SpatialReference()
srs.SetWellKnownGeogCS("WGS84")
dst_ds.SetProjection( srs.ExportToWkt() )

# write the band
dst_ds.GetRasterBand(1).WriteArray(raster)

将代码转换为 .Net 应该很简单。

关于mesh - 给定最小的 ESRI ASCII 文件,在 libtiff 或 libgeotiff 中设置的相应字段是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53588712/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com