Example #1
0
 def haversine(latlong1, latlong2):
     if latlong1.hasnans:
         latlong1 = replace_latlong_nan(latlong1)
     if latlong2.hasnans:
         latlong2 = replace_latlong_nan(latlong2)
     lat_1s = np.array([x[0] for x in latlong1])
     lon_1s = np.array([x[1] for x in latlong1])
     lat_2s = np.array([x[0] for x in latlong2])
     lon_2s = np.array([x[1] for x in latlong2])
     lon1, lat1, lon2, lat2 = map(np.radians,
                                  [lon_1s, lat_1s, lon_2s, lat_2s])
     dlon = lon2 - lon1
     dlat = lat2 - lat1
     a = np.sin(dlat / 2.0) ** 2 + np.cos(lat1) * \
         np.cos(lat2) * np.sin(dlon / 2.0)**2
     radius_earth = 3958.7613
     if self.unit == 'kilometers':
         radius_earth = 6371.0088
     distance = radius_earth * 2 * np.arcsin(np.sqrt(a))
     return distance
Example #2
0
 def longitude(latlong):
     if latlong.hasnans:
         latlong = replace_latlong_nan(latlong)
     return latlong.map(lambda x: x[1])
Example #3
0
 def longitude(latlong):
     if latlong.hasnans:
         latlong = replace_latlong_nan(latlong)
     return pd.Series(x[1] for x in latlong)
def test_replace_latlong_nan():
    values = pd.Series([(np.nan, np.nan), np.nan, (10, 5)])
    result = replace_latlong_nan(values)
    assert result[0] == values[0]
    assert result[1] == (np.nan, np.nan)
    assert result[2] == values[2]