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).
map = smopy.Map((48., -1., 52., 3.), z=4)
In the IPython notebook, you can display the image directly with show_ipython
.
map.show_ipython()
You can also save it as a PNG file.
from IPython.display import Image
map.save_png('europe.png')
Image('europe.png')
We can omit the zoomlevel, to automatically determine a maximum zoomlevel (based on a reasonable number of maximum OSM tiles:
map = smopy.Map((49., -1., 52., 3.))
map.show_ipython()
Lowered zoom level to keep map size reasonable. (z = 7)
Zooming out, by manually setting the zoom level:
map = smopy.Map((49., -1., 52., 3.), z=6)
map.show_ipython()
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.
x, y = map.to_pixels(48.86151, 2.33474)
ax = map.show_mpl(figsize=(8, 6))
ax.plot(x, y, 'or', ms=10, mew=2);
The to_pixels
method also works with NumPy arrays, so you can really plot anything on your map (lines, curves, polygons, patches).