How to draw a png-osm map with coordinates

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

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

+6
source share
2 answers

This is not my decision; I put it in the question, because the iser does not have enough reputation to answer his own question.

I found a solution:

Using imshow inside the imshow includes png in the graph as an image in the background. To get the correct background image, I used the OSM export function with borders taken from the base map 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') 
+2
source

I found some available basemap images from a NASA GIBS server. You may be able to use the same method for other developers.

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

Thi uses GDAL 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() 

To do this, you need the TERRA.xml file from the link above, although you can also embed XML.

+2
source

Source: https://habr.com/ru/post/915907/


All Articles