Tag Archives: software

Projection from WGS1984 to Swiss national grid (CH1903 LV03)

In my last project I used (standalone) Python for geoprocessing. Since ArcGIS or something like that was not there to help with projecting geodata from one coordinate system to another, I wrote a function which converts well-known WGS1984 to Swiss national grid coordinates (SwissgridCH1903 LV03).

Swisstopo has the formulas of an approximate transformation and also funtions in C#, Javascript and PHP, but not in Python. So here is to your disposal:

def projWGS1984ToCH1903(x, y):
  """Converts coordinates from WGS1984 to CH1903_LV03 using the
     method from http://www.swisstopo.admin.ch/internet/swisstopo/
     de/home/products/software/products/skripts.html, returns a
     list [x,y]
     :param x: x coordinates in degrees in WGS1984 :
     :param y: y coordinates in degrees in WGS1984 """

  # Transformation into sexagesimal seconds
  x = x * 3600
  y = y * 3600

  # Latitude and longitude difference to Bern
  x_fact = (x - 26782.5) / 10000 # LAMBDA
  y_fact = (y - 169028.66) / 10000 # PHI

  x = 600072.37 + 211455.93 * x_fact - 10938.51 * x_fact * y_fact - 0.36 * x_fact * y_fact**2 - 44.54 * x_fact**3
  y = 200147.07 + 308807.95 * y_fact + 3745.25 * x_fact**2 + 76.63 * y_fact**2 - 194.56 * x_fact**2 * y_fact + 119.79 * y_fact**3

  return [x, y]

Py all means

Over on his blog, Bill Dollins muses about the range and ubiquity of the Python language in the geospatial realm.

It’s true – if you work with ESRI products on a daily basis (like I do) you almost can’t get away without using Python one way or the other, be it for scripting some workflow, writing some standalone programme with or without using ESRI’s arcpy or implementing advanced Field Calculations in ArcGIS. The most important upside about the ubiquity of Python to me is the availability of great packages. In my work I have for example used such diverse packages as EXIF.py for manipulating EXIF data in images (think extraction of geocoding information from photos), suds for accessing SOAP services and Numpy for handling computations in, and manipulations of, rasters.
Very recently I tested map production automation in ArcGIS using the arcpy.mapping package. Part of the task encompassed automatically adapting the map title in accordance with changing map content. The title was put into a relatively small text box and I had thus to find a way to make sure that both a string of say ten characters as well as 25 characters could fit in the space. After some digging I came across a nice package called PyHyphen which I could include into my script for hyphenating the title string and thus perfectly solving my problem. It even came with a German dictionary which handled names of Swiss municipalities well!
Also very recently, I finished a study on the threat nuclear power stations present to people living in their (more or less immediate) environment. The geospatial part of that study was – except for a small bit of the open source statistics software R thrown in there – completely done in Python. And if I had already been aware of rpy which Bill mentions in his post, I might have been able to pull off the entire analysis in Python.

I think Python is here to stay for a while. In the geospatial realm which works with ESRI it has always been clear that Python is the next thing after AML and VBA/ArcObjects. But it’s very good to see that Python in fact has a much broader base than just the ESRI products in the geospatial realm and certainly beyond that. And I also really like that it runs on my Ubuntu desktop as well.