Smopy example

Smopy lets you retrieve OpenStreetMap image maps from geographical coordinates.

In [2]:
import smopy
%matplotlib inline

Define a Map object by giving the boundaries of your map: (lat_min, lon_min, lat_max, lon_max). Creating this object fetches the image from OpenStreetMap's servers (see usage policy).

In [3]:
map = smopy.Map((48., -1., 52., 3.), z=4)

In the IPython notebook, you can display the image directly with show_ipython.

In [4]:

You can also save it as a PNG file.

In [5]:
from IPython.display import Image

We can omit the zoomlevel, to automatically determine a maximum zoomlevel (based on a reasonable number of maximum OSM tiles:

In [6]:
map = smopy.Map((49., -1., 52., 3.))
Lowered zoom level to keep map size reasonable. (z = 7)

Zooming out, by manually setting the zoom level:

In [7]:
map = smopy.Map((49., -1., 52., 3.), z=6)

Now, you can create a matplotlib figure from this image. The Map object comes with a to_pixels method to convert from geographical coordinates to pixels in this image.

In [8]:
x, y = map.to_pixels(48.86151, 2.33474)
In [9]:
ax = map.show_mpl(figsize=(8, 6))
ax.plot(x, y, 'or', ms=10, mew=2);