If I understand you correctly, what you want to do is re-project an existing equirectangular map to have the pole(s) in a different location—and your title question (“transfer onto a globe and back”) is how you think this might be done, not something that’s absolutely mandatory. Am I right?
That is, would something that can do the re-projection without ever showing you a globe suit you? Because there’s software that can do it for you. Two options are the Cartopy cartography library for Python, and the G.Projector tool from NASA that uses Java.
My evaluation so far: Cartopy gives better results, but is more fiddly to install and use. G.Projector is more straightforward. I’ll go through steps for both.
Here’s a world map I’ll use to demonstrate. It’s not much of a map, but it will do for our purposes.
We’re going to re-project it so that the new poles are on what’s currently the equator—the north pole will lie on that big landmass to the left (0°N 135°W), and the south pole on the smallest landmass in the cluster of three in the centre (0°N 45°E). But the methods shown will be fully adaptable to wherever you want your poles to be.
Installation
Unfortunately neither of these were particularly straightforward for me to install or run. Maybe you’ll have better luck?
Cartopy
- Install Miniconda.
- Assuming without loss of generality that you’re on Windows, open the Anaconda Prompt that should now be on your Start Menu.
- Type in
conda install -c conda-forge cartopy
and hit Enter.
I haven’t tested this method, but it should work? (I already have Python on my computer, but not through Anaconda, so I first tried installing Cartopy through pip… ★☆☆☆☆ Do Not Recommend. It’d probably go better on Linux than on Windows, but the Windows machine is what I had at the time!)
G.Projector
- Install Java.
- Download G.Projector and extract it wherever you like.
- Again assuming you’re on a Windows computer, double-click on
G.Projector.exe
in the folder you just extracted. After a delay, you should get a file chooser window.
(Give it time, and if you’ve got other programs open, Alt+Tab between your windows occasionally. I thought it hadn’t worked, and I ended up fiddling around and finding a way to open it manually, only to find while writing this up that it had opened in the background without a taskbar icon. If it doesn’t work, let me know and I’ll share the steps I took to open it.)
Running Cartopy
- Copy this short script into a text file and save it as
reproject.py
in the same place as your image.
- Change the filenames
notmuchofaworldmap.png
and stillnotmuchofamap.png
to be your existing image, and a new name for your re-projected image, respectively.
- Also change the numbers for
pole_longitude
and pole_latitude
, and for figsize
, to whatever you want.
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
# The image starts in a PlateCarree (equirectangular) projection, taking up
# the entire globe…
img_projection = ccrs.PlateCarree()
img_extent = (-180.0, 180.0, -90.0, 90.0)
# …but we draw the map in a RotatedPole projection. Set the pole location to
# suit yourself.
map_projection = ccrs.RotatedPole(pole_longitude=45.0, pole_latitude=0.0)
# Load the image.
img = plt.imread("notmuchofaworldmap.png")
# Create a new map at a size of 720×360 pixels @ 100dpi (the default for
# matplotlib). I chose these sizes because this is how big I made my sample
# map; change them to suit your image.
fig = plt.figure(figsize=(7.2, 3.6), frameon=False)
fig.tight_layout(pad=0)
ax = plt.axes(projection=map_projection, frame_on=False)
ax.set_global()
ax.imshow(img, origin="upper", transform=img_projection, extent=img_extent)
# Save the result!
plt.savefig("stillnotmuchofamap.png", bbox_inches="tight", pad_inches=0)
- In the Anaconda Prompt that you still have open from before, navigate (with
cd
) to the location of your image and the script.
- Type
python reproject.py
and hit Enter.
Here’s the result of running this on the sample map.
It ain’t pretty, though that’s mostly because my original map was so low-quality. There will be distortion, but at the very least, it’ll show you how it should look, and you can take steps to tidy up from there!
One thing I haven’t quite gotten right yet is making the result have the same dimensions as the original. A decent chunk of the code up there is just to get it to stop putting borders and padding around everything, which is apparently not easy! And it still comes out to 22.5% smaller than the original. This may be a side effect of the re-projection process, but I don’t see why it should be. A crude solution would be to make the output bigger…
Running G.Projector
- In the file chooser that opened up previously, find and open your image. Confirm that the default import options (equirectangular, −180° to 180° longitude, −90° to 90° latitude) are correct and click “Okay”.
- In the Projection dialog that’s open by default, change the projection to “Equirectangular (Oblique)”, and change the “Centered on” position to whatever you choose.
- As the name suggests, “Centered on” sets the centre of the map, not the pole location like we did with Cartopy.
- If, as in my example, you want the (old) north pole to be at the centre, then the latitude will be 90°. The longitude you choose will point up from there, towards the new north pole (so -135° in my example).
- On the Window menu, open the Graticule dialog and change Stroke to “None”. Likewise, open the Overlay dialog and change it to “<none>”.
- On the File menu, use “Save map as...” to save the re-projected result, choosing whatever image dimensions you want (probably the same as the original image).
Here’s what I got:
This is even less pretty than the Cartopy version. But it did the job!