Understanding Coordinate Reference Systems (CRS): EPSG:4326 vs EPSG:3857
A clear, developer-focused guide to geographic coordinate systems, map projections, datums, and resolving spatial reprojection issues.
- 1. What is a Coordinate Reference System (CRS)?
- 2. Geographic (GCS) vs Projected (PCS) Systems
- 3. Deep Dive: EPSG:4326 (WGS 84)
- 4. Deep Dive: EPSG:3857 (Web Mercator)
- 5. Direct Comparison: EPSG:4326 vs EPSG:3857
- 6. Popular National & Regional Projections (UTM, State Plane, BNG)
- 7. Client-Side Reprojection with Proj4
- 8. Troubleshooting CRS Inconsistencies
1. What is a Coordinate Reference System (CRS)?
Every spatial coordinate pair, such as (-73.985, 40.748) or (583200, 179400), is meaningless without a defined Coordinate Reference System (CRS). A CRS provides the mathematical framework that pins numbers on a screen to physical locations on Earth's curved, irregular surface (the geoid).
A CRS consists of:
- An Ellipsoid (Spheroid): A simplified geometric approximation of Earth's shape (e.g. WGS 84, GRS 1980).
- A Geodetic Datum: Defines the position of the ellipsoid relative to the center of the Earth and orients the coordinate axes.
- A Coordinate System: The units of measurement (degrees, meters, feet) and axis directions.
- A Map Projection (if projected): A mathematical algorithm that flattens the 3D ellipsoid onto a 2D surface.
2. Geographic (GCS) vs Projected (PCS) Systems
| Attribute | Geographic Coordinate System (GCS) | Projected Coordinate System (PCS) |
|---|---|---|
| Model | 3D spherical / ellipsoidal globe | 2D flattened planar sheet |
| Units | Angular decimal degrees (°, minutes, seconds) | Linear measurements (meters, US survey feet) |
| Primary Example | EPSG:4326 (WGS 84) | EPSG:3857 (Web Mercator) |
| Distance Math | Great-circle / Haversine / Geodesic distance (complex) | Euclidean distance: $\sqrt{\Delta x^2 + \Delta y^2}$ (simple) |
| Area Distortion | Minimal distortion when calculated geodesically | High distortion away from standard parallels |
3. Deep Dive: EPSG:4326 (WGS 84)
EPSG:4326 corresponds to the World Geodetic System 1984 (WGS 84). It is the native coordinate system used by the Global Positioning System (GPS), satellite navigation devices, and standard GeoJSON (RFC 7946).
- Longitude: Angular distance East (+) or West (-) of the Prime Meridian in Greenwich, UK. Range:
-180.0°to+180.0°. - Latitude: Angular distance North (+) or South (-) of the Equator. Range:
-90.0°to+90.0°.
The Catch with EPSG:4326: Because degrees do not represent uniform physical distances (one degree of longitude is ~111 km at the Equator, but narrows to 0 km at the North Pole), calculating areas or buffers using planar formulas in EPSG:4326 produces wildly incorrect results unless geodesic math is used!
4. Deep Dive: EPSG:3857 (Web Mercator)
EPSG:3857 (also known historically as EPSG:900913 or "Google Mercator") is the standard projected coordinate system for interactive web tile maps, adopted universally by Google Maps, OpenStreetMap, Mapbox, Bing Maps, and Esri.
Web Mercator treats the Earth as a sphere of radius $R = 6,378,137\text{ m}$. Coordinates are projected onto a square grid measured in meters:
- X Range:
-20,037,508.34 mto+20,037,508.34 m - Y Range:
-20,037,508.34 mto+20,037,508.34 m
Why Web Maps Chose Web Mercator
- Square World: The projected coordinate space forms an exact square ($20037508 \times 20037508\text{ m}$), making it computationally trivial to divide the globe into quadtree 256x256 pixel raster/vector tiles.
- Conformal: It preserves local angles. A right-angle street intersection in Tokyo or London looks like a 90° angle on the screen.
- Directional Integrity: North is always straight up, South is always straight down.
5. Direct Comparison: EPSG:4326 vs EPSG:3857
// The same physical landmark (Empire State Building, NYC) in both systems:
// In EPSG:4326 (WGS 84 Decimal Degrees):
Longitude: -73.98513
Latitude: 40.74881
// In EPSG:3857 (Web Mercator Meters):
X: -8235999.41 meters
Y: 4975549.95 meters
6. Popular National & Regional Projections
When precision engineering, cadastral surveying, or construction planning is required, localized projected systems are used to minimize distortion:
- EPSG:27700 (British National Grid / OSGB36): Designed specifically for Great Britain. Measured in meters from a false origin southwest of the Isles of Scilly.
- EPSG:2154 (RGF93 / Lambert-93): The official legal projection for mainland France.
- EPSG:25832 (ETRS89 / UTM Zone 32N): Widely used across Central Europe and Germany.
- EPSG:2263 (NAD83 / New York Long Island): The local State Plane coordinate system for New York City and Long Island (measured in US survey feet).
7. Client-Side Reprojection with Proj4
Spatial-Sandbox integrates Proj4js to reproject geometries directly in your browser without transmitting your data to any backend server:
// Example Proj4js transformation in JavaScript
import proj4 from 'proj4';
// Define British National Grid (EPSG:27700)
proj4.defs("EPSG:27700", "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs");
// Transform coordinates: [Eastings, Northings] -> [Longitude, Latitude]
const bngCoords = [530000, 180000]; // Central London
const wgsCoords = proj4("EPSG:27700", "EPSG:4326", bngCoords);
console.log(wgsCoords); // [-0.1278, 51.5074]
8. Troubleshooting CRS Inconsistencies
1. Geometry Plots Off the Coast of Africa
Cause: Latitude and longitude coordinate values are swapped, or your coordinates are in local meters (e.g. 500,000) and being parsed as degrees.
2. Polygon Appears Flattened or Stretched
Cause: You rendered geographic coordinates (degrees) directly onto a Cartesian grid without applying Mercator scaling factor $\cos(\text{latitude})$.
3. Reprojecting in Spatial-Sandbox
If your data comes from PostGIS or a government shapefile in a local projection (e.g. EPSG:3857 or EPSG:27700), simply enter the EPSG code in the CRS box of Spatial-Sandbox WKT Viewer to reproject and render accurately on the map.