I know this question looks like a duplicate of this, but in that post, the answer does not give the right answer.


Given two UTM coordinates, how would I go about finding the distance between them in Mathematica?

Also, using the below approach, what is the units of the outputted answer?

Norm[{359577, 5.51291*10^6, 0} - {509108, 5.972*10^6, 0}]
EuclideanDistance[{359577, 5.51291*10^6, 0}, {509108, 5.972*10^6, 0}]
  • $\begingroup$ "in that post, the answer does not give the right answer." - can you specify an example where GeoDistance[] fails? $\endgroup$ – J. M. is in limbo Aug 1 '16 at 21:13
  • $\begingroup$ In the single answer in that post, at the very end, the user gets 482985. m when he says the points are really 157 meters apart. $\endgroup$ – Sham Says Aug 1 '16 at 21:23
  • $\begingroup$ While I'm far from an expert in map projections assuming the UTM coordinates are in the same Zone, then it's the Euclidean distance as described in the duplicate question. And clearly the farther apart the coordinates are, the poorer the approximation to the length of a line on the globe between the two coordinates. (If the answer to the duplicate question isn't correct, please state why.) $\endgroup$ – JimB Aug 1 '16 at 21:23
  • $\begingroup$ Ok, then what's the units of the answer? Meters, centimeters? $\endgroup$ – Sham Says Aug 1 '16 at 21:25
  • 2
    $\begingroup$ It's whatever the input coordinates are in. Usually it's meters for UTM's. $\endgroup$ – JimB Aug 1 '16 at 21:40


Apology: I read the post mentioned above incorrectly. The "157 m difference" has to do with the difference between the Euclidean distance using the UTM coordinate system and the geodesic distance (from GeoDistance) rather than the distance between the two locations. The two points in question are over 480 km apart and with any 3D-to-2D map projection, the farther apart two locations are the farther apart are any measures between those two locations. In this case a difference in 157 m is small (about 0.03 percent) compared to the distance between the locations. That's just what can happen with any map projection.

End of Update

The UTM locations given in the post you mention (with coordinates {359577, 5.51291*10^6} and {509108, 5.972*10^6}) are simply not 157 m apart. But here is how to get UTM coordinates and the distance between two locations:

(* Two locations {latitude,longitude} in degrees *)
loc1 = {49.7021, 7.0422}
loc2 = {49.701, 7.0420}

(* Convert to UTM Zone 32 coordinates *)
utm1 = GeoGridPosition[GeoPosition[loc1], "UTMZone32"]
(* GeoGridPosition[{358829.5878969211`,5.507349541635585*10^6}, "UTMZone32"] *)
utm2 = GeoGridPosition[GeoPosition[loc2], "UTMZone32"]
(* GeoGridPosition[{358811.97903316177`,5.5072276325212475*10^6}, "UTMZone32"] *)

(* Find distance between the two locations *)
UnitConvert[GeoDistance[loc1, loc2], "meters"]
(* 123.19340149964208 m *)
UnitConvert[GeoDistance[utm1, utm2], "meters"]
(* 123.1934014982296 m *)
Norm[utm1[[1]] - utm2[[1]]]
(* 123.17428401031748 *)

If you start out with UTM's in meters from Zone 32, then you can find the distance between the two locations with

xy1 = GeoGridPosition[{358829.5878969211, 5.507349541635585*10^6}, "UTMZone32"]
xy2 = GeoGridPosition[{358811.97903316177, 5.5072276325212475*10^6}, "UTMZone32"]
UnitConvert[GeoDistance[xy1, xy2], "meters"]
  • $\begingroup$ How the difference between the distances obtained in two equivalent ways (via GeoPosition and GeoGridPosition) can be explained? $\endgroup$ – Alexey Popkov Aug 2 '16 at 5:42
  • $\begingroup$ @AlexeyPopkov I assume the difference is due to a lack of infinite precision (my term, I'm sure that's not a meaningful mathematical term) when converting from lat/long to UTM's. Using the numbers as given above the difference is Quantity[1.412473693562788*10^-9, "Meters"] and when rationalizing the lat/long values the difference is a bit smaller at Quantity[-1.0611387324388488*10^-9, "Meters"]. $\endgroup$ – JimB Aug 2 '16 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.