How to transform a distance from degrees to metres?
Asked Answered
A

3

16

I'm using OpenLayers with an ordinary mercator map and I'm trying to sample a bounding box by finding a grid of points in latlong. The bbox is expressed in latlon, e.g.

48.1388,-15.3616,55.2057,-3.9359

I can define a distance in degrees (e.g. x: 2.5, y: 2.4) and work out the points from there. But I'd like to express this distance in metres (e.g. 50000) in order to relate it to the user mindset (people understand metres, not degrees). How can I convert this distance? I know how to reproject a point, but not a distance.

Thanks for any hints! Mulone

Asteria answered 5/11, 2010 at 0:6 Comment(0)
O
24

Use the haversine formula to get the distance between two points of lat/long. This assumes the earth is a sphere (which is, for most cases, "good enough").

A Javascript implementation of it (shamelessly stolen from here) looks like this:

var R = 6371; // km
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad(); 
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
        Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * 
        Math.sin(dLon/2) * Math.sin(dLon/2); 
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
var d = R * c;
Obcordate answered 5/11, 2010 at 0:24 Comment(1)
The Haversine works for different latitudes but is the opposite of what the OP is requesting. The OP wants to map linear (metre) distance to degrees latitude and longitude.Tieshatieup
B
11

Without allowing for the slightly non-spherical shape of the earth,

One minute of latitude North to south = 1 Nautical Mile = 6075 feet So One degree = 60 Minutes = 60 * 6075 feet There are 3.28 Feet in a meter so One degree = 60 * 6075 / 3.28 Meters = 111,128 meters

Alternatively, one minute of Latitude = 1,852 Meters So One degree = 60 * 1852 meters = 111,120 meters

I'm not sure which is more accurate...

For One degree of Longitude, do the same thing, but multiply by the Cosine(Latitude) since the Longitude lines converge, (get closer together), as you move north.

Note: if you're using a calculator or computer, make sure you use the right units for the latitude (degrees or radians) that your device requires or is set to use.

Bennion answered 5/11, 2010 at 0:11 Comment(7)
This answer seems to contradict https://mcmap.net/q/46815/-simple-calculations-for-working-with-lat-lon-and-km-distance. I assume I am misunderstanding something. What is the difference between the two answers?Larson
The two answers are different by only (111.128 - 110.574)/ 111.128 = 0.498%Bennion
What causes the difference? I'm unclear on which numbers I should be using.Larson
You are missing the point. In the real world, No numerical measurement answer is or ever can be 100% accurate. You are not counting things! You are measuring something real. Any measurement you make is and will be inaccurate to a degree. The question is to what degree, (what level of accuracy), is the measurement ? If you need accuracy greater than +- 0.498%, then none of the simplified formulae will suffice for every point or pair of points on the globe. If you demand perfect accuracy, then go out and measure it with a tape measure. And that will change from moment to moment!Bennion
Gotcha. Makes sense. I imagined it to be as accurate as going out with measuring tape. Good to know it isn't! Thanks!Larson
No Measurement can ever be 100% accurate. Even the Tape measure! How accurate is the tape measure? It shrinks and expands as temperature changes, as you pull on it, If it is bent slightly, etc. etc. Sure they are small changes, but that's the point! They are way bigger than a laser measurement that counts wavelengths. And laser wavelengths change depending on the strength of the gravitational field. The real question is: How big an error or uncertainty is significant for the purpose for which you need the measurement?Bennion
There used to be a somewhat facetious saying in carpentry: "Measure with a micrometer, mark it with a pencil, cut it with an axe,."Bennion
T
1

The transformation between degrees and metres varies across the Earth's surface.

Assuming a spherical Earth, degrees latitude = distance * 360 / (2*PI * 6400000)

Note that longitude will vary according to the latitude:

Degrees longitude = distance *360 * / (2*PI* cos(latitude) )

The above is for the Earth's surface, and does not use the Mercator projection. If you wish to work with projected linear distance, then you will need to use the Mercator projection.

Tieshatieup answered 5/11, 2010 at 0:15 Comment(2)
And for the more general case when working with different map projections in javascript, use the open source Proj4js library. - which is also used by OpenLayers.Tieshatieup
Unit of measurements of the longitude makes no sense. You have degrees on one side and meters times degrees on the other. Do you have to divided times the radius earth, as ` longitude = distance 360 * / (2*PI cos(latitude) * 6400000)`?Schleiermacher

© 2022 - 2024 — McMap. All rights reserved.