diff options
author | Étienne Simon <esimon@esimon.eu> | 2015-05-02 05:17:11 +0000 |
---|---|---|
committer | Étienne Simon <esimon@esimon.eu> | 2015-05-02 05:17:11 +0000 |
commit | a042000073bf348fddff23f41d30f49f2e874adb (patch) | |
tree | 2d2c5d275a7e8d335b1df5b6d6eac4387eda4a0c | |
parent | 12fbc9b96ea1ef2727c87c02fe8d2305235b4d15 (diff) | |
download | taxi-a042000073bf348fddff23f41d30f49f2e874adb.tar.gz taxi-a042000073bf348fddff23f41d30f49f2e874adb.zip |
Add equirectangular distance
-rw-r--r-- | hdist.py | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -2,6 +2,9 @@ from theano import tensor import theano import numpy +rearth = const(6371) +deg2rad = const(3.141592653589793 / 180) + def const(v): if theano.config.floatX == 'float32': return numpy.float32(v) @@ -9,9 +12,6 @@ def const(v): return numpy.float64(v) def hdist(a, b): - rearth = const(6371) - deg2rad = const(3.141592653589793 / 180) - lat1 = a[:, 0] * deg2rad lon1 = a[:, 1] * deg2rad lat2 = b[:, 0] * deg2rad @@ -27,5 +27,11 @@ def hdist(a, b): return tensor.switch(tensor.eq(hd, float('nan')), (a-b).norm(2, axis=1), hd) - - +def erdist(a, b): + lat1 = a[:, 0] * deg2rad + lon1 = a[:, 1] * deg2rad + lat2 = b[:, 0] * deg2rad + lon2 = b[:, 1] * deg2rad + x = (lon2-lon1) * tensor.cos((lat1+lat2)/2) + y = (lat2-lat1) + return tensor.sqrt(tensor.sqr(x) + tensor.sqr(y)) * rearth |