1

题主问题。最近使用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;
        }
4

1 回答 1

0

我想我有办法解决你的问题。我还尝试阅读复杂的 TerraSAR-X 并遇到了您的答案。

复杂文件格式将 CInt16 的两个 Int16 和 CInt32 的两个 Int32 合并。要正确读取复杂数据,您应该将 Integer 分成两个短裤。正确的阅读应该是这样的:

    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;
    }
于 2015-06-08T17:18:11.697 回答