I want to get an XYZ-like surface from a Geotiff with GDAL in Python.

I do the following:

1) Get some geotiff from here: http://srtm.csi.cgiar.org/SELECTION/inputCoord.asp

2) Write the script:

from osgeo import ogr, osr, gdal

file_path = os.path.join(os.path.dirname("/home/felix/dump/srtm_62_05.tif")
gdal_data = gdal.Open(file_path, gdal.GA_ReadOnly)
raster_band = gdal_data.GetRasterBand(1)
raster = raster_band.ReadAsArray()

Okay, it works and even gives me some data in [latitude, longitude --> some_strange_elevation_units] format.

I want to convert this raster to some X[i,j], Y[i,j], Z[i, j] surface. And I need the units to be scaled in meters. How can it be done?

P.S. I use GDAL 2.1.3

  • 1
    What height units does your data srtm_62_05.tif use? – user30184 Sep 16 '17 at 9:51
  • Meters. But they are calculated not from simple sea level, but from some strange point. Also, when there is sea on the map, the elevation is about -32000, and I don't know why... – Felix Sep 16 '17 at 9:57
  • Data providers usually have also metadata about their products. I would read first everythig from srtm.csi.cgiar.org/index.asp. My guess is that about -32000 means a hole in the data, "nodata". – user30184 Sep 16 '17 at 10:06
  • It's -32768, not -32000. This is explicitly stated on the CGIAR site (and read/understood by GDAL) to be the No Data (null) value. – user2856 Sep 16 '17 at 10:55
  • 1
    Duplicate of Stack Overflow question GDAL for Python: how to get a cartesian XYZ surface in meters from a Geotiff? – gene Sep 16 '17 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.