首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用gdalwarp/ GDAL _ GeoTIFF设置GeoTIFF文件的“带描述”选项/标记

如何使用gdalwarp/ GDAL _ GeoTIFF设置GeoTIFF文件的“带描述”选项/标记
EN

Stack Overflow用户
提问于 2015-09-16 13:10:20
回答 4查看 6.6K关注 0票数 7

是否有人知道如何使用GDAL更改或设置GeoTIFF文件的"Description“选项/标记?

为了说明我的意思,这是一个带有set“Description”的GeoTIFF文件返回gdalinfo的示例:

代码语言:javascript
复制
 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通道1: 0.58微米- 0.68微米

如何使用GDAL设置此参数?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2017-11-20 20:54:44

在Python中,您可以设置如下所示的波段描述:

代码语言:javascript
复制
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是否能够读取波段描述。但是,带名在图维中是明显可见的:

票数 9
EN

Stack Overflow用户

发布于 2015-10-18 20:14:25

GDAL包括一个名为gdal_edit.py的python应用程序,它可以用于修改文件的元数据。我不熟悉您所指的描述字段,但是这个工具应该是要使用的。

下面是手册页:edit.py

下面是一个使用我从USGS地球资源管理器下载的正射图像的示例脚本。

代码语言:javascript
复制
#!/bin/sh

#  Image to modify
IMAGE_PATH='11skd505395.tif'

#  Field to modify
IMAGE_FIELD='TIFFTAG_IMAGEDESCRIPTION'

# Print the tiff image description tag
gdalinfo $IMAGE_PATH | grep $IMAGE_FIELD

#  Change the Field
CMD="gdal_edit.py -mo ${IMAGE_FIELD}='Lake-Tahoe' $IMAGE_PATH"
echo $CMD
$CMD

#  Print the new field value
gdalinfo $IMAGE_PATH | grep $IMAGE_FIELD

输出

代码语言:javascript
复制
$ ./gdal-script.py 
TIFFTAG_IMAGEDESCRIPTION=OrthoVista
gdal_edit.py -mo TIFFTAG_IMAGEDESCRIPTION='Lake-Tahoe' 11skd505395.tif
TIFFTAG_IMAGEDESCRIPTION='Lake-Tahoe'

这是另一个应该提供有用信息的链接。

https://gis.stackexchange.com/questions/111610/how-to-overwrite-metadata-in-a-tif-file-with-gdal

票数 2
EN

Stack Overflow用户

发布于 2021-07-21 23:44:48

这里有一个单一用途的python命令行脚本来编辑带描述。

代码语言:javascript
复制
''' Set image band description to specified text'''
import os
import sys
from osgeo import gdal

gdal.UseExceptions()

if len(sys.argv) < 4:
    print(f"Usage: {sys.argv[0]} [in_file] [band#] [text]")
    sys.exit(1)

infile = sys.argv[1]        # source filename and path
inband = int(sys.argv[2])   # source band number
descrip = sys.argv[3]        # description text

data_in = gdal.Open(infile, gdal.GA_Update)
band_in = data_in.GetRasterBand(inband)
old_descrip = band_in.GetDescription()
band_in.SetDescription(descrip)
new_descrip = band_in.GetDescription()

# de-reference the datasets, which triggers gdal to save
data_in = None
data_out = None

print(f"Description was: {old_descrip}")
print(f"Description now: {new_descrip}")

在使用中:

代码语言:javascript
复制
$ python scripts\gdal-edit-band-desc.py test-edit.tif 1 "Red please"
Description was:
Description now: Red please

$ gdal-edit-band-desc test-edit.tif 1 "Red please also"

$ python t:\ENV.558\scripts\gdal-edit-band-desc.py test-edit.tif 1 "Red please also"
Description was: Red please
Description now: Red please also

正确地说,应该将它添加到gdal_edit.py中,但我还不知道是否安全,直接添加它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32609570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档