Reputation: 27615
A very similar question, solved the same way: how to use 'extent' in matplotlib.pyplot.imshow
I have a list of geographical coordinates (a "tracklog") that describe a geographical trajectory. Also, I have the means of obtaining an image spanning the tracklog coverage, where I know the "geographical coordinates" of the corners of the image.
My plot currently looks like this (notice the ticks - x=longitudes, y=latitudes, in UTM, WGS84):
Then suppose I know the corner coordinates of the following image (or a version of it without the blue track), and would like to plot it SO THAT IT FITS THE COORDINATE SYSTEM of the plot.
How would I do it?
(as a side note, in case that matters, I plan to use tiles)
As per the comment of Joe Kington (waiting for his actual answer so that I can accept it), the following code works as expected, giving a pannable and zoomable fixed-aspect "georeferenced" tile over which I am able to plot tracklogs:
import matplotlib.pyplot as plt
import Image
import numpy
imarray = numpy.asarray(Image.open('map.jpg'))
plt.plot([0,1], [0,1], 'o', c='red', ms=20) ## some reference circles for debugging
plt.imshow(imarray, extent=[0,1,0,1]) ## some random map whose corners have known coordinates
plt.axis('equal')
plt.show()
Upvotes: 2
Views: 4163
Reputation: 382
I solved it by taking a screenshot from some maps program and then finding out the lat/lon borders of the image. I can imshow the whole map and the use set_xlim
and set_ylim
to only show the area I want to.
Since the maps in navigation programs are plot maps in a 1km:1km aspect ratio, you have to manually set that ratio using the sinus of the latitude.
from PIL import Image
munich_map = Image.open("images/munich-map.png")
...
axis.imshow(
munich_map,
extent=[11.245921, 11.930659, 47.949627, 48.279644],
aspect=1 / math.sin(math.radians(48)),
)
axis.set_xlim(from_lon, to_lon)
axis.set_ylim(from_lat, to_lat)
Upvotes: 0
Reputation: 28868
There is really not much of an answer here, but if you are using matplotlib, and you geos-tuff, take a look at matplotlib.basemap.
By default all operations are done on UTM maps, but you can choose your own projection.
Take also a look on the list of good tutorials in http://www.geophysique.be, for example.
Upvotes: 0