如何使用GDAL读取Terrasar-X数据

本文关键字:Terrasar-X 数据 读取 GDAL 何使用 | 更新日期: 2023-09-27 18:05:02

标题问题。最近使用GDAL读取Terrasar-X数据并划分虚部和实部的软件NEST让我很困惑。任何帮助和建议将高度赞赏。下面是我的实现方法:

        string dataPath = @"E:'SARDATA'SampleData'TerraSar-X'SO_000009564_0002_1'SO_000009564_0002_1'TSX1_SAR__SSC______HS_S_SRA_20090223T204240_20090223T204241'TSX1_SAR__SSC______HS_S_SRA_20090223T204240_20090223T204241.xml";
        Gdal.AllRegister();
        Dataset dataset = Gdal.OpenShared(dataPath, Access.GA_ReadOnly);
        Band band = dataset.GetRasterBand(1);
        int xSize = band.XSize;
        int ySize = band.YSize;
        short[] realArray = new short[xSize * ySize];
        short[] imgArray = new short[xSize * ySize];
        if (band.DataType == DataType.GDT_CInt16)
        {
            short[] tmpArray = new short[2 * xSize * ySize];
            band.ReadRaster(0, 0, xSize, ySize, tmpArray, xSize, ySize, 0, 0);
            for (int i = 0; i < tmpArray.Length;i++ )
            {
                realArray[i] = tmpArray[i / 2];
                imgArray[i] = tmpArray[i / 2 + 1];
            }
            tmpArray = null;
        }

如何使用GDAL读取Terrasar-X数据

我想我有办法解决你的问题。我也试着读取一个复杂的TerraSAR-X,我遇到了你的答案。

复杂的文件格式合并了CInt16的两个Int16和CInt32的两个Int32。为了正确读取复杂的数据,你应该把一个Integer分成两个short。正确的读数应该是这样的:

    string dataPath = @"E:'SARDATA'SampleData'TerraSar-X'SO_000009564_0002_1'SO_000009564_0002_1'TSX1_SAR__SSC______HS_S_SRA_20090223T204240_20090223T204241'TSX1_SAR__SSC______HS_S_SRA_20090223T204240_20090223T204241.xml";
    Gdal.AllRegister();
    Dataset dataset = Gdal.OpenShared(dataPath, Access.GA_ReadOnly);
    Band band = dataset.GetRasterBand(1);
    int xSize = band.XSize;
    int ySize = band.YSize;
    short[] realArray = new short[xSize * ySize];
    short[] imgArray = new short[xSize * ySize];
    if (band.DataType == DataType.GDT_CInt16)
    {
        short[] tmpArray = new short[xSize * ySize];
        band.ReadRaster(0, 0, xSize, ySize, tmpArray, xSize, ySize, 0, 0);
        for (int i = 0; i < tmpArray.Length;i++ )
        {
            int value = tmpArray[i];
            realArray[i] = (short)(value>>16);
            imgArray[i] =  (short)(value & 0xffff);
        }
        tmpArray = null;
    }