12

Is there a service available for exporting georeferenced OpenStreetMap (OSM) maps in the GeoTiff format?

3 Answers 3

10

There is no service or readily available tool that I can think of. But if you are comfortable on the command line and willing to spend some time tinkering, here is a way that can work

  1. Download the OSM shapefile.
  2. Import the shapefile to TileMill..
  3. Once you style it, export it as a georeferenced PNG.

    • The following command should work once you have installed nik2img; it will produce a PNG and matching world file from your TileMill export: nik2img.py <TileMill export name>.xml <desired file name>.png -d <pixel width> <pixel height> --srs <desired projection, probably 900913> --bbox <bounding box parameters> -v -w pgw
  4. Use gdal_translate to convert it to a GeoTIFF.

    • The following command should work: gdal_translate -of GTiff -a_srs <desired projection, probably EPSG:3857, as above> <desired file name>.png <desired file name>.tiff
1
  • Has anyone done this? I've gotten as far as producing the PNG + world file, but cannot work out how to get gdal_translate to use the world file. It looks like as of version 0.6, nik2img is supposed to produce GeoTIFF directly, but it does not appear to in my testing.
    – Phoebe
    Commented Feb 8, 2014 at 0:54
2

I don't know of a tool either. If you aren't comfortable at the command line, I'd download the data from OSM, load into a desktop GIS and export a GeoTiff OR use QGIS with this plugin and then create an empty Geotif for the area you are interested in and then see if you can merge the data down into the empty file. I haven't tried that in QGIS, but with some work it should be possible. You'll want to check the licensing terms for OSM before doing that.

1
  • If you save the current QGIS view as a PNG image you also get a world file, meaning a GeoTIFF is only a quick gdal_translate conversion away....
    – Spacedman
    Commented Mar 10, 2015 at 8:14
0

I assume you have your basic stylesheet and the relevant hillshading already set up - otherwise see the github page for your stylesheet (e.g. https://github.com/hotosm/HDM-CartoCSS)

#!/usr/bin/python

from datetime import datetime
from subprocess import call

import ConfigParser
import math
import dateutil.tz

roughLatRadius = 110574
roughLonRadius = 111111

description = 'Generated from OSM data - unknown date'
copyright = '(C) OpenStreetMap contributors, see http://www.openstreetmap.org/copyright'

def getDimensions(lon, lat, geosize, scale):
    latDims = geosize * roughLatRadius / scale
    lonDims = geosize * math.cos(math.radians(lat)) * roughLonRadius / scale
    return str(int(math.ceil(lonDims))) + " " + str(int(math.ceil(latDims)))

def renderOneImage(lon, lat, geosize, scale):

    dims = getDimensions(lon, lat, geosize, scale)

    extent = str(lon) + " " + str(lat) + " " + str(lon + geosize) + " " + str(lat + geosize)
    output_file = "osm_hot_" + extent.replace(" ", "_") + "_" + str(scale) + "m" + ".tif"
    temp_file = "temp.png"

    now = datetime.utcnow().replace(tzinfo=dateutil.tz.gettz('UTC')).isoformat()
    print "Generating", output_file

    call("nik2img.py --format=RGB24 --world-file=pgw --mapnik-version=1 --dimensions " + dims + " --srs=4326 --no-open --bbox " + extent + " osm_hot_style.xml " + temp_file, shell=True)

    call('gdal_translate -a_srs EPSG:4326 -q -mo "TIFFTAG_ARTIST=WhoEver" -mo "TIFFTAG_IMAGEDESCRIPTION=' + description + '" -mo "TIFFTAG_COPYRIGHT=' + copyright + '" -mo "TIFFTAG_DOCUMENTNAME=OSM Humanitarian Style map - ' + str(scale) + 'm per pixel" -mo "TIFFTAG_DATETIME=' + now + '" ' + temp_file + " " + output_file, shell=True)

def makerange(start, end, step):
    while start < end:
        yield start
        start += step

def renderImages(min_x, min_y, max_x, max_y, stepsize, scale):
    for lon in makerange(min_x, max_x, stepsize):
        for lat in makerange(min_y, max_y, stepsize):
            renderOneImage(lon, lat, stepsize, scale)

if __name__ == '__main__':
    config = ConfigParser.ConfigParser()
    config.read('osm.cfg')
    description = 'Generated from OSM data as of ' + config.get('Metadata', 'ExtractDate', 0)
    copyright = config.get('Metadata', 'CopyrightStatement', 0)
    for scale in ['100', '50', '20', '10', '5', '2', '1', '0.5']:
        for entry in config.items(scale):
            (entry_name, entry_value) = entry
            (min_x, min_y, max_x, max_y, stepsize) = entry_value.split(',')
            renderImages(float(min_x), float(min_y), float(max_x), float(max_y), float(stepsize), float(scale))

The configuration file (osm.cfg) looks like:

[Metadata]
ExtractDate: 2015-03-05T21:21:02Z
CopyrightStatement: (C) OpenStreetMap contributors, see http://www.openstreetmap.org/copyright

[100]
# around 2 degree steps are good at 100 metres
phillipines: 118, 4, 127, 20, 2


[50]
# around 1-2 degree steps are good at 50 metres
phillipines: 118, 4, 127, 20, 1

[20]
# around 0.5 to 1 degree steps are good at 20 metres
samar: 124, 11, 126, 13, 0.5
northwest: 120, 12.4, 124.5, 14.5, 0.5
northofmanila: 120, 14.5, 122.4, 19.6, 0.5


[10]
# roughly 0.4 degree steps are sane at 10 metres

[5]
# around 0.2 degree steps are good at 5 metres

[2]
# around 0.1 degree steps are good at 2 metres
guiuan: 125.5, 10.9, 125.8, 11.1, 0.1
tacloban: 124.8, 11.1, 125.1, 11.4, 0.1
legazpi: 123.5, 13.1, 123.8, 14.5, 0.1
manila: 120.8, 14.2, 121.2, 14.7, 0.1
subicbay: 120.1, 14.7, 120.4, 15.0, 0.1

[1]
# around 0.05 degree steps are good at 1 metre

[0.5]
# around 0.02 degree steps are good at 0.5 metres
tacloban: 124.8, 11.1, 125.1, 11.4, 0.02

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.