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

时间:2017-11-08 13:35:43

标签: python gdal

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

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的输出。任何人都可以建议如何设置corrdinate系统和其他投影信息或将子数据集BAND1 / DATA转换为传统的光栅文件?

坦克提前。

=====

%gdalinfo clip_jers1palsar_stack_clumps_elim_final_mean.kea

  

驱动程序:HDF5 /分层数据格式版本5文件:   clip_jers1palsar_stack_clumps_elim_final_mean.kea尺寸为512,512   坐标系是''元数据: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位)   浮点)
  SUBDATASET_2_NAME = HDF5:“clip_jers1palsar_stack_clumps_elim_final_mean.kea”:// BAND1 / DATA SUBDATASET_2_DESC = [2500x1500] // BAND1 / DATA(16位无符号整数)
  SUBDATASET_3_NAME = HDF5: “clip_jers1palsar_stack_clumps_elim_final_mean.kea”:// BAND1 /概述/ OVERVIEW1   SUBDATASET_3_DESC = [625x375] // BAND1 / OVERVIEWS / OVERVIEW1(16位   无符号整数)
  SUBDATASET_4_NAME = HDF5: “clip_jers1palsar_stack_clumps_elim_final_mean.kea”:// BAND1 /概述/ OVERVIEW2   SUBDATASET_4_DESC = [312x187] // BAND1 / OVERVIEWS / OVERVIEW2(16位   无符号整数)
  SUBDATASET_5_NAME = HDF5: “clip_jers1palsar_stack_clumps_elim_final_mean.kea”:// BAND1 /概述/ OVERVIEW3   SUBDATASET_5_DESC = [156x93] // BAND1 / OVERVIEWS / OVERVIEW3(16位   无符号整数)
  SUBDATASET_6_NAME = HDF5: “clip_jers1palsar_stack_clumps_elim_final_mean.kea”:// BAND1 /概述/ OVERVIEW4   SUBDATASET_6_DESC = [78x46] // BAND1 / OVERVIEWS / OVERVIEW4(16位无符号)   整数)角坐标:左上角(0.0,0.0)左下角   (0.0,512.0)右上(512.0,0.0)右下(512.0,   512.0)中心(256.0,256.0)

1 个答案:

答案 0 :(得分: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

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

可能有更简单/更好的方法来做到这一点,但现在这种方法有效。