I have an SVG map (called "external map" hereafter) representing a portion of the globe ; along with a map of the globe ("background map") in its entirety. I would like to be able to detect what projection the external map uses (my final aim being to superimpose the two maps). For the moment I only consider the Mercator, equirectangular and orthographic projections.
I developed a code that shows the two maps (external on the left, background on the right) and allows the user to drag/zoom on the background map and choose one of these projections (link). If I manually fiddle with these properties I conclude that the external map was probably created using the Mercator projection ; but how could I have found this result programmatically ? I thought about the following algorithm :
- Ask the user to choose, say, 5 points that he would geolocalize on both maps.
- Calculate the (pixel-based) distances between each of the 5 points on the external map.
- For each projection :
- Center and scale the background map using the coordinates of the 5 points that the user located on the background map.
- Calculate the pixel-based distances between the 5 points on the background map. Compare them with the distances calculated on step 2. The projection with the smallest distance differences is then considered to be the one that was used to create the external map.
This algorithm raises several questions :
- On step 3, how can I calculate the center of the map using the located points ? The projections are often distorted, so using proportionality to find it doesn't seem right.
- For the same reasons, I don't know how I could determine the scale (zoom) to apply on the background map.
This algorithm seems quite natural but the issues I raise make it look impossible to implement. Are there other (better) algorithms that could help me determine this projection ? If I can find it manually there must be a way to find it programmatically !
I use d3 for the map rendering if it helps.