是否有用于以GeoTiff格式导出地理参考OpenStreetMap(OSM)地图的服务?


Answers:


10

我没有想到的服务或现成的工具。但是,如果您在命令行上很舒服并且愿意花一些时间进行修补,那么这是一种可行的方法

  1. 下载OSM shapefile。
  2. 将shapefile导入TileMill。
  3. 设置样式后,将其导出为地理参考PNG

    • 安装nik2img后,以下命令应该可以使用;它将从TileMill导出中生成PNG和匹配的世界文件: 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. 使用gdal_translate将其转换为GeoTIFF。

    • 以下命令应该起作用: gdal_translate -of GTiff -a_srs <desired projection, probably EPSG:3857, as above> <desired file name>.png <desired file name>.tiff

有人这样做吗?我已经制作了PNG +世界文件,但无法弄清楚如何使gdal_translate使用世界文件。看起来好像从0.6版本开始,nik2img应该直接产生GeoTIFF,但是在我的测试中却没有。
Z O.

2

我也不知道工具。如果您不习惯使用命令行,则可以从OSM下载数据,加载到桌面GIS中,然后导出GeoTiff或对该插件使用QGIS,然后为感兴趣的区域创建一个空的Geotif,然后看看是否可以将数据合并到空文件中。我没有在QGIS中尝试过,但是通过一些工作,它应该是可能的。在执行此操作之前,您需要检查OSM的许可条款。


如果将当前QGIS视图另存为PNG图像,您还将获得一个世界文件,这意味着GeoTIFF只是gdal_translate快速转换而已....
Spacedman 2015年

0

我假设您已经设置了基本样式表,并且已经设置了相关的阴影-否则,请参见样式表的github页面(例如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))

配置文件(osm.cfg)如下所示:

[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
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.