Map Projection Types & KMA Grid Conversion (Lambert Conformal Conic) Explained
Developers integrating the Korea Meteorological Administration (KMA) Short-Range Forecast API for the first time are often surprised to discover that the endpoint does not accept standard GPS latitude and longitude (`lat`, `lon`). Instead, it requires integer grid coordinates like nx = 60, ny = 127. Those integers represent a 5 km × 5 km cell on a flat meteorological plane created by projecting the curved Earth through a Lambert Conformal Conic (LCC) map projection. This article explains why map projections are necessary, why meteorological agencies favor the LCC projection, and how to convert WGS84 latitude/longitude into KMA `(nx, ny)` grid coordinates in JavaScript with verified test cases.
1. Why Every Flat Map Requires a Map Projection
As Carl Friedrich Gauss proved in his Theorema Egregium, a spherical or ellipsoidal surface has intrinsic curvature and cannot be flattened onto a 2D plane without stretching, tearing, or shearing. Just as you cannot flatten an orange peel onto a table without deforming it, every map projection must choose which geometric property to preserve at the expense of others:
- Conformal Projections (Preserve Local Angles & Shapes): Meridians and parallels intersect at right angles, preserving local angles and wind/navigation bearings. Examples include the Mercator projection and the Lambert Conformal Conic (LCC) projection.
- Equal-Area Projections (Preserve Area Ratios): Ensure that any two regions of equal square kilometer area occupy equal pixel area on the map (e.g., Albers Equal-Area Conic, Mollweide), ideal for thematic density maps.
- Equidistant Projections (Preserve Distance from Specific Origin/Lines): Maintain true scale only along meridians or radially from a single center point (e.g., Azimuthal Equidistant)—no flat map can preserve distances between all pairs of points simultaneously.
- Compromise Projections: Balance shape and area distortion visually for world wall maps (e.g., Robinson, Winkel Tripel).
2. Why Meteorology Uses the Lambert Conformal Conic (LCC) Projection
Imagine placing a paper cone over the northern hemisphere so that the cone slices through the globe along two specific latitude circles—called the standard parallels ($\phi_1$ and $\phi_2$)—projecting the surface onto the cone while preserving local angles, and then unrolling the cone flat.
Along the two standard parallels, scale distortion is zero; between them, scale is slightly compressed, and outside them, scale expands gradually. Because atmospheric weather systems (jet streams, cold fronts, low-pressure troughs) in the mid-latitudes (`30° N` to `60° N`) travel predominantly west-to-east, and because meteorological equations require true local angles for wind vectors and pressure gradients, the Lambert Conformal Conic projection is the standard choice for numerical weather prediction models covering the Korean peninsula and East Asia.
3. Official Parameters of the KMA 5 km Forecast Grid
The official coordinate conversion specification published with KMA's Short-Range Forecast OpenAPI defines a spherical LCC grid with the following constants:
KMA Short-Range Forecast Grid Constants
- Earth Radius (`RE`):
6371.00877 km(models Earth as a sphere rather than an ellipsoid) - Grid Cell Spacing (`GRID`):
5.0 km - Standard Parallels (`SLAT1`, `SLAT2`):
30.0° Nand60.0° N - Reference Origin (`OLAT`, `OLON`): Latitude
38.0° N, Longitude126.0° E - Grid Index at Origin (`XO`, `YO`):
XO = 43,YO = 136(in 5 km grid units)
Under this definition, the reference point `(38.0° N, 126.0° E)` maps to grid cell `(43, 136)`. Moving east increments `nx` (from `1` to `149`), and moving north increments `ny` (from `1` to `253`). Because KMA's formula assumes a spherical Earth (`RE = 6371.00877 km`) for computational simplicity, you must use KMA's exact constants rather than generic GRS80 ellipsoidal LCC parameters.
4. JavaScript Implementation: Converting `(lat, lon)` to `(nx, ny)`
Below is a clean, self-contained JavaScript implementation of KMA's official forward LCC grid transformation. The first block derives the cone constant `sn`, scale factor `sf`, and origin radius `ro`; the second block projects the input `(lat, lon)` into polar cone coordinates `(ra, theta)` and rounds to the nearest 5 km grid index:
function toKmaGrid(lat, lon) {
const RE = 6371.00877, GRID = 5.0;
const SLAT1 = 30.0, SLAT2 = 60.0, OLON = 126.0, OLAT = 38.0;
const XO = 43, YO = 136;
const DEGRAD = Math.PI / 180.0;
const re = RE / GRID;
const slat1 = SLAT1 * DEGRAD;
const slat2 = SLAT2 * DEGRAD;
const olon = OLON * DEGRAD;
const olat = OLAT * DEGRAD;
let sn = Math.tan(Math.PI * 0.25 + slat2 * 0.5) / Math.tan(Math.PI * 0.25 + slat1 * 0.5);
sn = Math.log(Math.cos(slat1) / Math.cos(slat2)) / Math.log(sn);
let sf = Math.tan(Math.PI * 0.25 + slat1 * 0.5);
sf = (Math.pow(sf, sn) * Math.cos(slat1)) / sn;
let ro = Math.tan(Math.PI * 0.25 + olat * 0.5);
ro = (re * sf) / Math.pow(ro, sn);
let ra = Math.tan(Math.PI * 0.25 + lat * DEGRAD * 0.5);
ra = (re * sf) / Math.pow(ra, sn);
let theta = lon * DEGRAD - olon;
if (theta > Math.PI) theta -= 2.0 * Math.PI;
if (theta < -Math.PI) theta += 2.0 * Math.PI;
theta *= sn;
return {
nx: Math.floor(ra * Math.sin(theta) + XO + 0.5),
ny: Math.floor(ro - ra * Math.cos(theta) + YO + 0.5),
};
}
Verification Table Against Official KMA Landmarks
| Landmark Location | Input (Latitude, Longitude) | KMA Grid (nx, ny) |
|---|---|---|
| Reference Origin | 38.0000, 126.0000 | 43, 136 |
| Seoul City Hall | 37.5665, 126.9780 | 60, 127 |
| Busan City Hall | 35.1796, 129.0756 | 98, 76 |
| Jeju City Hall | 33.4996, 126.5312 | 53, 38 |
Whenever you port this function to a new language, test these four coordinate pairs against the official administrative district Excel table distributed by KMA on the Public Data Portal (`data.go.kr`) to confirm your rounding and trigonometric signs match 100%.
5. Common Implementation Mistakes
- Swapping `lat` and `lon` arguments: Passing `(126.9780, 37.5665)` produces out-of-range grid indices outside `[1..149, 1..253]`. Validate that `lat` is between `32` and `39` and `lon` is between `124` and `132` before calling the KMA API.
- Tweaking `RE` or `XO`/`YO` constants: Replacing `6371.00877` with `6378.137` shifts the grid calculation enough to land in an adjacent 5 km cell near boundaries. Always keep KMA's exact constants untouched.
- Assuming a 1-to-1 match between administrative neighborhoods and grid cells: A large rural township can span several 5 km grid cells, while a single 5 km × 5 km cell in dense Seoul can cover 4 or 5 administrative dong neighborhoods.
6. Summary
Map projections trade off shape, area, and distance distortion to flatten Earth's curved surface. KMA's short-range neighborhood forecast grid uses a spherical Lambert Conformal Conic projection (`SLAT1 = 30°`, `SLAT2 = 60°`) sliced into 5 km squares so mid-latitude weather patterns retain true local angles.
HereWeather runs this exact LCC grid transformation in real time to map your GPS coordinates to your local KMA forecast cell. For more on how GPS coordinates are represented and acquired in the browser, see Differences Between WGS84 and UTM-K Coordinate Systems and HTML5 Geolocation API Accuracy Limits.