<div dir="ltr" gmail_original="1">Another approach using rasterio<div><br></div><div>import rasterio</div><div>import numpy as np</div><div><br></div><div>dataset = rasterio.open('P3412A.tif')<br>band1 = dataset.read(1)</div><div>rows, cols = np.where(band1 == np.max(band1))<div><div dir="ltr" class="gmail_signature"><div dir="ltr">lon, lat = rasterio.transform.xy(dataset.transform, row[0], col[0])<br>print(lat, lon)</div><div dir="ltr">---<div>Ujaval Gandhi</div><div>Spatial Thoughts</div><div><a href="https://mailtrack.io/l/79bb80f67e4a9e655cddd40fc6a12779870dac63?w=Z2RhbC1kZXZAbGlzdHMub3NnZW8ub3Jn&url=http%3A%2F%2Fwww.spatialthoughts.com&u=8747767&signature=198a984b1b993e73" target="_blank" data-mt-detrack-inspected="true">www.spatialthoughts.com</a></div><div><br></div></div></div></div><br></div></div><br><img width="0" height="0" class="mailtrack-img" alt="" style="display:flex" src="https://mailtrack.io/trace/mail/w/Z2RhbC1kZXZAbGlzdHMub3NnZW8ub3Jn/534810d4c31014abe1126883ab1899f775f7c9e0.png?u=8747767" ><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Oct 30, 2024 at 8:06 AM Scott via gdal-dev <gdal-dev@lists.osgeo.org> wrote:<br></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">It ain't pretty or efficient, but it's cheap. Here's min value. Remove <br>
'r' from sort for max value:<br>
<br>
gdal2xyz.py -csv -skipnodata source.tif /dev/stdout | grep -v done | <br>
sort -rnk 3,3 -t "," | tail -1<br>
<br>
result:<br>
-116.9916667,36.54166667,46<br>
<br>
On 10/29/24 17:31, Rahkonen Jukka via gdal-dev wrote:<br>
> Hi,<br>
> <br>
> I would like to know the georeferenced coordinates of the min and max <br>
> values of a DEM file. Even better if I could forward them into a vector <br>
> file. If the minimum or maximum happens to be on a flat area like seabed <br>
> I would be happy with the first pixel at the moment.<br>
> <br>
> By copy-pasting from How do I open geotiff images with GDAL in Python? - <br>
> Stack Overflow <br>
> <<a href="https://stackoverflow.com/questions/41996079/how-do-i-open-geotiff-images-with-gdal-in-python" rel="noreferrer" target="_blank">https://stackoverflow.com/que<wbr>stions/41996079/how-do-i-open-<wbr>geotiff-images-with-gdal-in-<wbr>python</a>> and How to find the indexes of the minimum or maximum value(s) in a matrix using python ? <<a href="https://en.moonbooks.org/Articles/How-to-find-the-indexes-of-the-minimum-or-maximum-values-in-a-matrix-using-python-/" rel="noreferrer" target="_blank">https://en.moonbooks.org/Arti<wbr>cles/How-to-find-the-indexes-<wbr>of-the-minimum-or-maximum-<wbr>values-in-a-matrix-using-<wbr>python-/</a>> I think I managed to get the correct points as numpy indexes<br>
> <br>
>>>> import numpy as np<br>
> <br>
>>>> from osgeo import gdal<br>
> <br>
>>>> ds = gdal.Open('P3412A.tif', gdal.GA_ReadOnly)<br>
> <br>
>>>> rb = ds.GetRasterBand(1)<br>
> <br>
>>>> img_array = rb.ReadAsArray()<br>
> <br>
>>>> vmin = img_array.min()<br>
> <br>
>>>> vmax = img_array.max()<br>
> <br>
>>>> vmin<br>
> <br>
> -0.929<br>
> <br>
>>>> vmax<br>
> <br>
> 17.246<br>
> <br>
>>>><br>
> <br>
>>>> np.where(img_array==vmin)<br>
> <br>
> (array([1504], dtype=intg64), array([1189], dtype=int64))<br>
> <br>
>>>> np.where(img_array==vmax)<br>
> <br>
> (array([1545], dtype=int64), array([2423], dtype=int64))<br>
> <br>
>>>><br>
> <br>
> But now I have no idea about how to get the georeferenced coordinates.<br>
> <br>
> The task feels rather simple and I was sure that someone has already <br>
> made an utility or a QGIS plugin, but all I have found yet is for R. I <br>
> was thinking that perhaps some of the gdaldem modes could be misused for <br>
> this purpose, but I believe they cannot. For QGIS I found advice to use <br>
> an obvious but clumsy method of polygonising the raster and finding the <br>
> extremes from the vector data. And one OpenJUMP developer took the <br>
> challenge and wrote a prototype with Java but it is not complete yet.<br>
> <br>
> -Jukka Rahkonen-<br>
> <br>
> <br>
> ______________________________<wbr>_________________<br>
> gdal-dev mailing list<br>
> <a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
> <a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailma<wbr>n/listinfo/gdal-dev</a><br>
______________________________<wbr>_________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailma<wbr>n/listinfo/gdal-dev</a><br>
</blockquote></div>