# Topography: How to get the x,y,z coordinates of highest or lowest point/pixel of a raster GIS?

Given a .tiff topographic raster image with mountains and deep sea, I am looking for the x,y,z specifics of the highest or lowest point.

The x,y,z values being:

• altitude (z-coordinate)
• latitude (y-coordinate)
• longitude (x-coordinate)

While `gdalinfo raster.tif` would give a summary of the bounding box and the highest / lowest elevation values (see my previous question here, and note comments below), I would like to find the elevation, latitude, longitude of the highest and/or lowest pixels of my raster.

Would be better if these values are got as isolated output integer. I think raster processing iterating on all pixels of the raster and keeping values of the z-highest point may be a good way to go.

• @radouxju: This is not the same question. Mar 24 '14 at 21:01
• @radouxju: Precision & linking was underway, now online ! Mar 24 '14 at 21:06
• IMPORTANT: these is NOT a duplicate of the other question. gis.stackexchange.com/questions/90726/… just need a `gdalinfo -mm input.tif` and, amongst the long answer, is the Min/Max altitude. There is NO coordinates. Onn the other hand, this new question want the highest altitude, and associated lat-long. The 2 questions are different, with this last one likely needing a completely different solution. Mar 27 '14 at 7:08
• I agree it is not the same. However, I suggest that you should do this with something else than GDAL (e.g. QGIS) if it is not a necessity for you. Changing the tags and title will help you attract better answers. Mar 27 '14 at 7:23

Is Python an option?

Use RasterIO (a Python GDAL/ numpy bridge) to load the raster to NumPy array, then use numpy.amax() to find the maximum value, followed by numpy.where() to find the row/column indices, then calculate the lat and lon from the raster extents.

• +1 The same workflow would apply in `R` (with almost the same names and syntax) and in Mathematica (but with different names and syntax). The same logic applies in all raster calculator environments I can think of (Spatial Analyst, GRASS, Idrisi, Manifold) but would require more cumbersome operations. Mar 27 '14 at 17:02

I recommend using Python or R (or a GIS software), as @Marc Pfister has suggested.

However, you can do it with bash and gdal only, and heavy usage of `grep`.

## First get the Min/Max values without coordinates:

Obtain the Min / Max values with `gdalinfo` or `gdalinfo -mm` like explained in your other question about Min/Max values. Use `grep` (and possibly some `awk`) to extract the values.

## Get their corresponding coordinates:

Convert your tiff file to xyz using `gdal_translate`. (Beware, large file size ahead!)

``````gdal_translate -of XYZ input.tiff /tmp/output.xyz
``````

Now `grep` for the Minimum or the Maximum value. For example, if your Maximum value is 2878, type

``````cat /tmp/output.xyz | grep -E ' 2878\$'
``````

to get the corresponding Lat / Lon / Elevation output:
`36.2358333333333249 -0.123611111111111116 2878`

If you are working with a float dataset, you should adapt the grep expression in order to find rounded Min/Max values.

That's it.

## Alternative if you got the pixel row/column coordinates with other software:

If you don't like the xyz file method, you could also first get the pixel row/column coordinates of the Min/Max values and then convert them to the corresponding lat/lon pair with `gdaltransform`:

For example, if you found out that the maximum value is at pixel coordinates x=12 y=300:
`echo 12 300 | gdaltransform image.tif` will output the corresponding geo coordinate pair depending on the CRS of your source image:
`36.2358333333333249 -0.123611111111111116 0`

If you keep this final coordinate conversion as an extra step, you may be able to use some other software packages (without geospatial features) (e.g. imagemagick) or a small Python / R script to locate pixel coordinates of the the Min/Max values in a more efficient way.

Since neither `gdal_translate -stats SRTM_NE_250m.tif` , nor `gdalinfo -stats SRTM_NE_250m.tif`, nor `gdalinfo -mm SRTM_NE_250m.tif` can work I think I have to iterare through the bitmap via a FOR_loop upon all pixels. The following may help.

• Your tags include raster-calculator and indeed a simple set of raster calculations will be far easier and more efficient than what you propose here. But which raster calculator are you using? Mar 24 '14 at 21:45
• I'am begginer, I currently just have gdal. Mar 27 '14 at 7:11