1

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.

Hugolpz
  • 2,653
  • 3
  • 26
  • 51
  • 1
    you already asked this question, please edit your first question instead of asking a duplicate – radouxju Mar 24 '14 at 20:55
  • @radouxju: This is not the same question. – Hugolpz Mar 24 '14 at 21:01
  • @radouxju: Precision & linking was underway, now online ! – Hugolpz Mar 24 '14 at 21:06
  • IMPORTANT: these is NOT a duplicate of the other question. http://gis.stackexchange.com/questions/90726/gdal-highest-and-lowest-point-pixel-how-to-get-their-altitudes 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. – Hugolpz Mar 27 '14 at 07: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. – radouxju Mar 27 '14 at 07:23
  • The Comments do not form part of a Question and therefore I am unable to vote to re-open this on the basis of anything written in them. Consequently, I recommend that you revise your Question so that, standalone, it explains why it is not a Duplicate. – PolyGeo Mar 27 '14 at 08:01
  • Why is different is already in the question from the start: need THREE (3) data back : altitude (z-coordinate), longitude (x-coordinate), lattitude (y-coordinate). – Hugolpz Mar 27 '14 at 08:07
  • Would you consider QGIS or R to get an answer to this question? – Simbamangu Mar 27 '14 at 08:42
  • I myself need linux shell answer to fit within my project, but your answer may help others. – Hugolpz Mar 27 '14 at 08:46
  • I strongly recommend that you use a scripting language like Python or R at least for parts of your tasks - they can easily be run within a linux shell / command line environment and are quite effective for these kind of tasks (probably more effective than pure sh scripts.) – lavarider Mar 27 '14 at 23:13

3 Answers3

6

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.

Marc Pfister
  • 4,097
  • 17
  • 11
  • 2
    +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. – whuber Mar 27 '14 at 17:02
2

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.

lavarider
  • 810
  • 1
  • 5
  • 15
-1

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.

Hugolpz
  • 2,653
  • 3
  • 26
  • 51
  • 1
    Your tags include [tag: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? – whuber Mar 24 '14 at 21:45
  • I'am begginer, I currently just have gdal. – Hugolpz Mar 27 '14 at 07:11