在 rsgislib 输出图像和图层上设置投影

setting projection on rsgislib output image and layers

我有一些使用 rsgislib 分割图像的测试代码。来自 rsgislib 的文档 I 运行:

from rsgislib.segmentation import segutils

inputImg = 'clipped_geotiff_image.tif'
outputClumps = 'clipped_jers1palsar_stack_clumps_elim_final.tif'
outputMeanImg = 'clipped_jers1palsar_stack_clumps_elim_final_mean.tif'

segutils.runShepherdSegmentation(inputImg, outputClumps, outputMeanImg, minPxls=100)

outputMeanImg在尝试显式添加后不包含坐标系和其他空间信息:

rsgislib.imageutils.copySpatialAndProjFromImage(outputMeanImg, inputImg)

rsgislib.imageutils.assignProj(outputMeanImg, rsgislib.imageutils.getWKTProjFromImage(outputMeanImg), None)

有关详细信息,我在下面提供了 gdalinfo 的输出。谁能建议如何设置坐标系统和其他投影信息或将子数据集 BAND1/DATA 转换为常规光栅文件?

=====

% gdalinfo clip_jers1palsar_stack_clumps_elim_final_mean.kea

Driver: HDF5/Hierarchical Data Format Release 5 Files: clip_jers1palsar_stack_clumps_elim_final_mean.kea Size is 512, 512 Coordinate System is `' Metadata: BAND1_DATA_BLOCK_SIZE=256d
BAND1_DATA_CLASS=IMAGE BAND1_DATA_IMAGE_VERSION=1.2
BAND1_NO_DATA_VAL_NO_DATA_DEFINED=
BAND1_OVERVIEWS_OVERVIEW1_BLOCK_SIZE=256d
BAND1_OVERVIEWS_OVERVIEW1_CLASS=IMAGE
BAND1_OVERVIEWS_OVERVIEW1_IMAGE_VERSION=1.2
BAND1_OVERVIEWS_OVERVIEW2_BLOCK_SIZE=187d
BAND1_OVERVIEWS_OVERVIEW2_CLASS=IMAGE
BAND1_OVERVIEWS_OVERVIEW2_IMAGE_VERSION=1.2
BAND1_OVERVIEWS_OVERVIEW3_BLOCK_SIZE=93d
BAND1_OVERVIEWS_OVERVIEW3_CLASS=IMAGE
BAND1_OVERVIEWS_OVERVIEW3_IMAGE_VERSION=1.2
BAND1_OVERVIEWS_OVERVIEW4_BLOCK_SIZE=46d
BAND1_OVERVIEWS_OVERVIEW4_CLASS=IMAGE
BAND1_OVERVIEWS_OVERVIEW4_IMAGE_VERSION=1.2 Subdatasets:
SUBDATASET_1_NAME=HDF5:"clip_jers1palsar_stack_clumps_elim_final_mean.kea"://BAND1/ATT/DATA/FLOAT SUBDATASET_1_DESC=[256x1] //BAND1/ATT/DATA/FLOAT (64-bit floating-point)
SUBDATASET_2_NAME=HDF5:"clip_jers1palsar_stack_clumps_elim_final_mean.kea"://BAND1/DATA SUBDATASET_2_DESC=[2500x1500] //BAND1/DATA (16-bit unsigned integer)
SUBDATASET_3_NAME=HDF5:"clip_jers1palsar_stack_clumps_elim_final_mean.kea"://BAND1/OVERVIEWS/OVERVIEW1 SUBDATASET_3_DESC=[625x375] //BAND1/OVERVIEWS/OVERVIEW1 (16-bit unsigned integer)
SUBDATASET_4_NAME=HDF5:"clip_jers1palsar_stack_clumps_elim_final_mean.kea"://BAND1/OVERVIEWS/OVERVIEW2 SUBDATASET_4_DESC=[312x187] //BAND1/OVERVIEWS/OVERVIEW2 (16-bit unsigned integer)
SUBDATASET_5_NAME=HDF5:"clip_jers1palsar_stack_clumps_elim_final_mean.kea"://BAND1/OVERVIEWS/OVERVIEW3 SUBDATASET_5_DESC=[156x93] //BAND1/OVERVIEWS/OVERVIEW3 (16-bit unsigned integer)
SUBDATASET_6_NAME=HDF5:"clip_jers1palsar_stack_clumps_elim_final_mean.kea"://BAND1/OVERVIEWS/OVERVIEW4 SUBDATASET_6_DESC=[78x46] //BAND1/OVERVIEWS/OVERVIEW4 (16-bit unsigned integer) Corner Coordinates: Upper Left ( 0.0, 0.0) Lower Left ( 0.0, 512.0) Upper Right ( 512.0, 0.0) Lower Right ( 512.0, 512.0) Center ( 256.0, 256.0)

我找到了部分解决方案,但在 rsgislib 中找不到。

使用 GDAL,我可以打开一个子数据集:

from osgeo import gdal

# get the projection and geotransform from the original input image
ids = gdal.Open(inputImg, gdal.GA_ReadOnly)
gt = ids.GetGeoTransform()
wkt = ids.GetProjectionRef()
print gt

del ids

# now set the projection and geotransform for the specific subdatsert
infile = 'HDF5:"'+outputMeanImg+'"://BAND1/DATA'
ods = gdal.Open(infile, gdal.GA_ReadOnly)
ods.SetProjection(wkt)
ods.SetGeoTransform(gt)

del ods

以上代码为我感兴趣的子数据集设置了投影和地理变换,但请注意,我以只读方式打开输出。如果我将其设置为更新,它会失败,并且它实际上会更新所选数据集,即使它以只读模式打开也是如此。我认为这是一个错误,但它似乎可以通过创建一个新的 .aux.xml 文件来工作。

可能有 easer/better 方法可以做到这一点,但目前可行。