Skip to content

Using latitude and longitude with a non north image

Mike edited this page Feb 29, 2016 · 2 revisions

By https://github.com/snacky6

Hello moagrius,

First of all I don't know if it's the best place to post this but anyway, I think it can help some people facing the same issue.

I had some troubles using defineRelativeBounds with a map not north-up oriented so I decided to do some research and I finally came up with a formula to convert latitude/longitude coordinates to pixels. The only things you need is the size of your map, the degree of rotation (from north) and two reference points (top left and bottom right).

Here it is:

formule_en

To find the degree of rotation and the reference points I used an image editing software and I overlaid my map with a satellite view from google maps (north-up oriented obviously). Here's the tricky part: you need to find the most precise position for the reference points (and it's not that easy...).

calc_carto

Anyway, I use it on a very large map (35000x4500px, 4 kilometers long) and it's works pretty well. Feel free to improve it (for example try to avoid the reference points).

Clone this wiki locally