But, sometime you just care about one single transformation (say: EPSG:4326 to EPSG:32633), and you are really concerned about file size (maybe you are targeting a mobile site), because size does matter and you feel that proj4.js weighs in a bit too heavy. Well, that was what Bjørn Sandvik thought yesterday:
— Bjørn Sandvik (@thematicmapping) August 31, 2014
Then I got around to thinkning: how hard can this be? After a bit of thinking I realized that, yes, this is actually rather complicated in terms of maths. But, after a bit more thinking, I remembered this project from a couple of years ago (blog post in Norwegian). Basically, my old department at NTNU had some fortran code from around 1990 written by professor Jon Holsen in Fortran.
After looking at old notes and books on coordinate transformations it dawned on me that Holsen.js has a “bl_to_xy”-function, which transforms Geographic to planar coordinates. I then ripped out the relevant code, removed things that wasn’t needed for my simple WGS84 to UTM33 conversion, looked up the right params for UTM33N and made a gist in the middle of the night.
I did some testing against proj4js, and Bjørn did some more (reporting: “similar down to the centimetre”), and after figuring out that the original code used X for North and Y for East it seems to do the work. Result: a js file of about 100 lines, and that is rather readable lines as well. Running this code through a minifier (uglify.js) results in a 8 kb file (that is, about 10% of proj4js).
The code is tailored to transforming to one specific UTM Zone, but it should be easy to modify to work for other zones as well. Another idea is to make a similar script for transforming the other way, from UTM33 to Geographic coordinates. Holsen.js has support for this, so it shouldn’t be that difficult.