UTM or Universal Transverse Mercator is a 2-D Cartesian coordinate system. Converting coordinates from a geographic coordinate system, e.g. WGS84, which is typically used by GPS receivers, to UTM maps those coordinates from the curved surface of the Earth to a plane. This makes it simpler to perform geometric calculations on those coordinates. For example, in UTM, one would only need to use the Pythagorean theorem to calculate the distance between two coordinates, whereas in geographic coordinates, one would have to use the Great Circle formula.
UTM is not just one coordinate grid, but 60 zones that divide the Earth into 60 north-south strips. Each UTM zone is a 6° slice of the Earth. This is important to note because you cannot perform geometric calculations across different UTM zones. We’ll see how to get around that below.
First, load the UTM library:
Then create a degree-minute coordinate object and convert it to UTM like so:
var degmin = new UTMConv.DegMinCoords(latdir, latdeg, latmin, lngdir, lngdeg, lngmin, "wgs84"); var utm = degmin.to_utm() console.log("UTM Zone = " + utm.utmz + " Easting = " + utm.easting + " Northing = " + utm.northing);
That’s all there is to it! Once you have the UTM coordinates, the easting is the x axis and the northing is the y axis in the Cartesian system.
The last parameter in the DegMinCoords constructor, which is the datum, defaults to “wgs84”, so it could have been omitted in the above example.
Of course, since toString() is defined on all coordinate objects, you could also print out UTM coordinates like so:
The to_utm() method takes one parameter, the UTM zone. If omitted, the zone is calculated during the conversion process. You may wish to specify the UTM zone if you have a set of geographic coordinates and you want to be sure that, once converted to UTM, those are all in the same zone. You’d do the conversion as follows:
// First coordinate sets the UTM zone for the other two. var utm1 = c1.to_utm(); var utm2 = c2.to_utm(utm1.utmz); var utm3 = c3.to_utm(utm1.utmz);
Converting from UTM to degree-minute coordinates is just as simple:
var degmin = utm.to_degmin();
For further information, see the UTMConv Reference.
YouTim includes a few examples:
To view the code and examples, see: https://github.com/mortonfox/YouTim/tree/master/docs
Or just use your browser’s “view source” feature when viewing the above examples.