Epilogue: Maps…

On topographical and geodetic maps, and PHP and JavaScript scripts for converting between the two

First day of the Milford Track
First day of the Milford Track. Buy the Milford Track Great Walk Topo Set (2013) – €5

I’ve occasionally said in jest that the earth is flat, at least for the purposes of drawing small scaled maps, such as those that appear in the pages of this blog.

But what I’ve somehow missed up until now is that there are two types of flatness.

For everyone with a GPS machine, let’s see what you have got and what you are missing. Your machine will produce degrees east or west of the meridian and north or south of the equator. That’s called geodetic data, and it’s fine. That’s what the elevation data produced by the SRTM (Shuttle Radar Topography Mission) are mapped out as, it’s the data that GEOrgET works with.

But it’s not the data that mapmakers express themselves in. They deal in things called Transverse Mercator projections, and they function a little differently from taking one “square degree” and squishing it into approximately its physical dimensions. Starting from a reference longitude (the north-south line), they branch off at various latitudes, initially directly to the east or west and map out a rectangular grid. Can you see what is going to be off kilter here? The further south you go, the more the line you are following, the tangent (to the east or west) will deviate southwards from the arc of the latitude. In the same way true north starts to deviate (in the Southern Hemisphere) to the east or west corresponding to how far east or west of the reference longitude you are.

Choose a path, Abel Tasman Track
The road less travelled, Abel Tasman Track. Buy Abel Tasman Coastal Track Great Walk Topo Set (2013) – €4.00
Normally this would not be of much concern, but I have discovered to my delight that Land Information New Zealand (LINZ) provides free downloads of its topo 50 maps under a creative commons licence. Now if only I could translate my geodetic data to the topographical frame I could plant my GPS data onto the topo maps and from there any number of applications suggest themselves.

LINZ is also very helpful in providing details of how this can be done, although I suspect that the formulae on their pages were scanned in from some ancient and yellowing calculus textbook. Oh, dear, it was time for another brain transplant. Once into the nitty-gritty of trying to express these formulae in PHP, I noticed that there were a couple of questions of interpretation that arose and crucially had to be resolved. Mathematicians might know when their operations begin and end, but programmers have to be told. Again LINZ was helpful in providing some C++ code which provided critical answers to interpreting the formulae, even if the programmers had taken some liberty in “simplifying” the code (i.e. make it less operation-intense, a question that plays no role today), and so I was able to produce some code that can be more clearly identified with the original formulae.

And then there was one jerk on the internet (just one this time) who claimed that secant was the reciprocal of sine. Go figure.

Finally, there was just a small matter of representing magnetic north. I tried NOAA’s magnetic declination calculator, but that was hidden beneath loads of JavaScript and thus unreachable for normal programming; but the Canadians came in to the rescue. Natural Resources Canada’s calculator is easily accessible (it’s not like my server will be spamming it continuously with magnetic declination requests), so that was chosen and all the data is on board.

In any case, most of the longer tramps and kayak trips are now available for sale or download from the page “GPS and Topo Downloads” as either KML/GPS/GPX files (a couple of KB each) or the full monty as Topo 50 maps (several MB). Each topo map set has an index sheet with details of which of LINZ’s maps were used as well as the map in full resolution and scale. Longer trips consist of several overlapping maps whose distribution is also shown on the index sheet. All sheets whether index or maps can be printed on A4 sized paper with margins of about 10 mm, and from there you can do what you want with them (laminate them, for example).

For the scripts and the demonstration below, the results can be checked with the official LINZ converter and the settings are the conversion between New Zealand Geodetic Datum 2000 (version 20160701) and New Zealand Transverse Mercator Projection. Accept no imitations or substitutes. The results should agree to umpteen decimal places. In fact, you can probably use the accuracy to measure gravitational waves.

The scripts can be found here: Geodetic/Topographical Conversion Script for PHP (376 downloads ) , Geodetic/Topographical Conversion Script for JavaScript (568 downloads )

How the JS script works is demonstrated by this converter:

Decimal Degrees Longitude: °
Latitude: °
Degrees, Minutes, Seconds Longitude: °'"
Latitude: °'"

Transverse Mercator Coordinates Easting:
Northing: