Mercator Projection Pixel Conversion
The Mercator projection is widely used in mapping, particularly for navigation charts. It transforms latitude and longitude coordinates into a rectangular grid, making it ideal for displaying maps of the world on a flat surface.
Formula Derivation
The Mercator projection is derived from cylindrical projections. The formulas for converting latitude and longitude to rectangular coordinates are:
E = FE + R (λ – λ0) N = FN + R ln[tan(π/4 + φ/2)]
where:
In spherical Mercator projection, FE and FN are not used, so the formula simplifies to:
x = (λ + 180) * (mapWidth / 360) y = (mapHeight / 2) - (mapWidth * ln(tan((PI / 4) + (latRad / 2))) / (2 * PI))
where:
Implementation
In Java, you can implement the Mercator projection conversion as follows:
public static void main(String[] args) { double latitude = 41.145556; double longitude = -73.995; double mapWidth = 200; double mapHeight = 100; // Convert latitude from degrees to radians double latRad = latitude * Math.PI / 180; // Calculate Easting and Northing coordinates double x = (longitude + 180) * (mapWidth / 360); double y = (mapHeight / 2) - (mapWidth * Math.log(Math.tan((Math.PI / 4) + (latRad / 2))) / (2 * Math.PI)); System.out.println("Easting: " + x); System.out.println("Northing: " + y); }
The above is the detailed content of How to Convert Latitude and Longitude to Pixel Coordinates Using the Mercator Projection?. For more information, please follow other related articles on the PHP Chinese website!