I am trying to create my own XYZ tiles to use them with OpenLayers 3 as my local tiles. On this example you can see the objective/idea.

I want to use the NASA Blue Marble Earth Visible maps, as an example this one from July 2004

On the readme PDF it says that the image is on projection datum WGS84. So the as we know this projection bounds are on EPSG:4326.

I georeference the image on this way.

gdal_translate -of GTiff -a_srs EPSG:4326 -a_ullr -180 90 180 -90 world.topo.bathy.200407.3x5400x2700.jpg world.topo.bathy.200407.3x5400x2700.tif

The information of the new generated GeoTIFF can be checked with:

$ gdalinfo world.topo.bathy.200407.3x5400x2700.tif
Driver: GTiff/GeoTIFF
Files: world.topo.bathy.200407.3x5400x2700.tif
Size is 5400, 2700
Coordinate System is:
        SPHEROID["WGS 84",6378137,298.257223563,
Origin = (-180.000000000000000,90.000000000000000)
Pixel Size = (0.066666666666667,-0.066666666666667)
Image Structure Metadata:
Corner Coordinates:
Upper Left  (-180.0000000,  90.0000000) (180d 0' 0.00"W, 90d 0' 0.00"N)
Lower Left  (-180.0000000, -90.0000000) (180d 0' 0.00"W, 90d 0' 0.00"S)
Upper Right ( 180.0000000,  90.0000000) (180d 0' 0.00"E, 90d 0' 0.00"N)
Lower Right ( 180.0000000, -90.0000000) (180d 0' 0.00"E, 90d 0' 0.00"S)
Center      (   0.0000000,   0.0000000) (  0d 0' 0.01"E,  0d 0' 0.01"N)
Band 1 Block=5400x1 Type=Byte, ColorInterp=Red
Band 2 Block=5400x1 Type=Byte, ColorInterp=Green
Band 3 Block=5400x1 Type=Byte, ColorInterp=Blue

As I want to create XYZ tiles with OpenLayers 3, checking the documentation, I see I need to warp the projection from EPSG:4326 to EPSG:3857, which I do with:

gdalwarp -s_srs EPSG:4326 -t_srs EPSG:3857 world.topo.bathy.200407.3x5400x2700.tif Marble_3857.tif

The problem is that the shape of this final image is (4009 x 4514) so it is not square which should be for XYZ tiles.

I have seen from MapTiler this example that uses that map which is already tiled in 256px tiles, something similar to what I want.

First of all, I have no square shape image projection so I cannot make tiles. And secondly, how can I make different zoom level tiles (zoom till 8 level)? Is there any tool on GDAL for that? I tried gdal2tiles but does not work with following command:

gdal2tiles.py --s_srs EPSG:3857 --zoom 0-3 -p 'raster' Marble_3857.tif


Following the answer of AndreJ it mostly seems to work. First I used gdal_translate as mentioned:

gdal_translate -of GTiff -a_srs EPSG:4326 -a_ullr -180 90 180 -90 world.topo.bathy.200407.3x5400x2700.jpg world.topo.bathy.200407.3x5400x2700.tif

Then, before gdal2tiles, as I am using Ubuntu I had to change something on the python code as mentioned here to avoid errors on projection.

After that, I could run the command of AndreJ:

gdal2tiles.py --s_srs EPSG:4326 --zoom 0-5 world.topo.bathy.200407.3x5400x2700.tif ./tiles

But the result is quite strange because it leaves a transparency column on the right on all the zoom levels... (can be checked downloading the below picture)

Which can be the reason? The modified code? Any option I should define?


2 Answers 2


There is no need to reproject the raster. This one worked for me:

gdal2tiles --s_srs EPSG:4326 --zoom 0-5 bluemarble.tif D:\Tiles\bluemrble

gdal2tiles automatically cuts off the pole areas at 85.0511 degrees to get a square output at zoom level 0:

enter image description here

  • AndreJ, I tried with the JPG image that I linked and I suppose that I first have to reference it with gdal_translate as I mentioned and the do what you said? Becase it gives me errors of, "ERROR 6: EPSG PCS/GCS code 900913 not found in EPSG support files. Is this a valid EPSG coordinate system?" and "ERROR 5: Illegal values for buffer size". Which version of gdal2tiles are you using? I see that you are no using the Visible Earth NASA image, could be that a difference for working on your computer?
    – iblasi
    Commented Jul 28, 2016 at 17:20
  • I have checked that you used the NASA Visible Earth image but this one: visibleearth.nasa.gov/view.php?id=57752 which has directly the TIFF files. I want to use the one that I put as an example which is not georeferenced due to the colors for a specific project. And I have check your command and does not work for me neither :(
    – iblasi
    Commented Jul 28, 2016 at 17:29
  • The gdal_translate command was ok. Then you can use gdal2tiles. At the time, EPSG:900913 was a valid EPSG code, now it is replaced by EPSG:3857.
    – AndreJ
    Commented Jul 28, 2016 at 18:10
  • I edited my question due to a strange behaviour making the tiles that leaves a transparent column on the right on all zoom levels. The version used is "GDAL 1.11.3, released 2015/09/16". Could be that the reason?
    – iblasi
    Commented Jul 28, 2016 at 18:29
  • I used GDAL 1.8 initially, and GDAL 2.1.0 now (both on Windows), without a transparent column. Maybe you could try another resampling method.
    – AndreJ
    Commented Jul 29, 2016 at 8:50

I have prepared ESRI World files for the Nasa Blue marble dataset: https://gist.github.com/klokan/b654b18367f372d58c58

If you place them next to the downloaded files they will get correct geolocation automatically.

MapTiler (http://www.maptiler.com) will generate the correct map tiles for you directly after you drag&drop the files into the user interface. It has also available command line interface for automation and installers for all different platforms like Windows, Mac OS X, various Linux distributions and Docker.

A free demo of MapTiler Pro is available at http://www.maptiler.com/demo/.

MapTiler is most efficient when you supply the individual input files directly - so do not make any preprocessing or merging in advance.

If you want to use open-source GDAL library tools you would probably first need to merge the individual input files into one VRT (with gdalbuildvrt), then reproject correctly (with gdalwarp) into the exact extent of the Spherical Mercator, then tile with my student project gdal2tiles.py. The result would be png or jpg tiles which may need size optimisation with pngnq or similar utility.

MapTiler is doing internally similar steps, but more efficiently and significantly faster. It also automatically handle dateline crossing datasets, is able to run on cluster and is easy to install and use and regularly updated. Try it and you will see! ;-)

Disclaimer: I am the original author of gdal2tiles.py, MapTiler and I have also rendered the tiles used in the jsfiddle example mentioned in the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.