I am trying to get senseful results in my Python script. I want to measure distance between features in a shapefile. I'm working with the SRS: GCS_WGS_1984, so my units are in degrees. But for the user, it would be better to have these units in meters, for more comprehension.
How can I convert degrees into meters? I'd like to not reproject my shapefile...
-
I know you said you don't want to reproject the shapefile but it is quite easy to do so. Here is a sample script how to do it: gis.stackexchange.com/questions/61303/…– ustroetzCommented May 27, 2013 at 23:52
-
stackoverflow.com/questions/27928/…– urcmCommented May 28, 2013 at 6:31
Add a comment
|
1 Answer
Use the Haversine Formula to calculate distance between two points. Here is a simple Python version that returns the distance in kilometers:
from math import cos, sin, asin, sqrt, radians
def calc_distance(lat1, lon1, lat2, lon2):
"""
Calculate the great circle distance between two points
on the earth (specified in decimal degrees)
"""
# convert decimal degrees to radians
lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
# haversine formula
dlon = lon2 - lon1
dlat = lat2 - lat1
a = sin(dlat / 2) ** 2 + cos(lat1) * cos(lat2) * sin(dlon / 2) ** 2
c = 2 * asin(sqrt(a))
km = 6371 * c
return km
-
2-1 Calculating a distance between points is not the problem I'm trying to solve. Essentially, I need a formula for
(lat, lon, heading, radius) -> (lat, lon)
Commented Mar 31, 2014 at 16:30