OSM Globes

Most web maps are Spherical Mercator, and as xkcd #977 tells is, a globe is a very clever. So let's see how to make images of globes with OpenStreetMap.org tile server. The OSM.org have a Tile Usage Policy which you must follow. Don't blame me if you get in trouble.

The page is based on GDAL's WMS documention, and their example OSM tiles file.

Begin

Create this file and call it frmt_wms_openstreetmap_tms.xml.

<GDAL_WMS>
    <Service name="TMS">
        <ServerUrl>https://tile.openstreetmap.org/${z}/${x}/${y}.png</ServerUrl>
    </Service>
    <DataWindow>
        <UpperLeftX>-20037508.34</UpperLeftX>
        <UpperLeftY>20037508.34</UpperLeftY>
        <LowerRightX>20037508.34</LowerRightX>
        <LowerRightY>-20037508.34</LowerRightY>
        <TileLevel>18</TileLevel>
        <TileCountX>1</TileCountX>
        <TileCountY>1</TileCountY>
        <YOrigin>top</YOrigin>
    </DataWindow>
    <Projection>EPSG:3857</Projection>
    <BlockSizeX>256</BlockSizeX>
    <BlockSizeY>256</BlockSizeY>
    <BandsCount>3</BandsCount>
    <UserAgent>OSM USERNAME HERE making tiles for globes</UserAgent>
    <Cache />
</GDAL_WMS>

download that file. (If you get ERROR 1: Parse error at EOF, not all elements have been closed, starting with UserAgent, you need to edit the file and put in your OSM Username)

The trick is to the use orto projection.

gdalwarp -dstalpha -ts 200 200 -t_srs "+proj=ortho" frmt_wms_openstreetmap_tms.xml globe-200-null-island.tiff

And when you convert the GeoTiff file to PNG (which gdal cannot output), you get this image:

I'm not sure why there's the bug at the equator. (And tips?)

This image is centred on (0, 0), (“Null Island”), you can change it with the +lat_0=X +lon_0=Y. Here's South America:

This globe is boring, because it's only zoom 0, because of the small size. Large resolution and it'll use larger tiles:

gdalwarp -dstalpha -ts 5000 5000 -t_srs "+proj=ortho +lat_0=-19 +lon_0=-59" frmt_wms_openstreetmap_tms.xml globe-5000-sth-am.tiff

Making this image, which has more details

The south (& north) pole is empty because the web mercator system used for tiles doesn't go there. You'll have to fill it in yourself.

Cropping

The ortho projection has these bounds (from gdalinfo $FILENAME):

Corner Coordinates:
Upper Left  (-6378137.000, 6377856.534) 
Lower Left  (-6378137.000,-6377749.531) 
Upper Right ( 6378137.000, 6377856.534) 
Lower Right ( 6378137.000,-6377749.531)

To include the top left quadrant include this option: -te -6378137 0 0 6354359.791. Less tiles will be downloaded.

gdalwarp -te -6378137 0 0 6354359.791 -dstalpha -ts 500 500 -t_srs "+proj=ortho +lat_0=30 +lon_0=70" frmt_wms_openstreetmap_tms.xml globe-europe-top-left.tiff

Satellite views

The ortho projection shows the Earth from an infinite distance, so it's quite "zoomed out". The tpers projection shows the view from some height from the surface.

gdalwarp -dstalpha -ts 1000 1000 -t_srs "PROJCS[\"satellite\", GEOGCS[\"satellite\"], PROJECTION[\"satellite\"], EXTENSION[\"PROJ4\",\"+proj=tpers +lon_0=100 +lat_0=0 +h=1e7\"]]" frmt_wms_openstreetmap_tms.xml globe-zoom-1e7.tiff

Produces this image which should be 1e8 m above the surface (about 100,000 km):

Play around with the parameters.

Further reading

This entry is tagged: