Home >Java >javaTutorial >How do you convert latitude and longitude to Mercator projections?

How do you convert latitude and longitude to Mercator projections?

Barbara Streisand
Barbara StreisandOriginal
2024-11-08 18:31:02207browse

How do you convert latitude and longitude to Mercator projections?

Mercator Projection: Converting Latitude/Longitude to Mercator Projections

The Mercator projection is a map projection that conformal and equidistant along particular lines. It preserves the shape but not the area and is widely used for navigation charts.

Converting Latitude/Longitude to Mercator Projections

To convert a latitude/longitude point to a Mercator projection, we use the following formulas:

E = FE + R (λ – λₒ)
N = FN + R ln[tan(π/4 + φ/2)] 

where:

  • E is the projected Easting
  • N is the projected Northing
  • λ is the longitude
  • φ is the latitude
  • FE is the false easting
  • FN is the false northing
  • λₒ is the longitude of natural origin

For the Mercator Sphere, FE and FN are 0, simplifying the formula to:

E = R * (λ – λₒ)
N = R * ln[tan(π/4 + φ/2)]

Code Example

In pseudo code, we convert latitude and longitude to Mercator projections as follows:

latitude    = 41.145556; // (φ)
longitude   = -73.995;   // (λ)

mapWidth    = 200;
mapHeight   = 100;

// get x value
x = (longitude+180)*(mapWidth/360)

// convert from degrees to radians
latRad = latitude*PI/180

// get y value
mercN = ln(tan((PI/4)+(latRad/2)));
y     = (mapHeight/2)-(mapWidth*mercN/(2*PI));

By applying these formulas and converting from radians to degrees as necessary, we can accurately convert latitude/longitude points to Mercator projections. This knowledge is essential for displaying data on Mercator-projected maps.

The above is the detailed content of How do you convert latitude and longitude to Mercator projections?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn