mercator β Ellipsoidal Mercator Map Projection Library
Overview & Purpose in the OMG Architecture
mercator (code/subr/mercator.c, code/subr/mercator.h), originally written by Guy Carpenter on November 13, 1989 and extended by John E. Hughes Clarke in 1993 (adding Snyderβs ellipsoidal inverse Mercator) and Bill Danforth (merc_fixBWD), provides forward and inverse Ellipsoidal Mercator map projection transformations for OMG grids and navigation tools.
In the OMG raster header specification (JHC_header in array.h), Mercator is used for projection codes 1 (North-up Mercator) and 5 (Rotated Mercator). Beyond raster gridding, many standalone OMG analysis tools (inArea, checkSD, getGraz, showPingRate, correctBS) call merc_init() and mercator() directly with scale = 1.0 to convert geographic (lon, lat) degrees into local metric $(x, y)$ displacements (in meters) around a survey areaβs central latitude (proj_lat).
Key Global Variables, Types & Macros (code/subr/mercator.h, code/subr/mercator.c)
Global State Variables
double merc_eccen: Eccentricity $e$ of the active reference ellipsoid (defaults toWGS84_ECCEN = 0.0818191908417579).double merc_earthrad: Equatorial radius $a$ in meters (defaults toWGS84_RADIUS = 6378137.0).double merc_eqscale: Scale factor at the equator derived from the standard parallelproj_lat($\cos\phi_0 / \sqrt{1 - e^2\sin^2\phi_0}$).double merc_scaledrad: Effective scaled radius (merc_earthrad * merc_eqscale / scale).double merc_xoffset,double merc_yoffset: Projected map origin offsets corresponding to(origin_lon, origin_lat).char merc_signflag: Hemisphere/longitude sign handling flag.
Enums & Macros
mapproj_type: Enumeration{no_proj, mercator_proj, utm_proj, amg_proj, rotutm_proj}.DEGTORAD(D):((double)(D) * M_PI / 180.0)RADTODEG(D):((double)(D) * 180.0 / M_PI)
Public Functions & Signatures
void merc_init(double scale, double proj_lat, double origin_lon, double origin_lat)Initializes the Mercator projection state before callingmercator()orinv_merc():- Sets
merc_eccenandmerc_earthradfrom the activeEllipsoid(wgs.h). - Computes the true-scale parallel factor
merc_eqscaleat latitudeproj_lat(degrees) and divides byscale(e.g., meters per pixelhead->xstep, or1.0for raw meters) to setmerc_scaledrad. - Projects
(origin_lon, origin_lat)to establish the grid origin offsets(merc_xoffset, merc_yoffset).
- Sets
-
void merc_fixBWD(int ellipsoid, double proj_lat)Explicitly updates the ellipsoid parameters (merc_eccen,merc_earthrad) and standard-parallel scale factor (merc_eqscale) for a specifiedellipsoidID and reference latitudeproj_lat. -
void mercator(double lon, double lat, double *x, double *y)Forward Ellipsoidal Mercator Projection: Converts longitudelonand latitudelat(decimal degrees) into projected map units(*x, *y)relative to(origin_lon, origin_lat): \(x = R_{\text{scaled}} \cdot \text{DEGTORAD}(\text{lon}) - x_{\text{offset}}\) \(y = R_{\text{scaled}} \cdot \ln\left[\tan\left(\frac{\pi}{4} + \frac{\phi}{2}\right) \left(\frac{1 - e\sin\phi}{1 + e\sin\phi}\right)^{e/2}\right] - y_{\text{offset}}\) void inv_merc(double x, double y, double *lon, double *lat)Inverse Ellipsoidal Mercator Projection: Converts projected map coordinates(x, y)back into geographic(*lon, *lat)in decimal degrees using Snyderβs iterative/series expansion for isometric latitude $t = \exp(-(y + y_{\text{offset}}) / R_{\text{scaled}})$ and conformal latitude $\chi = \frac{\pi}{2} - 2\arctan(t)$.
How It Fits Into the OMG Architecture
mercator is called by j_proj.c for raster projections 1 and 5, and is directly included by numerous swath and backscatter analysis utilities in code/omg/ (inArea, checkSD, getGraz, showPingRate, correctBS) and code/JV/ (JV_global.h) whenever fast local metric coordinate conversion is needed.