Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to transform a distance from degrees to metres?

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

like image 729
Mulone Avatar asked Nov 05 '10 00:11

Mulone


People also ask

How long is a degree in meters?

So, for latitude the number of degrees from the pole to the equator is 90∘, and the number of meters is 10 million (or 10,000 kilometers). That means 1∘ of latitude is 10,000/90=111 kilometers, and 0.001∘=0.111 kilometers or 111 meters, essentially an American football field plus both endzones.

What is the distance of 1 degree?

One degree of latitude equals approximately 364,000 feet (69 miles), one minute equals 6,068 feet (1.15 miles), and one-second equals 101 feet. One-degree of longitude equals 288,200 feet (54.6 miles), one minute equals 4,800 feet (0.91 mile), and one second equals 80 feet.


1 Answers

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;
like image 143
blindauer Avatar answered Sep 28 '22 02:09

blindauer