# Get true maximum value of a raster

**URL:** <https://discourse.julialang.org/t/get-true-maximum-value-of-a-raster/70622>\
**Category:** General Usage\
**Tags:** geo\
**Created:** [October 29, 2021, 1:40pm UTC](https://discourse.julialang.org/t/get-true-maximum-value-of-a-raster/70622 "2021-10-29T13:40:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![CompulsoryCoffee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compulsorycoffee/32/30434_2.png) [@CompulsoryCoffee](https://discourse.julialang.org/u/CompulsoryCoffee)\
**Post date:** [October 29, 2021, 1:40pm UTC](https://discourse.julialang.org/t/get-true-maximum-value-of-a-raster/70622/1 "2021-10-29T13:40:50Z")

</div>

Hi,

I have raster which I would like to get the maximum value from using ArchGDAL but I get only the (I believe 98th percentile (as it is done in QGIS)

```julia

using ArchGDAL
const AG = ArchGDAL

dataset = AG.readraster("raster.tif")

GDAL Dataset (Driver: GTiff/GeoTIFF)
File(s): 
  /Volumes/Black/Git_Data/node_creation/FlowR/su30m_nepal_propa_17843_nb_propagations.tif
  /Volumes/Black/Git_Data/node_creation/FlowR/su30m_nepal_propa_17843_nb_propagations.tif.aux.xml

Dataset (width x height): 79607 x 46661 (pixels)
Number of raster bands: 1
  [GA_ReadOnly] Band 1 (Gray): 79607 x 46661 (UInt32)

```

```julia
band = AG.getband(dataset, 1)

[GA_ReadOnly] Band 1 (Gray): 79607 x 46661 (UInt32)
    blocksize: 79607×1, nodata: nothing, units: 1.0px + 0.0
    overviews:

```

```julia
AG.maximum(band)
11131.0

```

Now if I use GeoArray

```julia
using GeoData

raster = GDALarray("raster.tif") |> GeoArray

79607×46661×1 GeoArray{UInt32,3} with dimensions: 
  X: range(-177639.86776953447, stop=618420.1322304655, length=79607)
    Projected: Ordered Regular Intervals crs: WellKnownText,
  Y: range(3.380732533405694e6, stop=2.914132533405694e6, length=46661)
    Projected: Ordered Regular Intervals crs: WellKnownText,
  Band: 1:1 Categorical: Ordered

using Statistics
m = Int(maximum(raster))

49231

```

49231 is the correct maximum raster value computed outside Julia for QC

Can I get the true maximum value from ArchGDAL like

`band.ComputeRasterMinMax()`

in python?

Thanks!

---

<div class="post-metadata">

**Author:** ![visr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/visr/32/17204_2.png) [@visr](https://discourse.julialang.org/u/visr)\
**Post date:** [October 29, 2021, 7:25pm UTC](https://discourse.julialang.org/t/get-true-maximum-value-of-a-raster/70622/2 "2021-10-29T19:25:57Z")

</div>

Hmm interesting. So the `gdalgetrastermaximum` function that is called here [doesn’t do any computation](https://github.com/OSGeo/gdal/issues/1548#issuecomment-494544033), but gets it from the metadata if it exists. So apparently the metadata in your file was set to the percentile and not the max.

If you want to compute the max, you can call `maximum(band)` (Base.maximum).

---

<div class="post-metadata">

**Author:** ![CompulsoryCoffee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compulsorycoffee/32/30434_2.png) [@CompulsoryCoffee](https://discourse.julialang.org/u/CompulsoryCoffee)\
**Post date:** [November 1, 2021, 9:34am UTC](https://discourse.julialang.org/t/get-true-maximum-value-of-a-raster/70622/3 "2021-11-01T09:34:18Z")

</div>

> [@visr](#):
>
> maximum(band)

Indeed - thank you for the solution

I manage to get the expected result by doing:

```julia

maxBand = Int(maximum(band))

```

---

<div class="post-metadata">

**Author:** ![CompulsoryCoffee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compulsorycoffee/32/30434_2.png) [@CompulsoryCoffee](https://discourse.julialang.org/u/CompulsoryCoffee)\
**Post date:** [November 1, 2021, 11:20am UTC](https://discourse.julialang.org/t/get-true-maximum-value-of-a-raster/70622/4 "2021-11-01T11:20:37Z")

</div>

I just happended to bump into an error this morning:

```julia

ERROR: Failed to precompile ArchGDAL [c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3] to /Users/ad/.julia/compiled/v1.6/ArchGDAL/jl_tCKQKD.
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::Base.TTY, internal_stdout::Base.TTY, ignore_loaded_modules::Bool)
   @ Base ./loading.jl:1385
 [3] compilecache(pkg::Base.PkgId, path::String)
   @ Base ./loading.jl:1329
 [4] _require(pkg::Base.PkgId)
   @ Base ./loading.jl:1043
 [5] require(uuidkey::Base.PkgId)
   @ Base ./loading.jl:936
 [6] require(into::Module, mod::Symbol)
   @ Base ./loading.jl:923

```

Would you know if any update happened recently?

---

<div class="post-metadata">

**Author:** ![visr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/visr/32/17204_2.png) [@visr](https://discourse.julialang.org/u/visr)\
**Post date:** [November 1, 2021, 11:25am UTC](https://discourse.julialang.org/t/get-true-maximum-value-of-a-raster/70622/5 "2021-11-01T11:25:41Z")

</div>

Yes, that is [https://github.com/JuliaGeo/GDAL.jl/issues/126](https://github.com/JuliaGeo/GDAL.jl/issues/126). If anyone has some time to edit the registry to prevent GDAL\_jll releases to pick up GEOS\_jll version 3.10, that’d be very welcome.
