Convert swiss national grid coordinates (CH1903) to WGS1984

Convert swiss national grid coordinates (CH1903) to WGS1984

October 13, 2014 17:15 0 comments
 
12 Kudos
Don't
move!

The World Geodetic System (or WGS) is a worldwide standard for the cartography. The well-known concepts (such as latitude and longitude, for example) are part of this standard.

Yet, in Switzerland, there is a different national standard that is called CH1903 (or Landesvermessung 1903, LV03).

Implementations, in the most widespread programming languages, to convert coordinates from the Swiss standard to WGS1984 are provided by swisstopo. However, the Python one is missing. You can grab it here.

from __future__ import division

def CHtoWGSlat(x,y):
    """
    Convert CH1903 system to WGS1984 system (latitude)

    :param x: northing
    :param y: easting
    :return: latitude in WGS1984 system

    """
    x_aux = (x - 200000) / 1000000
    y_aux = (y - 600000) / 1000000

    lat = (16.9023892 + (3.238272 * x_aux)) \
          - (0.270978 * pow(y_aux, 2)) \
          - (0.002528 * pow(x_aux, 2)) \
          - (0.0447 * pow(y_aux, 2) * x_aux) \
          - (0.0140 * pow(x_aux, 3))

    lat = (lat * 100) / 36

    return lat

def CHtoWGSlng(x,y):
    """
    Convert CH1903 system to WGS1984 system (longitude)

    :param x: northing
    :param y: easting
    :return: longitude in WGS1984 system

    """
    x_aux = (x - 200000) / 1000000
    y_aux = (y - 600000) / 1000000

    lng = (2.6779094 + (4.728982 * y_aux) + (0.791484 * y_aux * x_aux) +
           (0.1306 * y_aux * pow(x_aux, 2))) - (0.0436 * pow(y_aux, 3))

    lng = (lng * 100) / 36

    return lng

def CH1903toWGS1984(x, y):
  """Converts coordinates from CH1903_LV03 to WGS1984 adopting the code taken from
     method from http://www.swisstopo.admin.ch/internet/swisstopo/de/home/products/software/products/skripts.html

     :param x: x coordinates in degrees in CH1903 (northing)
     :param y: y coordinates in degrees in CH1903 (easting)
     :return: a pair containing the latitude and longitude of the given coordinates, respectively"""

  lat = CHtoWGSlat(x, y)
  lng = CHtoWGSlng(x, y)

  return [lat, lng]

Enjoy!