How to use the geopy.distance.great_circle 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 milangritta / Pragmatic-Guide-to-Geoparsing-Evaluation / phd_work.py View on Github external
if name + u":::" + feature_type not in geo_location_pop:
                    geo_location_pop[name + u":::" + feature_type] = []
                geo_location_pop[name + u":::" + feature_type].append(distance)
                toponym_feature_types[label_map[label]].append(feature_type)
            # -------------------- Build two lists of toponyms -------------------------
            if label_map[label] == u"Associative":
                associative.append(toponym)
            else:
                literal.append(toponym)
        accuracy = []
        for assoc in associative:
            if len(literal) == 0:
                continue
            min_dist = numpy.inf
            for lit in literal:
                distance = great_circle((lit.find('latitude').text, lit.find('longitude').text),
                                        (assoc.find('latitude').text, assoc.find('longitude').text)).km
                if distance < min_dist:
                    min_dist = distance
            accuracy.append(min_dist)
        associative_outliers.extend(accuracy)
    # ---------------- Compute Associative Outliers -----------------
    print(u"Total measurements:", len(associative_outliers))
    hist = numpy.histogram(associative_outliers, bins=[0, 100, 200, 300, 400, 500, 750, 1000, 2000, 5000, 10000, 20000])
    for count, bucket in zip(hist[0], hist[1]):
        print(count, ",", bucket)
    # ---------------- Compute Geocoding by Population and Type ----------------
    sorted_by_type = {}
    total = 0
    print(u"Number of unique toponyms:", len(geo_location_pop))
    for toponym in geo_location_pop:
        the_type = toponym.split(u":::")[1]
github anitagraser / movingpandas / sandbox / predict_samples_sts.py View on Github external
    nearest_pt = min(cluster, key=lambda point: great_circle(point, pt).m)
    nearest_pt = Point(nearest_pt[1],nearest_pt[0])
github Ajapaik / ajapaik-web / project / ajapaik / models.py View on Github external
def get_nearest_point(set_of_points, point_of_reference):
        closest_point = None
        closest_dist = None
        for point in set_of_points:
            point = (point[1], point[0])
            dist = great_circle(point_of_reference, point).meters
            if (closest_dist is None) or (dist < closest_dist):
                closest_point = point
                closest_dist = dist
        return closest_point
github PokemonGoF / PokemonGo-Bot / pokemongo_bot / cell_workers / camp_fort.py View on Github external
def update_cluster_distance(self, cluster):
        cluster["distance"] = great_circle(self.bot.position, cluster["center"]).meters
github jpwright / subway / server / flask / TransitModel.py View on Github external
bb.max_lat += 0.02;
    bb.min_lng -= 0.02;
    bb.max_lng += 0.02;
    
    region = TransitGIS.hexagons_bb(bb)
    condensed_region = TransitGIS.HexagonRegion()
    
    # For now just use the first service
    service = m.services[0]
    hexagon_to_station = {}
    
    for hexagon in region.hexagons:
        center = hexagon.center()
        # Look for stations within catchment.
        for station in service.stations:
            distance = great_circle(center, (station.location[0], station.location[1])).miles
            if (distance <= CATCHMENT_DISTANCE):
                if hexagon in hexagon_to_station:
                    hexagon_to_station[hexagon].append(station)
                else:
                    hexagon_to_station[hexagon] = [station]
                if not condensed_region.has_hexagon(hexagon):
                    condensed_region.add_hexagon(hexagon)
    
    ridership = {}
    print "Using "+str(condensed_region.num_hexagons())+" hexagons"
    
    for hexagon_a in condensed_region.hexagons:
        # Get information about Hexagon A
        hexagon_a_center = hexagon_a.center()
        hexagon_a_stations = hexagon_to_station[hexagon_a]
github metro-ontime / performance_tracker / src / library / analyzer / track.py View on Github external
def order_lines(feature_collection):
    features = copy.deepcopy(feature_collection['features'])
    ordered_coords = [features.pop()['geometry']['coordinates']]
    while len(features) > 0:
        min_dist = 1.e6
        idx = 0
        reverse = False
        insert_idx = 0
        for i, feature in enumerate(features):
            coord_list = feature['geometry']['coordinates']
            front_feat = coord_list[0][::-1]
            back_feat = coord_list[-1][::-1]
            front_coords = ordered_coords[0][0][::-1]
            back_coords = ordered_coords[-1][-1][::-1]
            d1 = distance(front_coords, front_feat)
            d2 = distance(front_coords, back_feat)
            d3 = distance(back_coords, front_feat)
            d4 = distance(back_coords, back_feat)
            
            if d1 < min_dist:
                min_dist = d1
                idx = i
                insert_idx = 0
                reverse = True
  
            if d2 < min_dist:
                min_dist = d2
                idx = i
                insert_idx = 0
                reverse = False
  
            if d3 < min_dist:
github jpwright / enmodal / lib / transit / Transit.py View on Github external
def edge_length(self, edge):
        stop_ids = edge.stop_ids
        for line in self.lines:
            if line.has_edge(edge):
                station_a = self.find_station(line.get_stop_by_id(stop_ids[0]).station_id)
                station_b = self.find_station(line.get_stop_by_id(stop_ids[1]).station_id)
                return great_circle((station_a.location[0], station_a.location[1]), (station_b.location[0], station_b.location[1])).miles
        return None
github geopy / geopy / geopy / distance.py View on Github external
d_div_r = float(distance) / self.RADIUS

        lat2 = asin(
            sin(lat1) * cos(d_div_r) +
            cos(lat1) * sin(d_div_r) * cos(bearing)
        )

        lng2 = lng1 + atan2(
            sin(bearing) * sin(d_div_r) * cos(lat1),
            cos(d_div_r) - sin(lat1) * sin(lat2)
        )

        return Point(units.degrees(radians=lat2), units.degrees(radians=lng2))


GreatCircleDistance = great_circle


class geodesic(Distance):
    """
    Calculate the geodesic distance between two points.

    Set which ellipsoidal model of the earth to use by specifying an
    ``ellipsoid`` keyword argument. The default is 'WGS-84', which is the
    most globally accurate model.  If ``ellipsoid`` is a string, it is
    looked up in the `ELLIPSOIDS` dictionary to obtain the major and minor
    semiaxes and the flattening. Otherwise, it should be a tuple with those
    values.  See the comments above the `ELLIPSOIDS` dictionary for
    more information.

    Example::
github metro-ontime / performance_tracker / src / library / analyzer / track.py View on Github external
features = copy.deepcopy(feature_collection['features'])
    ordered_coords = [features.pop()['geometry']['coordinates']]
    while len(features) > 0:
        min_dist = 1.e6
        idx = 0
        reverse = False
        insert_idx = 0
        for i, feature in enumerate(features):
            coord_list = feature['geometry']['coordinates']
            front_feat = coord_list[0][::-1]
            back_feat = coord_list[-1][::-1]
            front_coords = ordered_coords[0][0][::-1]
            back_coords = ordered_coords[-1][-1][::-1]
            d1 = distance(front_coords, front_feat)
            d2 = distance(front_coords, back_feat)
            d3 = distance(back_coords, front_feat)
            d4 = distance(back_coords, back_feat)
            
            if d1 < min_dist:
                min_dist = d1
                idx = i
                insert_idx = 0
                reverse = True
  
            if d2 < min_dist:
                min_dist = d2
                idx = i
                insert_idx = 0
                reverse = False
  
            if d3 < min_dist:
                min_dist = d3
github milangritta / Geocoding-with-Map-Vector / geoparse.py View on Github external
prediction = model.predict([np.array([context_words]), np.array([context_words]), np.array([entities_strings]),
                                        np.array([entities_strings]), np.array([map_vector]), np.array([target_string])])
            prediction = index_to_coord(REVERSE_MAP_2x2[np.argmax(prediction[0])], 2)
            candidates = get_coordinates(conn, name)

            if len(candidates) == 0:
                print(u"Don't have an entry for", name, u"in GeoNames")
                continue

            max_pop = candidates[0][2]
            best_candidate = []
            bias = 0.905  # Tweak the parameter depending on the domain you're working with.
            # Less than 0.9 suitable for ambiguous text, more than 0.9 suitable for less ambiguous locations, see paper
            for candidate in candidates:
                err = great_circle(prediction, (float(candidate[0]), float(candidate[1]))).km
                best_candidate.append((err - (err * max(1, candidate[2]) / max(1, max_pop)) * bias, (float(candidate[0]), float(candidate[1]))))
            best_candidate = sorted(best_candidate, key=lambda (a, b): a)[0]

            # England,, England,, 51.5,, -0.11,, 669,, 676 || - use evaluation script to test correctness
            print name, start, end
            print u"Coordinates:", best_candidate[1]