Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a png-osm-map with coordinates

I want to create a map with several given points in Python. For this I want to use Basemap from matplotlib. It works well, but I don't know how to get a proper background map.

How can I import an OSM map? Or should I use a different mapping package? I just want to create a raster map and save it as png.

like image 700
teGuy Avatar asked May 16 '12 12:05

teGuy


2 Answers

This not my solution; I have pasted it from the question because the asker doesn't have enough reputation to answer his own question.

I found a solution:

Using imshow within Basemap includes an png into the plot as background image. To obtain the right background image, I used the export feature of OSM with boundaries taken from the Basemap constructor:

m = Basemap(llcrnrlon=7.4319, urcrnrlat=52.0632, urcrnrlon=7.848, llcrnrlat=51.8495,
        resolution='h', projection='merc')

im = plt.imread('background.png')
m.imshow(im, interpolation='lanczos', origin='upper')
like image 95
Ramchandra Apte Avatar answered Oct 20 '22 23:10

Ramchandra Apte


I found some accessible basemap imagery from NASA GIBS tileserver. You might be able to use the same method for other tileservers.

http://earthdata.nasa.gov/wiki/main/index.php/GIBS_Supported_Clients#Script-level_access_to_imagery

Thi Uses GDAL's gdal_translate in a python subshell:

import subprocess
import matplotlib.pyplot
import mpl_toolkits.basemap

l,u,r,d=(7.4319,52.0632,7.848,51.8495)

subprocess.call ('gdal_translate -of GTiff -outsize 400 400 -projwin {l} {u} {r} {d} TERRA.xml Background.tif'.format(l=l,u=u,r=r,d=d),shell=True )

im=matplotlib.pyplot.imread('Background.tif')

m = mpl_toolkits.basemap.Basemap(llcrnrlon=l, urcrnrlat=u, urcrnrlon=r, llcrnrlat=d,
    resolution='h', projection='merc')
m.imshow(im, interpolation='lanczos', origin='upper')

matplotlib.pyplot.show()

This needs the TERRA.xml file from the above link, though you can inline the XML as well.

like image 20
Dave X Avatar answered Oct 20 '22 22:10

Dave X