How do I write out a GeoTIFF with a coordinate reference system for Mars (e.g., IAU_Mars_2000_Sphere)?
69 views (last 30 days)
Show older comments
I am trying to write out a digital elevation model (DEM) as a geoTIFF, with a coordinate reference system for Mars. For Earth, I am able to do:
outfile = 'synthetic_dem.tif';
geotiffwrite(outfile, int16(Z), Rgeo, 'CoordRefSysCode', 4326); % EPSG:4326 = WGS84 (Earth)
But I am not sure how to do this for Mars, since, as far as I can tell, there is no CoordRefSysCode for Mars. Something like IAU_Mars_2000_Sphere would be ideal ( https://spatialreference.org/ref/esri/104971/wkt.html ). I am new to these systems, so I may be mixing projections and coordinate reference systems.
Thank you for your help!
2 Comments
Walter Roberson
on 16 Nov 2025 at 6:21
I have no idea how to do this, but when I look around a bit, I find references that indicate that it can be done. I find specific mention of GeoTIFF format being used for Mars rover data.
Aditya Khuller
on 17 Nov 2025 at 22:09
Edited: Walter Roberson
on 17 Nov 2025 at 23:03
Answers (1)
Moritz Tenthoff
on 20 Nov 2025 at 0:03
I had the exact same problem this week but for Mercury instead of Mars.
geotiffwrite defaults to 'EPSG:4326' if you don't provide the CoordRefSysCode Name-Value argument. Unfortunately, you cannot provide ESRI or IGNF codes like you can for projcrs or geocrs (Although I found that IAU_2015 codes would be more useful here for celestial bodies). EPSG codes are only for Earth.
That leaves two options:
- Define the coordinate reference system manually via the GeoKeyDirectoryTag argument. That means manually building a struct with all required keys. I've found this resource for the Key IDs, but it's pretty incomprehensible.
- Use an external program to fill in the correct information. This is what I chose after I didn't find a way to make geotiffwrite do it. I used gdal (you can execute gdal_translate with system from within MATLAB, which is nice). Inputs are the geotiff as saved by MATLAB, the WKT of your reference system and a world file specifiying your grid parameters.
The code could look something like this:
gcrs = geocrs(104905,"Authority","ESRI");
Rgeo.GeographicCRS = gcrs;
outfile = 'synthetic_dem.tif';
geotiffwrite(outfile, int16(Z), Rgeo); % You are sure you want to convert to integer? Geotiff can save floating point values.
wkt = wktstring(gcrs); % get the well-known text for your geocrs
fid = fopen('wkt.txt','w'); % write to file (or manually enter in gdal cli)
fprintf(fid,wkt);
fclose(fid);
worldfilewrite(Rgeo,replace(outfile,'.tif','.tfw')); % write world file with the same filename (this is how gdal will find it)
% Run gdal_translate from MATLAB (Windows)
gdalCommand = sprintf("gdal_translate -a_srs %s -of GTiff %s %s",'wkt.txt',outfile,'synthetic_dem_fixed.tif');
[status, cmdout] = system(gdalCommand);
% Reload
[Z,R] = readgeoraster('synthetic_dem_fixed.tif'); % R.GeographicCRS should now have the correct object
Note: If you are on Windows and have installed gdal via conda you will have to activate the conda environment first in the command.
4 Comments
Jacob Halbrooks
on 20 Nov 2025 at 22:18
The number 9102 means degrees, as indicated in the angular units section of the GeoKey field names page here.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!