2

I can obtain the maximum/minimum value of a raster via the ComputeRasterMinMax code:

  using (var ds = Gdal.Open(tiffFile, Access.GA_ReadOnly))
  {
    var nCol = ds.RasterXSize;
    var nRow = ds.RasterYSize;
    var allValues = new int[nCol * nRow];
    Band band = ds.GetRasterBand(1);
    band.ReadRaster(0, 0, nCol, nRow, allValues, nCol, nRow, 0, 0);   
    double[] minMax = new double[2];
    band.ComputeRasterMinMax(minMax, 0);

  }

As per documentation, minMax[0] is the minimum value, and minMax[1] is the maximum value of the band.

But how to get the cell that these maximum and minimum occurs, besides actually looping through the array and compare the item one by one?

0

you could get the value of the "max" cell, reclassify everything that isn't that value to NA, convert the raster to polygon, then find the centroid of the polygon. it's the gorilla approach.

  • Can you show some code snippet how this can be done ? – Graviton Jul 12 at 22:25

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.