Previously I described osmgnuplot, a tool to plot registered OpenStreetMap tiles in gnuplot, which makes it easy to plot georeferenced data. The tool worked just fine with a caveat: it would produce bogus plots when looking at a large geographical area. This is because the relationship between latitude and the row coordinate of the OSM image was assumed to be linear, which is not the case in reality (longitude is always linear, however).

Well, I just hit this issue in one of my projects, and have fixed the tool to lift this limitation. The latest version of the tool uses linked gnuplot axes to connect the pixel coordinates to latitude/longitude. So the image is plotted against the gnuplot x1,y1 axes, which are mapped to the latitude,longitude on the x2,y2 axes. The conversions are all handled by gnuplot, which is quite nice.

One interesting thing is that the expression I was using for the latitude-to-pixel conversion contained this subexpression:


The code update requires me to compute the inverse conversion (pixel-to-latitude), and deriving this, I need to reverse the above subexpression. I derived this inverse:


The proof is left as an exercise to the reader. If I had bothered to look it up, however, I would have found all the expressions (forward and backward) here.

The script works, and some examples will appear in an upcoming post.

There were some questions that came up in writing this, and the discussion is in this mailing list thread.