Web whack.thechajoneri.se
Whack!
My world of hacks

Eniro images

After playing with Google Earth for a while, and being from Sweden, I got slightly irritated that Sweden had so few areas with hight resolution imagery. Even Gothenburg, the second largest city, did not have any high res areas at all. Meanwhile, Eniro.se and Hitta.se, who are both major providers of telephone directory and maps information in Sweden, both started to supply higher resolution images both from satellites and aerial photography. From my experience, Eniro had the more detailed images of the two. I first made an attempt to simply grab an images of my home area, importing it into Google Earth and trying to fit it to the rest of the geography. It worked OK, but I thought it must be possible to automate the process.

Screenshot of Google Earth showing Gothenburg before the hack.
Gothenburg before the hack is applied.


The Eniro server

I started out by examining the Eniro site to see if I could figure out how to request the images ("View page source" is your friend). It took a little effort and some JavaScript reading until I had it right. The format is as follows:

http://maps.eniro.com/tellus/servlets/tellus/
?profile=Main&size=[x-size]x[y-size]&ul=[ul-y];[ul-x]&lr=[lr-y];[lr-x]


Note that it the line is broken to make it more readable, the whole thing should of course be on a single line.

x-size and y-size define the size in pixels of the image you want. I found that 700x700 is the maximum size supported.

The other parameters: ul-x, ul-y and lr-x, lr-y are the upper left and lower right corner of the image given in RT90 coordinates. RT90 is a two dimensional reference coordinate system that most Swedish maps (up until now) are defined in. This brings us to the next section...


Geometry conversions

Swedish maps and also the images from Eniro are defined in the RT90 reference system. Google Earth, however, uses latitude and longitude and height defined in the WGS 84 reference system. So what is all this? Well, to simplify a bit one could say that different systems uses a different mathematical model of the earth in the form of an ellipsoid. There are several resources on the Internet that can explain all this in more detail. If you can read Swedish, a very good site is lantmateriet.se.

So, to connect these two, we need to convert data in one of the systems to the other. This turns out to be non-trivial. There is simply no analytical form of the relation between the two systems. Things get even more complicated by the fact that RT90 is actually a two dimensional projection (Gauss-Kruger or Transverse Mercator) while WGS 84 is three dimensional. Traditionally, a conversion between two systems is done using the so called 7-parameter transformation. However, to use this we must add height information to the equations which will unfortunately affect the planar result.

Anyway, the smart people at Lantmäteriet in Sweden have developed parameters that make it possible to go directly from latitude, longitude in WGS 84 (note, no height) to x, y in RT90 by way of a Gauss-Kruger projection. You can read about it and find parameters and formulas for this direct projection here (in Swedish).


Code

OK, we now have all the puzzle pieces. To build the network link we need to:
  1. Get the call from Google Earth and extract the bounding box of the area the user is watching.
  2. Convert this bounding box, given in lat long, to RT90 coordinates.
  3. Generate a piece of KML that specifies an overlay image, fitted to the bounding box in step 1, and as source for the image we give the URL we generated to the Eniro server using the RT90 coordinates.
I have implemented these steps in C# in an ASP.NET page. You can download the code in the form of a zip-file below:


Result

The hack seems to work great. Geometric fit to map data is excellent.

Screenshot of Google Earth showing Gothenburg before the hack.Screenshot of Google Earth showing Gothenburg after the hack.
Gothenburg before and after the hack is applied.

But wait, aren't we forgetting something...?
How do you actually use this?
Well, you grab the file above and install it on a web server that supports ASP.NET. Then you create the actual network link in Google Earth that points to that server. I will leave that as an exercise for the reader for now. Hint: Right click on "My Places" and select "Add"...

Ok, ok, just kidding... The zip-file contains an example of such a KML file that points to a service on this server. If you install the ASP.NET page on your own server, remember to change the link in the KML file as well.

Happy Hacking!