1

Question of the title.Recently using GDAL reading Terrasar—X data and dividing imaginary and real parts Like software NEST confuses me a lot.Any help and suggestion will be highly appreciated.Below is my implementation method:

        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;
        }
xwhsky
  • 141
  • 6

1 Answers1

0

I think I have a solution to your problem. I also tried to read a complex TerraSAR-X and I encountered your answer.

The complex file format merges two Int16 for CInt16 and two Int32 for CInt32. To read correctly the complex data you should split an Integer into two shorts. The correct reading should look like this:

    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;
    }
floring
  • 1
  • 1