# How can I convert geomagnetic coordinates to geographic coordinates without doing the math myself?

I have some data which are in geomagnetic coordinates; that is, they are latitude and longitude, but in reference to the magnetic north pole in Canada rather than the geographic north pole. As you might guess, I'd like to match them to other data which are in other coordinate systems.

(The data originated as a computation of the auroral oval; i.e., they originated as geomagnetic and there is no geographic source I could consult, even in principle.)

The data will be stored in PostGIS.

The easy way to do this is to find an EPSG code for the geomagnetic coordinate system, tag the data with that code, and then everything is magically reprojected to whatever I need at the time. However, I can't find any EPSG codes on spatialreference.org containing either geomagnetic or magnetic. Various Google searches also turn up nothing.

For the level of precision I need, any latitude/longitude coordinate system (e.g., WGS84) modified to have a different north pole is good enough. So if there's an easy way to define such a coordinate system and load it into PostGIS, that would be OK too.

Clarification

For example, suppose that instead of converting from geomagnetic coordinates to geographic, I simply wanted to convert from UTM 15N to WGS84. I could save the UTM object into PostGIS unmodified, and tag it with the EPSG code 26915. Then, when I later made a query, I could say to PostGIS, "please return results in EPSG code 4326", and PostGIS would convert to WGS84 automatically.

Similarly, I would like to tag the geomagnetic data with some coordinate system and let PostGIS do the reprojection behind the scenes, without me having to call a `reproject()` function manually.

• Could you explain how your geomagnetic coordinates were obtained in the first place? I think that may hold the key to an accurate solution: it appears likely they are computed from geographic coordinates. (Otherwise, how would one directly measure a geomagnetic latitude?) Jul 9, 2012 at 18:30
• @whuber, question edited. Thanks for the clarification.
– Reid
Jul 9, 2012 at 19:04

I am not sure anyy open source supports this geomagnetic to geographic.

But if you are having few coordinates, pls. try this..
http://wdc.kugi.kyoto-u.ac.jp/igrf/gggm/index.html

NASA has published the algorithm, you can try http://idlastro.gsfc.nasa.gov/ftp/pro/astro/mag2geo.pro

• I've opened a ticket for the proj4 team. They might add support for it in a later version? trac.osgeo.org/proj/ticket/178 Jul 9, 2012 at 23:55
• Somebody ported the `geo2mag.pro` IDL code to Python. This inverse code is very similar to `mag2geo.pro`. Here is the Python-ported code. Apr 17, 2014 at 13:06

The links provided by vadivelan make it clear that geomagnetic coordinates are just a rotation of the sphere so that (a) the north pole passes through the current magnetic south pole and (b) the prime meridian passes through the physical and magnetic poles.

For instance, IGRF-95 uses the position of the magnetic north pole in 1995, at latitude 79.30 and longitude -71.41 degrees.

Spherical rotations can be computed in many ways, typically by converting to 3D geocentric Cartesian coordinates, applying a linear transformation (through a 3 x 3 matrix multiplication or a quaternion multiplication), and converting back to spherical coordinates. But if you don't want to program this, there is a trick: a GIS that supports oblique projections can rotate by means of a reprojection. Just project the geomagnetic coordinates as if they were geographic coordinates, say by means of a polar aspect of the sterographic projection (with a central meridian at 0 degrees). Then unproject the result using the oblique aspect of the same projection with latitude of origin at 79.30 and central meridian of -71.41. Finally, project once more using any desired projection to obtain the "magical reprojection."

• Hmm. Is there a way for me to define such a GEOS or PROJ coordinate system, or something else that PostGIS will accept, and let a library do the reprojection without me having to do it explicitly?
– Reid
Jul 9, 2012 at 20:19
• It depends on what you mean by "explicitly." At some point--preferably as early in the process as possible--you should physically convert the coordinates from geomagnetic to geographic. You can do this once using a suitable GIS (e.g., QGIS looks like it would work) or reprojection utility. You don't need to know the reprojection equations for this if you use the trick I outlined. Jul 9, 2012 at 21:16
• Let me clarify the question to answer that.
– Reid
Jul 10, 2012 at 16:45