1

Is it possible to resample the raster by using GDAL C# binaries, in a way that every other cell in a row and column is removed?

Basically a replication of this GDAL command:

gdal_translate -outsize 50% 50% C:/input.tif C:/output.tif

Looks like I need to create a new dataset first:

outputDataset.GetDriver().Create("C:/output.tif", inputDataset.RasterXSize/2, inputDataset.RasterYSize/2, channelCount, DataType.GDT_Byte, null); 

Then read the elevation values from the initial (non-resampled) dataset by applying the buffer size to be half of those the inputDataset had (inputDataset.RasterXSize/2 , inputDataset.RasterYSize/2):

inputDataset.ReadRaster(0, 0, inputDataset.RasterXSize, inputDataset.RasterYSize, buffers, inputDataset.RasterXSize/2, inputDataset.RasterYSize/2, inputDataset.RasterCount, [inputDataset.RasterCount], 0, 0, 0);

And finally write the elevation values to a new .tif file:

finalDataset.WriteRaster(0, 0, inputDataset.RasterXSize, inputDataset.RasterYSize, buffers, inputDataset.RasterXSize/2, inputDataset.RasterYSize/2, inputDataset.RasterCount, [inputDataset.RasterCount], 0, 0, 0);

But the final .tif file I am getting does not seem to be correct.

Can somebody provide a C# example please?

1 Answer 1

1

If you download the GDAL source, you'll have the source for gdal_translate.cpp. Just peruse the code and duplicate it in C#. The translation is straight-forward.

2
  • Thank you for the reply @Reilly. Would you mind pointing to the correct part of the gdal_translate.cpp which deals with "-outsize". I can not find it. Here is the gdal 2.0.1 gdal_translate.cpp. Thank you
    – marco
    Apr 21, 2016 at 15:12
  • Line 651 checks the arg and pulls the arguments into pszOXSize/pszOYSize. Then see line 1214 where nOXSize/nOYSize are calculated. Used many places thereafter.
    – Reilly
    Apr 23, 2016 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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