How to use the geopy.distance.vincenty function in geopy

To help you get started, we’ve selected a few geopy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github geometalab / OSMDeepOD / src / service / PositionHandler.py View on Github external
def getDistantBetweenPoinsInMeters(self, pointA, pointB):
        return vincenty(pointA, pointB).meters
github SEL-Columbia / infrastructure-planning / infrastructure_planning / preprocessors.py View on Github external
geometries.append(geometry)
        else:
            L.warn(
                'Ignoring incompatible geometry '
                'in grid_mv_line_geotable (%s)' % geometry.wkt)
            xs.append(x)
    grid_mv_line_geotable.drop(grid_mv_line_geotable.index[xs])
    # Remove elevation
    geometries = transform_geometries(geometries, drop_z)
    # Match coordinate order
    if geometries:
        regular = tuple(GeometryCollection(geometries).centroid.coords[0])[:2]
        flipped = regular[1], regular[0]
        reference = tuple(demand_point_table[['longitude', 'latitude']].mean())
        # If the flipped coordinates are closer,
        if get_distance(reference, flipped) < get_distance(reference, regular):
            # Flip coordinates to get (longitude, latitude) coordinate order
            geometries = transform_geometries(geometries, flip_xy)
    grid_mv_line_geotable['wkt'] = [x.wkt for x in geometries]
    return {'grid_mv_line_geotable': grid_mv_line_geotable}
github EricssonResearch / monad / TravelRecommendation / Scripts / TravelRecommendation_version_1.1.py View on Github external
def timeApproximation(lat1, lon1, lat2, lon2):
    point1 = (lat1, lon1)
    point2 = (lat2, lon2)
    distance = vincenty(point1, point2).kilometers
    return int(round(distance / 10 * 60))
github burakbayramli / kod / nomadicterrain / ui / main.py View on Github external
locs = polyline.decode(coords,precision=6)
    locs = [list(x) for x in locs]

    lat2,lon2 = my_curr_location()

    # sample / interpolate to create more points from line segments
    # so closest point is more fine grained
    roi = np.array(locs)
    steps = np.linspace(roi[:,0].min(), roi[:,0].max(),100.0)
    fsampled = np.interp(steps, roi[:,0], roi[:,1])
    fs2 = [[lat,lon] for (lat,lon) in zip(steps, fsampled)]
    df = pd.DataFrame(fs2)
    df.loc[:,'dist'] = df.apply(lambda x: geopy.distance.vincenty((lat2,lon2),(x[0],x[1])).km, axis=1)
    res = df.ix[df['dist'].idxmin()]
    c = [res[0],res[1]]
    d = geopy.distance.vincenty((lat2,lon2),c).km
    b = route.get_bearing([lat2,lon2],(c[0],c[1]))

    print (d,b)
    
    fout = "static/out-%s.png" % uuid.uuid4()
    clean_dir()
    map = OnlyOne().map
    zfile,scale = params['mapzip'][map]
    locs.insert(0,(lat2,lon2))
    locs.insert(0,c)        
    plot_map.plot(locs, fout, zfile=zfile, scale=scale, pixel=True, bp=True)
    return render_template('/poly.html', location=fout, distance=d, bearing=b)
github demisto / content / Scripts / CalculateGeoDistance / CalculateGeoDistance.py View on Github external
from CommonServerUserPython import *
import geopy.distance

requests.packages.urllib3.disable_warnings()

try:
    # Extract each set of coordinates and create a list
    src_coords_list = argToList(demisto.args()['src_coords'])
    dest_coords_list = argToList(demisto.args()['dest_coords'])

    # Convert each coordinate to a Float value and add to a tuple
    src_coords = (float(src_coords_list[0]), float(src_coords_list[1]))
    dest_coords = (float(dest_coords_list[0]), float(dest_coords_list[1]))

    # Compute distance between the set in miles
    geo_distance = round(geopy.distance.vincenty(src_coords, dest_coords).miles, 2)
    hr = 'Calculated Distance: {} miles.'.format(str(geo_distance))
    context = {
        "Geo.Distance": geo_distance,
        "Geo.Coordinates": [src_coords, dest_coords]
    }

    return_outputs(hr, context, geo_distance)


except Exception as ex:
    return_error('Error occurred while parsing output from command. Exception info:\n' + str(ex))
github burakbayramli / kod / nomadicterrain / ui / main.py View on Github external
dists.append([point, d.km])
                prev = point

    disp.append("Total distance %f " % total_dist)
    disp.append("Total elevation %f " % (elev_max-elev_min))
    dists = np.array(dists)
    start_idx = dists[:,1].argmin()

    front = [0.1, 0.2, 10000.0]
    elev_mins = [10000.0, 10000.0, 10000.0]
    elev_maxs = [-10000.0, -10000.0, -10000.0]
    curr_dist= float(0.0)
    prev = None
    if elevs:
       for i in range(start_idx, len(dists)):    
           if prev: curr_dist += (geopy.distance.vincenty((dists[i][0].latitude,
                                                           dists[i][0].longitude),
                                                          (prev.latitude,
                                                           prev.longitude))).km
           for j in range(len(front)):
               if curr_dist < front[j]:
                   if dists[i][0].elevation < elev_mins[j]: elev_mins[j] = dists[i][0].elevation
                   if dists[i][0].elevation > elev_maxs[j]: elev_maxs[j] = dists[i][0].elevation
           prev = dists[i][0] 

       disp.append("For the next x km the elevation change will be")
       for j in range(len(front)):
           disp.append("%f %f" % (front[j], elev_maxs[j]-elev_mins[j]))
           #print (front[j], elev_maxs[j]-elev_mins[j])
    
    return render_template('/trail.html', location=fout, disp=disp, link=gpx.link, first_point_lat=first_point.latitude, first_point_lon=first_point.longitude)
github m-wrzr / populartimes / populartimes / crawler.py View on Github external
def get_circle_centers(b1, b2, radius):
    """
    the function covers the area within the bounds with circles

    :param b1: south-west bounds [lat, lng]
    :param b2: north-east bounds [lat, lng]
    :param radius: specified radius, adapt for high density areas
    :return: list of circle centers that cover the area between lower/upper
    """

    sw = Point(b1)
    ne = Point(b2)

    # north/east distances
    dist_lat = vincenty(Point(sw[0], sw[1]), Point(ne[0], sw[1])).meters
    dist_lng = vincenty(Point(sw[0], sw[1]), Point(sw[0], ne[1])).meters

    circles = cover_rect_with_cicles(dist_lat, dist_lng, radius)
    cords = [
        VincentyDistance(meters=c[0])
        .destination(
            VincentyDistance(meters=c[1])
            .destination(point=sw, bearing=90),
            bearing=0
        )[:2]
        for c in circles
    ]

    return cords
github okfn-brasil / serenata-de-amor / research / develop / 2016-11-24-irio-traveled-speeds-between-meals.py View on Github external
def calculate_distances(x):
    coordinate_list = x[['latitude', 'longitude']].values
    distance_list = [distance(*coordinates_pair).km
                     for coordinates_pair in pairwise(coordinate_list)]
    return np.nansum(distance_list)
github burakbayramli / kod / nomadicterrain / ui / main.py View on Github external
break

    #lat,lon = my_curr_location()
    OnlyOne().last_location = [lat,lon]

    lat2,lon2 = my_curr_location()
    OnlyOne().last_gpx_file = gpx_file
    fout = plot_trail(lat, lon, gpx_file, (lat2,lon2))  

    first_point = None
    for track in gpx.tracks:
        for segment in track.segments:
            for i,point in enumerate(segment.points):
                if i==0: first_point = point
                if prev:
                    prev_dist = geopy.distance.vincenty((point.latitude, point.longitude),(prev.latitude,prev.longitude))
                    total_dist +=  prev_dist.km
                if point.elevation:
                    elevs = True
                    if point.elevation < elev_min: elev_min = point.elevation
                    if point.elevation > elev_max: elev_max = point.elevation
                d = geopy.distance.vincenty((point.latitude, point.longitude),(lat,lon))
                dists.append([point, d.km])
                prev = point

    disp.append("Total distance %f " % total_dist)
    disp.append("Total elevation %f " % (elev_max-elev_min))
    dists = np.array(dists)
    start_idx = dists[:,1].argmin()

    front = [0.1, 0.2, 10000.0]
    elev_mins = [10000.0, 10000.0, 10000.0]
github nicolehe / the-best-art / modules.py View on Github external
def get_ISS():
    api = requests.get("http://api.open-notify.org/iss-now.json")
    data = api.json()
    iss = (data["iss_position"]["latitude"], data["iss_position"]["longitude"])
    home = (40.674974, -73.957325)
    dist = vincenty(iss, home).miles
    ISS_closeness = map_val(dist, 0.0, 12450.0, -1.0, 1.0)
    return -1.0 * ISS_closeness