# Should we always calculate length and area in lat,lng to get accurate sizes/lenghts of real world measurements

Heres is the simple case, that we discussed at the office today.

Given a map in local projection where units are meter. Since we are in denmark and we have some very local projections at our hand I will make an example using two projections here.

First one: http://epsg.io/32632 (UTM 32, a very large local projection)

Second one: http://epsg.io/4097 (DKTM1, a very local projection).

The first Point of interest in both coordinate system:

and the second point of interest in both systems:

Now that we have defined the two points in both system we read out the coordinates for both in both systems and calculate the length between them using Pythagoras.

``````Distance in DKTM1 (EPSG:4097) is  : 3082.372235
Distance in UTM32 (EPSG:32632) is : 3081.193264
``````

So the next question is, what is the accurate actual distance in the real world if we send out a guy on the runway to measure the distance between these two points?

How would i calculate this using mathematics? Reproject to lat,lng and do something there?

I will buy a beer for the one that provides the best example, and you can pick it up at either of the two locations :)

• You mention what distance would a surveyor get if she goes out to the runway--yet a different value because she's measuring "on the ground." Measuring in a projected CRS or using Haversine/great circle/Vincenty/other geodesic algorithm is that they're measuring on either the projection plane or on a sphere or ellipsoid surface. None of that is the "ground." A surveyor would adjust the measured distance to get it from ground to grid (plane) or ellipsoid surface. – mkennedy Oct 14 '16 at 19:03
• See this recent related question gis.stackexchange.com/questions/212867/… – Martin F Oct 18 '16 at 19:25

For a small distance like 3081 or 3082 meters, it shouldn't matter very much for most applications which "projection" you use (as you've seen ~1m) but you don't want to use lat/long (geographic coordinates). For calculating large distances you should probably use an Equidistant Projection which will calculate distance minimizing distance distortion.

You typically will get a better result that minimizes distance distortion by using a local Cartesian system. You would rarely want to use a Geographic system since distance varies greatly at different points on the earth. I would make the assumption that the DKM1 projection is giving you a better result since you said it was "very local".

If you really want to calculate distances using latitude and longitude, you can use the Haversine formula which uses trigonometry to calculate a "great circle" distance (shortest distance between points on a sphere) or the even more accurate Vincenty Formula.

I'm also referencing: "Learning Geospatial Analysis with Python" by Joel Lawhead which has python code for calculating distances with the Pythagorean Theorum as well as Haversine, and Vincenty.

EDIT - To address your comment: My interpretation of this in the book that I referenced was that bringing in the geographic coordinate system even with the more precise Vincenty formula adds some error to the calculation. The author uses the Mississippi Transverse Mercator Coordinate system (MSTS) to calculate the Euclidean distance initially and treats that as the correct distance (+/-). We all know it is not "correct" since the datum and ellipsoid used provide a model only and this model is not ever going to be perfect. I believe it is treated in the book as the most accurate known way to calculate the distance without using surveying instruments on the ground. If no "more local" coordinate system is known, UTM would still give the best answer.

In that example the distances are measured in Kilometers and the error is about 0.1 Km even with the Vincenty formula (240.2 from MSTS vs. 251Km using Decimal Degrees converted to Radians vs. 240.6Km-Haversine vs. 240.1Km-Vincenty).

• We started the discussion due to that we have a requirement where we are given the two points P1 and P2 and needed to extend the line they form with X (X > 10s of kms). This P3 is something that the user will look at and expect to be accurate to less than 1m. Our first implementation used a UTM cooridnate system and this is where we discovred that the UTM projection was not accurate enough for our requirement and we started discussing this things :) Our engineers have methods in their GIS deskop applications that have this feature "X km in a direction" where it is not using local projection. – Poul K. Sørensen Oct 14 '16 at 15:12
• Could you comment on, using Haversine or Vincenty, does those provide a better measurement than a a general UTM coordinate system for places where a "very local" projection is not known? – Poul K. Sørensen Oct 14 '16 at 15:14
• Thanks, so my next step would be to find out which vincenty/haversine implemention the GIS desktop application uses (we are using global mapper) and then I am correct to argue that extending the line P1P2 by X in local coordinate system (UTM) would be more accurate towatch the real world over using geodesic measurments by vincenty/haversine function? (Since I dont have the years of experience in this I just need to make the argument very clear such I can make the correct decision for our development). Much appreciated for the feedback you provide – Poul K. Sørensen Oct 14 '16 at 17:12
• That is my understanding. Your 3082.372235 is probably about as good as you can get. – jbchurchill Oct 14 '16 at 17:19
• Be careful with statements about "equidistant" projections minimizing distance distortions. They cannot perform magic; they only preserve distances in some directions. – Martin F Oct 18 '16 at 19:28

For others to use, we did the following in ol3. Creating a local projection allowed us to have similar area/length calculations as if we was using great circle calculations. Here is our code for creating a local projection.

createLocalProjection.ts

``````import ol = require("openLayers");
import proj4 = require("proj4");

ol.proj.setProj4(proj4);

export function createLocalProjection(projkey: string, center_wgs84: number[], buffer_meter: number) {
proj4.defs(projkey, `+proj=tmerc +lat_0=\${center_wgs84} +lon_0=\${center_wgs84} +x_0=0 +y_0=0 +towgs84=0,0,0,0,0,0,0 +units=m +vunits=m +no_defs`);

var newProj = ol.proj.get(projkey);
var fromLonLat = ol.proj.getTransform('EPSG:4326', newProj);
let center = fromLonLat(center_wgs84);
let extent = [center - buffer_meter, center - buffer_meter, center + buffer_meter, center + buffer_meter];
newProj.setExtent(extent);

return newProj;
}
``````