Converting Latitude and Longitude to Cartesian Coordinates: Principles and Practice of Map Projections

Dec 04, 2025 · Programming · 13 views · 7.8

Keywords: Map Projection | Coordinate Conversion | Equirectangular Projection | Latitude Longitude | GIS

Abstract: This article explores the technical challenges of converting geographic coordinates (latitude, longitude) to planar Cartesian coordinates, focusing on the fundamental principles of map projections. By explaining the inevitable distortions in transforming spherical surfaces to planes, it introduces the equirectangular projection and its application in small-area approximations. With practical code examples, the article demonstrates coordinate conversion implementation and discusses considerations for real-world applications, providing both theoretical guidance and practical references for geographic information system development.

In geographic information systems (GIS) and mapping applications, converting Earth surface coordinates from latitude and longitude to planar Cartesian coordinates is a common yet complex problem. Since the Earth is approximately spherical while map displays are two-dimensional, this transformation inherently involves geometric distortions. This article examines the core challenges and solutions, starting from fundamental principles.

Inherent Challenges in Spherical-to-Planar Transformation

The Earth's surface is a three-dimensional sphere, while planar maps are two-dimensional. Mathematically, no isometric map exists from a sphere to a plane. This means that during transformation, it's impossible to preserve all distances, angles, and areas simultaneously. Any map projection method must make compromises among these properties, choosing to preserve some characteristics while sacrificing others.

A common misconception is expecting converted planar coordinates to precisely maintain actual distances between points on Earth's surface. In reality, even when using three-dimensional Cartesian coordinates (x, y, z) to represent Earth points, the calculated straight-line distance differs from the geodesic distance along the surface. The shortest path on Earth's surface follows great circle arcs, while straight-line distances in three-dimensional space pass through the Earth's interior, thus always being shorter than actual surface distances.

Fundamentals of Map Projections

Map projection refers to mathematical methods that map geographic coordinates (φ, λ) to planar Cartesian coordinates (x, y). Hundreds of different projection methods exist, each with specific applications, advantages, and limitations. Among these, the equirectangular projection is widely used for small-area mapping due to its computational simplicity.

The basic formula for equirectangular projection is:

x = R * λ * cos(φ₀)
y = R * φ

where R is Earth's radius (typically 6371 km), λ is longitude (in radians), φ is latitude (in radians), and φ₀ is the reference latitude. The key element is the scaling factor cos(φ₀) for the longitude direction, which compensates for meridian convergence caused by latitude variation.

Implementation of Small-Area Approximation

For small regions (such as a few square kilometers), the equirectangular projection provides sufficiently accurate approximations. The following JavaScript code demonstrates a complete implementation:

// Earth radius in kilometers
const EARTH_RADIUS = 6371;

// Convert latitude/longitude to global planar coordinates
function latLngToGlobalXY(lat, lng, referenceLat) {
    // Convert degrees to radians
    const latRad = lat * Math.PI / 180;
    const lngRad = lng * Math.PI / 180;
    const refLatRad = referenceLat * Math.PI / 180;
    
    // Apply equirectangular projection formula
    const x = EARTH_RADIUS * lngRad * Math.cos(refLatRad);
    const y = EARTH_RADIUS * latRad;
    
    return { x, y };
}

// Example: Convert Beijing Tiananmen coordinates (39.9075°N, 116.3972°E)
// Using 40°N as reference latitude
const beijing = latLngToGlobalXY(39.9075, 116.3972, 40);
console.log(`Global coordinates: x=${beijing.x.toFixed(2)} km, y=${beijing.y.toFixed(2)} km`);

Mapping from Global to Screen Coordinates

In practical applications, global planar coordinates often need further mapping to screen display areas. This can be achieved by establishing correspondence between two reference points:

// Define reference points for screen display area
const screenBounds = {
    topLeft: { screenX: 0, screenY: 0, lat: 40.0, lng: 116.0 },
    bottomRight: { screenX: 800, screenY: 600, lat: 39.5, lng: 116.5 }
};

// Calculate global coordinates for reference points
screenBounds.topLeft.global = latLngToGlobalXY(
    screenBounds.topLeft.lat, 
    screenBounds.topLeft.lng,
    (screenBounds.topLeft.lat + screenBounds.bottomRight.lat) / 2
);
screenBounds.bottomRight.global = latLngToGlobalXY(
    screenBounds.bottomRight.lat,
    screenBounds.bottomRight.lng,
    (screenBounds.topLeft.lat + screenBounds.bottomRight.lat) / 2
);

// Convert latitude/longitude to screen coordinates
function latLngToScreenXY(lat, lng) {
    // Calculate global coordinates
    const referenceLat = (screenBounds.topLeft.lat + screenBounds.bottomRight.lat) / 2;
    const globalPos = latLngToGlobalXY(lat, lng, referenceLat);
    
    // Calculate relative position in global coordinate system
    const globalWidth = screenBounds.bottomRight.global.x - screenBounds.topLeft.global.x;
    const globalHeight = screenBounds.bottomRight.global.y - screenBounds.topLeft.global.y;
    
    const relativeX = (globalPos.x - screenBounds.topLeft.global.x) / globalWidth;
    const relativeY = (globalPos.y - screenBounds.topLeft.global.y) / globalHeight;
    
    // Map to screen coordinates
    const screenX = screenBounds.topLeft.screenX + 
                   relativeX * (screenBounds.bottomRight.screenX - screenBounds.topLeft.screenX);
    const screenY = screenBounds.topLeft.screenY + 
                   relativeY * (screenBounds.bottomRight.screenY - screenBounds.topLeft.screenY);
    
    return { x: screenX, y: screenY };
}

// Example: Map coordinates to 800×600 screen
const screenPos = latLngToScreenXY(39.9, 116.4);
console.log(`Screen coordinates: x=${screenPos.x.toFixed(1)}, y=${screenPos.y.toFixed(1)}`);

Practical Considerations

1. Projection Selection: While equirectangular projection works well for small areas, larger-scale maps may require more complex projections like Transverse Mercator, which forms the basis of the Universal Transverse Mercator (UTM) coordinate system.

2. Accuracy Considerations: Earth is not a perfect sphere but an approximate ellipsoid. For high-precision applications, more accurate Earth models like the WGS84 ellipsoid parameters should be used.

3. Performance Optimization: The calculation of cos(φ₀) for the reference latitude can be precomputed and cached to avoid repeated trigonometric calculations when converting large numbers of coordinates.

4. Boundary Handling: Some projection methods may encounter singularities or extreme distortions near projection boundaries, requiring special handling.

Conclusion

Converting latitude and longitude to planar coordinates is fundamental in geographic information processing. Understanding the mathematical principles and limitations of map projections is crucial for developing accurate and reliable geographic applications. The equirectangular projection provides a simple yet effective solution for small-area mapping, while the reference-point mapping approach offers flexibility in adapting global coordinates to various display requirements. In practical development, appropriate projection methods and accuracy levels should be selected based on specific application scenarios, balancing computational complexity with accuracy requirements.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.