# convert .srtm to xyz ord grd

I need to plot bathymetry map of my study region and need to convert the .srtm to .xyz or .grd format to use GMT. I tried to do this with grdraster and xyz2grd, but got wrong results. I found that there is srtm2grd command in Linux but I do not have it in my commands. the data are in the following address: ftp://topex.ucsd.edu/pub/srtm30_plus/srtm30/data/

• srtm comes as decimal lat/lon with height values above or below reference ellipsoid. Converting lat/lon to cartesian (e.g.wgs84) is straight forward. e.g. stackoverflow.com/questions/1185408/…. Extrude height along ellipsoid surface normals, not centric normals.
– user20217
Mar 31, 2020 at 14:04
• suggest moving this to Geographic Information Systems stack ex change Apr 1, 2020 at 1:01
• @a_donda The .xyz format for GMT doesn't need cartesian coordinates as requested in Converting from longitude\latitude to Cartesian coordinates. The GMT xyz Format describes the elevation (z) above a reference ellipsoid at a specific location at the surface of the reference ellipsoid (x,y). x and y are expected to be longitude and latitde coordinates in degree East and degree West. Thus, xyz rather means lon-lat-z. Apr 1, 2020 at 8:00
• I see. I wrote a conversion routine for srtm data for my terrain renderer to convert them from geodetic to cartesian (it's just a few lines in C++) to render them in opengl. Wasn't aware that .xyz is a format, thought it was just meant as a paraphrase for cartesian. It takes longer to install GDAL (not mentioning learn the command syntax) than to write the method in an ellipsoid class. I wouldn't trust GDAL on srtm v4.1 data when there's a manual method :-)
– user20217
Apr 1, 2020 at 9:53
• @a_donda Thanks for the background. "I wouldn't trust GDAL on srtm v4.1 data when there's a manual method :-) " => Than better by hand :-D Apr 1, 2020 at 14:58

NOTE: This is not the solution to the question in the title but it solves the problem described in the question's text.

# Alternative solution

I would download the netCDF files from the grd directory instead of the srtm files from the data directory on the FTP server. The netCDF files can directly be plotted by GMT.

# Example

Based on this file: e020n40.nc

#!/bin/bash

outfile=pic.ps
infile=e020n40.nc
invar=z
colorfile=colors.cpt

gmt makecpt -Cviridis -D -T-5200/2400/400 > \${colorfile}

gmt psbasemap -R20/60/-10/40 -JM18 -B4/4"NSEW" -X+1.5c -P -K > $${outfile} gmt grdimage$${infile}?$${invar} -R -J -C$${colorfile} -O -K >> $${outfile} gmt pscoast -J -R -Di -W1,black -O >>$${outfile}


output (pic.ps imported into GIMP v2.8.22 in 60 dpi resolution and with strong antialiasing):

QGIS does it easily. open the NETCDF (or whatever format the SRTM sits in) by add raster right click on the menu item and select export choose the file format as .xyz

DONE!

thanks everybody for your comments and reply I used the grdconvert command in GMT to convert the mentioned .srtm to .grd format.

• Please provide some example code on how the conversion works. This might help other users having the same problem. Thanks. Apr 5, 2020 at 12:59