gpt4 book ai didi

gdal - 如何使用 GDAL (gdalwarp/gdal_translate) 设置 GeoTIFF 文件的 "band description"选项/标签

转载 作者:行者123 更新时间:2023-12-04 23:19:05 32 4
gpt4 key购买 nike

有人知道如何使用 GDAL 更改或设置 GeoTIFF 文件的“描述”选项/标签吗?

为了说明我的意思,这是从带有设置“描述”的 GeoTIFF 文件返回的 gdalinfo 示例:

 Band 1 Block=64x64 Type=UInt16, ColorInterp=Undefined
Description = AVHRR Channel 1: 0.58 micrometers -- 0.68 micrometers
Min=0.000 Max=814.000
Minimum=0.000, Maximum=814.000, Mean=113.177, StdDev=152.897
Metadata:
LAYER_TYPE=athematic
STATISTICS_MAXIMUM=814
STATISTICS_MEAN=113.17657236931
STATISTICS_MINIMUM=0
STATISTICS_STDDEV=152.89720574652

在示例中您可以看到: Description = AVHRR Channel 1: 0.58 micrometers -- 0.68 micrometers

如何使用 GDAL 设置此参数?

最佳答案

在 Python 中,您可以像这样设置波段描述:

from osgeo import gdal, osr
import numpy

# Define output image name, size and projection info:
OutputImage = 'test.tif'
SizeX = 20
SizeY = 20
CellSize = 1
X_Min = 563220.0
Y_Max = 699110.0
N_Bands = 10
srs = osr.SpatialReference()
srs.ImportFromEPSG(2157)
srs = srs.ExportToWkt()
GeoTransform = (X_Min, CellSize, 0, Y_Max, 0, -CellSize)

# Create the output image:
Driver = gdal.GetDriverByName('GTiff')
Raster = Driver.Create(OutputImage, SizeX, SizeY, N_Bands, 2) # Datatype = 2 same as gdal.GDT_UInt16
Raster.SetProjection(srs)
Raster.SetGeoTransform(GeoTransform)

# Iterate over each band
for band in range(N_Bands):
BandNumber = band + 1
BandName = 'SomeBandName '+ str(BandNumber).zfill(3)
RasterBand = Raster.GetRasterBand(BandNumber)
RasterBand.SetNoDataValue(0)
RasterBand.SetDescription(BandName) # This sets the band name!
RasterBand.WriteArray(numpy.ones((SizeX, SizeY)))

# close the output image
Raster = None
print("Done.")

不幸的是,我不确定 ArcGIS 或 QGIS 是否能够读取波段描述。但是,带名称在 Tuiview 中清晰可见:
enter image description here

关于gdal - 如何使用 GDAL (gdalwarp/gdal_translate) 设置 GeoTIFF 文件的 "band description"选项/标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32609570/

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