2

Treat me as a beginner.

I have this method, where the bandArray is the original image double[] array

private double[] ApplyAverageSmoothingNxN(double[] bandArray, int width, int height, int n)
{
    //logic inside here (not relevant)
}

This method returns me a double[] array which is actually the raster file. After the methods returns I try to save the output using Gdal like so:

composedDs = drv.Create(path + "smoothed.tif", XSize, YSize, 1, DataType.GDT_Int16, null);
composedDs.SetGeoTransform(transform);
composedDs.WriteRaster(0, 0, band.XSize, band.YSize, result, band.XSize, band.YSize, 1, null, 0, 0, 0);
composedDs.Dispose();

Now, after I open the output tif image, I see everything black (all 0's). But if I try to run my code again, the raster has all it's values correct. However, if I try to assign all values of the output double[] array like so:

for (int i = 0; i < array.Length; i++) {
     array[i] = 10 //some value.. could be anything else
}

After I save it with Gdal.Create() Arcmap displays pixel values correctly. What is happening ?

Also my input image is a ".jp2" file while the output is done with "GTiff" driver as ".tif".

1

I have solved the issue! The problem was that I had to assign pixelSpace parameter and lineSpace parameter to 1 and 1 respectively. These are practically pixel dimensions.

Here is what I have modified:

composedDs.WriteRaster(0, 0, band.XSize, band.YSize, result, band.XSize, band.YSize, 1, null, 1, 1, 1);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.