Proj4js, L-EST and GeoPoint

This post is about converting Estonian coordinates (L-EST 97, L-EST 92) to the common lon/lat format that probably everyone is familiar with (EPSG4326 or WGS84).

For solving this problem I used the excellent proj4js library. The following defintions are needed for EPSG:3301 (L-EST 97) and EPSG:3300 (L-EST 92):

Proj4js.defs["EPSG:3301"] = "+proj=lcc +lat_1=59.33333333333334 +lat_2=58 +lat_0=57.51755393055556 +lon_0=24 +x_0=500000 +y_0=6375000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs";
Proj4js.defs["EPSG:3300"] = "+proj=lcc +lat_1=59.33333333333334 +lat_2=58 +lat_0=57.51755393055556 +lon_0=24 +x_0=500000 +y_0=6375000 +ellps=GRS80 +towgs84=0.055,-0.541,-0.185,0.0183,-0.0003,-0.007,-0.014 +units=m +no_defs";

The conversion is actually pretty simple:

var x = 6512000;
var y = 541975.6;

var src = new Proj4js.Proj("EPSG:3301");
var dst = new Proj4js.Proj("EPSG:4326");

var point = new Proj4js.Point(y, x);

Proj4js.transform(src, dst, point);

// 24.72504500749274
console.log(point.x);

// 58.74554729994484
console.log(point.y);

The only thing to watch out for is that you need to swap x/y when converting from L-EST. While generally lat = y and lon = x then in L-EST it seems to be reversed and you get incorrect results otherwise.

I also had the problem of needing to display the coordinates in the more human friendly DEG° MIN’ SEC” format and so I wrote a small library (GeoPoint) to do just that, it’s available at Github and released under MIT license.

var geopoint = new GeoPoint(point.x, point.y);

// 24° 43' 30.16"
console.log(geopoint.getLonDeg());

// 58° 44' 43.97"
console.log(geopoint.getLatDeg());

GeoPoint also is able to do the reverse transformation – take the human readable format and turn it into a float:

var lon = "24° 43' 30.16"";
var lat = "
58° 44' 43.97"";

var geopoint = new GeoPoint(lon, lat);

// 24.725044444444443
console.log(geopoint.getLonDec());

// 58.74554722222222
console.log(geopoint.getLatDec());

As a final tip I’ll show you how to take a point in lon/lat format, convert it to L-EST and display it on Maa-amet maps (this example assumes you’ve added the above defs to Proj4js):

// the location of our office :)
var lon = 24.756253;
var lat = 59.43922;

var point = new Proj4js.Point(lon, lat);

var src = new Proj4js.Proj("EPSG:4326");
var dst = new Proj4js.Proj("EPSG:3301");

Proj4js.transform(src, dst, point);

window.open("http://xgis.maaamet.ee/xGIS/XGis?app_id=UU82&user_id=at&punkt=" + point.x + "," + point.y + "&moot=2000");

You can view the actual map for the above example here and come visit us :)

Hope this was helpful to someone and happy map hacking!

Tarmo Lehtpuu
Tarmo is the swiss army knife Software Engineer. His deep knowledge on wide range of technologies makes him an efficient problem solver. In addition to Ruby on Rails, he enjoys developing iOS Apps.

1 Comment

Liked this post?

There’s more where that came from. Follow us on Facebook, Twitter or subscribe to our RSS feed to get all the latest posts immediately.