# How to tile Mars themis raster for Cesium

**URL:** <https://community.cesium.com/t/how-to-tile-mars-themis-raster-for-cesium/10356>\
**Category:** CesiumJS\
**Created:** [July 26, 2020, 2:24pm UTC](https://community.cesium.com/t/how-to-tile-mars-themis-raster-for-cesium/10356 "2020-07-26T14:24:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![semper](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/semper/32/2793_2.png) [@semper](https://community.cesium.com/u/semper)\
**Post date:** [July 26, 2020, 2:24pm UTC](https://community.cesium.com/t/how-to-tile-mars-themis-raster-for-cesium/10356/1 "2020-07-26T14:24:40Z")

</div>

I am trying to tile the Mars [themis](https://astrogeology.usgs.gov/search/map/Mars/Odyssey/THEMIS-IR-Mosaic-ASU/Mars_MO_THEMIS-IR-Day_mosaic_global_100m_v12) raster that has the following crs:

```auto
PROJCS["SimpleCylindrical Mars",
    GEOGCS["GCS_Mars",
        DATUM["D_Mars",
            SPHEROID["Mars",3396190,0]],
        PRIMEM["Reference_Meridian",0],
        UNIT["degree",0.0174532925199433]],
    PROJECTION["Equirectangular"],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",180],
    PARAMETER["standard_parallel_1",0],
    PARAMETER["false_easting",0],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]]]

```

The `--profile` option in `gdal2tiles` can be `geodetic`, `mercator` or `raster`. Given the projection of the input raster above, I tile the raster as follows:

```auto
gdal2tiles.py --zoom=0-7 --profile raster input.tif output/

```

However, Cesium.js is unable to consume these tiles because it only supports a tiling scheme of either `geodetic` or `mercator`.

Is there a workaround? I was wondering if someone could kindly point me in the right direction.

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [July 26, 2020, 4:52pm UTC](https://community.cesium.com/t/how-to-tile-mars-themis-raster-for-cesium/10356/2 "2020-07-26T16:52:19Z")

</div>

Normally the easiest way is to just upload your imagery to Cesium ion ([https://cesium.com/ion](https://cesium.com/ion)) which will handle reprojecting and tiling. In this case it looks like the Mars spatial reference isn’t supported at the moment, I get:

```auto
Error: Invalid spatial reference system
File: Mars.tif
Spatial Reference System: PROJCS["SimpleCylindrical Mars",GEOGCS["GCS_Mars",DATUM["D_Mars",SPHEROID["Mars",3396190,0]],PRIMEM["Reference_Meridian",0],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]]],PROJECTION["Equirectangular"],PARAMETER["standard_parallel_1",0],PARAMETER["central_meridian",180],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH]]

```

So you may need to reproject it to something else.

What happens when you pass `--profile mercator` ?

An example that may be helpful to look at is this [Sandcastle showing lunar terrain and imagery](https://sandcastle.cesium.com/index.html#c=zVdtb9s2EP4rRL7Y7hzKsp3ESbNuSZqmxtwkaNwWxTwEtHS2uFCkQNJ23SH/fUdRtizba74M2IwAiu6Nx7vnXjRnmoAQPDOKx+RnImFBrsDwWUqvV+R6eNI56bZaza1n4/VIjuS2NP1y89Droqm1WRSb4zEpy+61+hMiy5WsHnUDaqpZlvColKiv9f05zsRUqDFsqTpSVTaXoiZRixutZjK+sKkyWQLaqU6YMPCaBAEaicAYppdkojSxXIAhVhGnR7gkUslDYNom5UVWpmPIbDIEYy+mjEtjh6A1/oPWrZ5BcV3riXihOY9BV732j2FVpP7XSBL8zbQ4I7XE2sycBcHEOUZZZKfMAo1UGhSWAzGTTD9ORRy2WrWm1137erbp9nMZQpVZg74UR1VyclZ9LSzmVz7zj4K0dbWzbUIhZp6WZejPfOSbzg/HxAS8R1kyk2UePvULRRDehb6MecSs0qW244+ZgQFbgr7n0RNsMS1PQXAJVeoUVKTibVkuJ+pSfasSTQQSPqDwPutM8pT5YOVkT8UIrwM857DYTvfnnFavRfn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0194id0i4uzW0n1aWdk5P26a7QH3ua2OYvCKp52UHw6rcoWs7RHl7qQsuZqCL0vgjTne9ZHwoh3AQyLMBlfU/s/rGf3n28uL25bu7X2GqK7R+L/XNd76o9N6q05/K1wP8L6H9I1EzguARXW5krgxypxu2pJSgXzA2bMQ5ft/sDw0EscYj6CWry4YxVmVeCsv+XCpgqub8AEo5e6ShZ7mf/OzVS1kqHhp3jo64f3q2T3lGv+SPxNj3tnXTbvrSOT3rtoxfEw+Pj3rEX7522wpes41dsJyw2iePj0x9b3/V9v/QfjT3Y/HEhbsH70zVdcJtciCxh9RY9ehHYBQrc+jdU9S1MNF4fNA/OjV0KeOM1f+VpprR1e32dUvygxFUQnTHBeIafPJZGJv8oOQ9WSucxnxMe/zw62PqEGR24UWEMcia4hLmVaXTw5hxn2ryiJhRzU/EOpzx+ITiRJHwz8ERK6XmAr7tauMaKMa6lpcW/AQ). This is from this forum discussion: [Clamping To Terrain on Lunar globe](https://community.cesium.com/t/clamping-to-terrain-on-lunar-globe/7977). It looks like the WMS imagery of the lunar surface in this example is served as EPSG:4326.

---

<div class="post-metadata">

**Author:** ![semper](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/semper/32/2793_2.png) [@semper](https://community.cesium.com/u/semper)\
**Post date:** [July 27, 2020, 8:23am UTC](https://community.cesium.com/t/how-to-tile-mars-themis-raster-for-cesium/10356/3 "2020-07-27T08:23:22Z")

</div>

Hi Omar,

Thank you so much for getting back to me. We wish to utilize the Ion offering further down the road once we have a working prototype.

I have now projected the original raster to `EPSG4326` and applied `--profile mercator` while tiling. Based on your suggestions, I now instantiate the `Cesium.Viewer` as follows:

```auto
var ellipsoid = new Cesium.Ellipsoid(3396190,3396190,3396190);

Cesium.Ellipsoid.WGS84 = ellipsoid;
var mapProjection = new Cesium.GeographicProjection(ellipsoid);

var globe = new Cesium.Globe(ellipsoid);
globe.showGroundAtmosphere = false; // necessary for tiles to show in non-earth ellipsoid
globe.depthTestAgainstTerrain = true;

var opts = {
    mapProjection: mapProjection,
    globe: globe,
    skyAtmosphere: false,
 
    imageryProvider: new Cesium.createTileMapServiceImageryProvider({
       url : 'http://localhost:8080/epsg4326',
       fileExtension : 'png',
       ellipsoid: ellipsoid
    }),
};

```

Cesium now recognizes the tiles, however, there are holes at the poles, which is not unexpected. Is there a way to extend the coverage further toward the poles? I also see a blue streak – likely at 0 longitude – that I am not too sure how to get rid of.  
Any tips to resolve these issues would be fantastic and thank you so much again for your help.

 ![2020-07-27_11-25-41](https://global.discourse-cdn.com/cesium/original/2X/b/b40c3fcd50034255938a29c2687e3264e1a68bbe.jpeg)  
Cheers,  
Rakib

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [July 28, 2020, 7:05pm UTC](https://community.cesium.com/t/how-to-tile-mars-themis-raster-for-cesium/10356/4 "2020-07-28T19:05:35Z")

</div>

Yeah the gaps are occurring because of the mercator projection. I think what you’d want instead is actually the `--profile geodetic`. As far as I understand, this will use a Earth-specific projection, but this may be “close enough”, and the geographic projection should cover the entire globe with no gaps.

---

<div class="post-metadata">

**Author:** ![semper](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/semper/32/2793_2.png) [@semper](https://community.cesium.com/u/semper)\
**Post date:** [July 29, 2020, 11:21am UTC](https://community.cesium.com/t/how-to-tile-mars-themis-raster-for-cesium/10356/5 "2020-07-29T11:21:30Z")

</div>

I’ve tried `--profile geodetic` but no luck – in fact, `gdal2tiles` keels over for some reason midway through the tile generation process and needs to be relaunched in `resume` mode to complete the tile generation. However, Ceseium then fails to consume those tiles. It’s not clear to me whether the problem is with the output from `gdal2tiles` or Cesium.  
I’ve seen others use tiles in mercator projection in Cesium without the sliver artefact – could there be any other tweaks I am missing?  
Thank you so much again.

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [July 29, 2020, 9:29pm UTC](https://community.cesium.com/t/how-to-tile-mars-themis-raster-for-cesium/10356/6 "2020-07-29T21:29:46Z")

</div>

> [@semper](#):
>
> However, Ceseium then fails to consume those tiles. It’s not clear to me whether the problem is with the output from `gdal2tiles` or Cesium.

Have you tried loading this in any other viewer to narrow this down? Maybe [QGIS](https://qgis.org/en/site/) or [OpenLayers](https://openlayers.org/) etc.

I haven’t seen this sliver artifact before in CesiumJS, and I would guess it’s coming from the imagery tiles themselves, but you should be able to confirm that.

---

<div class="post-metadata">

**Author:** ![semper](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/semper/32/2793_2.png) [@semper](https://community.cesium.com/u/semper)\
**Post date:** [January 19, 2021, 4:03am UTC](https://community.cesium.com/t/how-to-tile-mars-themis-raster-for-cesium/10356/7 "2021-01-19T04:03:37Z")

</div>

I’ve managed to resolve the various issues and wanted to leave some hints that might help others:

- 
  1. Reproject a raster to **EPSG:4326** in parallel using gdal **version 3.3**

`gdalwarp -multi -wo NUM_THREADS=ALL_CPUS input.tif -s_srs EPSG:4326 -wo SOURCE_EXTRA=1000 -te -180 -90 180 90 out.tif`

`SOURCE_EXTRA` resolves the blue sliver issue (see above.). Gdal **version 3.3** is needed for parallel execution – older versions seem suboptimal.

- 
  1. Tile the reprojected raster in parallel using **version 2.4.4**

`gdal2tiles.py --zoom=0-9 --processes=10 out.tif output`

The parallel tiling functionality seems to work better in gdal **version 2.4.4**

- 
  1. The resulting tiles are then loaded in Cesium with a custom ellipsoid specified as follows:

`var ellipsoid = new Cesium.Ellipsoid(3396190,3396190,3396190); // define Mars ellipsoid Cesium.Ellipsoid.WGS84 = ellipsoid; var mapProjection = new Cesium.GeographicProjection(ellipsoid);`

---

<div class="post-metadata">

**Author:** ![Ilya\_S](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/ilya_s/32/8631_2.png) [@Ilya\_S](https://community.cesium.com/u/Ilya_S)\
**Post date:** [March 27, 2022, 2:37pm UTC](https://community.cesium.com/t/how-to-tile-mars-themis-raster-for-cesium/10356/8 "2022-03-27T14:37:49Z")

</div>

Woud love to see the result of this work!
