当前位置: 首页>>代码示例>>Python>>正文


Python distance.great_circle方法代码示例

本文整理汇总了Python中geopy.distance.great_circle方法的典型用法代码示例。如果您正苦于以下问题:Python distance.great_circle方法的具体用法?Python distance.great_circle怎么用?Python distance.great_circle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在geopy.distance的用法示例。


在下文中一共展示了distance.great_circle方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_search_points

# 需要导入模块: from geopy import distance [as 别名]
# 或者: from geopy.distance import great_circle [as 别名]
def get_search_points(self, cell_id):
        points = []

        # For cell level 15
        for c in Cell(CellId(cell_id)).subdivide():
            for cc in c.subdivide():
                latlng = LatLng.from_point(cc.get_center())
                point = (latlng.lat().degrees, latlng.lng().degrees)
                points.append(point)

        points[0], points[1] = points[1], points[0]
        points[14], points[15] = points[15], points[14]
        point = points.pop(2)
        points.insert(7, point)
        point = points.pop(13)
        points.insert(8, point)

        closest = min(points, key=lambda p: great_circle(self.bot.position, p).meters)
        index = points.index(closest)

        return points[index:] + points[:index] 
开发者ID:PokemonGoF,项目名称:PokemonGo-Bot,代码行数:23,代码来源:pokemon_hunter.py

示例2: test_haversine_distance

# 需要导入模块: from geopy import distance [as 别名]
# 或者: from geopy.distance import great_circle [as 别名]
def test_haversine_distance():
    try:
        from geopy.distance import great_circle
    except ImportError:
        raise pytest.skip("scikit-learn not installed")

    rng = np.random.RandomState(42)

    N = 100

    x = rng.rand(N, 2) * 80
    y = x * rng.rand(N, 2)

    d_ref = np.zeros(N)
    for idx, (x_coord, y_coord) in enumerate(zip(x, y)):
        d_ref[idx] = great_circle(x_coord, y_coord).km

    d_pred = haversine_distance(x, y)
    # same distance +/- 3 km
    assert_allclose(d_ref, d_pred, atol=3) 
开发者ID:symerio,项目名称:pgeocode,代码行数:22,代码来源:test_pgeocode.py

示例3: get_alt

# 需要导入模块: from geopy import distance [as 别名]
# 或者: from geopy.distance import great_circle [as 别名]
def get_alt(self, at_point=None):
        if at_point is None:
            at_point = self._last_pos
        if self._elevation_at_point:
            elevations = sorted([(great_circle(at_point, k).meters, v, k) for k, v in self._elevation_at_point.items()])

            if len(elevations) == 1:
                return elevations[0][1]
            else:
                (distance_to_p1, ep1, p1), (distance_to_p2, ep2, p2) = elevations[:2]
                distance_p1_p2 = great_circle(p1, p2).meters
                return self._get_relative_hight(ep1, ep2, distance_p1_p2, distance_to_p1, distance_to_p2)
        else:
            return None 
开发者ID:PokemonGoF,项目名称:PokemonGo-Bot,代码行数:16,代码来源:polyline_generator.py

示例4: update_cluster_distance

# 需要导入模块: from geopy import distance [as 别名]
# 或者: from geopy.distance import great_circle [as 别名]
def update_cluster_distance(self, cluster):
        cluster["distance"] = great_circle(self.bot.position, cluster["center"]).meters 
开发者ID:PokemonGoF,项目名称:PokemonGo-Bot,代码行数:4,代码来源:camp_fort.py

示例5: get_distance

# 需要导入模块: from geopy import distance [as 别名]
# 或者: from geopy.distance import great_circle [as 别名]
def get_distance(self, location, fort):
        return great_circle(location, (fort["latitude"], fort["longitude"])).meters 
开发者ID:PokemonGoF,项目名称:PokemonGo-Bot,代码行数:4,代码来源:camp_fort.py

示例6: get_distance

# 需要导入模块: from geopy import distance [as 别名]
# 或者: from geopy.distance import great_circle [as 别名]
def get_distance(self, location, pokemon):
        return great_circle(location, (pokemon["latitude"], pokemon["longitude"])).meters 
开发者ID:PokemonGoF,项目名称:PokemonGo-Bot,代码行数:4,代码来源:pokemon_hunter.py

示例7: populate_sql

# 需要导入模块: from geopy import distance [as 别名]
# 或者: from geopy.distance import great_circle [as 别名]
def populate_sql():
    """
    Create and populate the sqlite3 database with GeoNames data. Requires Geonames dump.
    No need to run this function, I share the database as a separate dump on GitHub (see link).
    """
    geo_names = {}
    p_map = {"PPLC": 100000, "PCLI": 100000, "PCL": 100000, "PCLS": 10000, "PCLF": 10000, "CONT": 100000, "RGN": 100000}

    for line in codecs.open(u"../data/allCountries.txt", u"r", encoding=u"utf-8"):
        line = line.split("\t")
        feat_code = line[7]
        class_code = line[6]
        pop = int(line[14])
        for name in [line[1], line[2]] + line[3].split(","):
            name = name.lower()
            if len(name) != 0:
                if name in geo_names:
                    already_have_entry = False
                    for item in geo_names[name]:
                        if great_circle((float(line[4]), float(line[5])), (item[0], item[1])).km < 100:
                            if item[2] >= pop:
                                already_have_entry = True
                    if not already_have_entry:
                        pop = get_population(class_code, feat_code, p_map, pop)
                        geo_names[name].add((float(line[4]), float(line[5]), pop, feat_code))
                else:
                    pop = get_population(class_code, feat_code, p_map, pop)
                    geo_names[name] = {(float(line[4]), float(line[5]), pop, feat_code)}

    conn = sqlite3.connect(u'../data/geonames.db')
    c = conn.cursor()
    # c.execute("CREATE TABLE GEO (NAME VARCHAR(100) PRIMARY KEY NOT NULL, METADATA VARCHAR(5000) NOT NULL);")
    c.execute(u"DELETE FROM GEO")  # alternatively, delete the database file.
    conn.commit()

    for gn in geo_names:
        c.execute(u"INSERT INTO GEO VALUES (?, ?)", (gn, str(list(geo_names[gn]))))
    print(u"Entries saved:", len(geo_names))
    conn.commit()
    conn.close() 
开发者ID:milangritta,项目名称:Geocoding-with-Map-Vector,代码行数:42,代码来源:preprocessing.py

示例8: distance

# 需要导入模块: from geopy import distance [as 别名]
# 或者: from geopy.distance import great_circle [as 别名]
def distance(self, lat: float, lon: float) -> Distance:
        """
        Returns a geopy Distance using the great circle method
        """
        return great_circle((lat, lon), (self.latitude, self.longitude)) 
开发者ID:avwx-rest,项目名称:avwx-engine,代码行数:7,代码来源:station.py

示例9: set_contextual_features

# 需要导入模块: from geopy import distance [as 别名]
# 或者: from geopy.distance import great_circle [as 别名]
def set_contextual_features(self):
        """
        GeonameFeatures are initialized with only values that can be extracted
        from the geoname database and span. This extends the GeonameFeature
        with values that require information from nearby_mentions.
        """
        geoname = self.geoname
        close_locations = 0
        very_close_locations = 0
        containing_locations = 0
        contained_locations = 0
        for recently_mentioned_geoname in self.nearby_mentions:
            if recently_mentioned_geoname == geoname:
                continue
            if location_contains(recently_mentioned_geoname, geoname) > 0:
                containing_locations += 1
            if location_contains(geoname, recently_mentioned_geoname) > 0:
                contained_locations += 1
            distance = great_circle(
                recently_mentioned_geoname.lat_long, geoname.lat_long
            ).kilometers
            if distance < 400:
                close_locations += 1
            if distance < 100:
                very_close_locations += 1
        greatest_overlapping_score = 0.0
        for location in geoname.overlapping_locations:
            if location.base_score > greatest_overlapping_score:
                greatest_overlapping_score = location.base_score
        self.set_values(dict(
            close_locations=close_locations,
            very_close_locations=very_close_locations,
            base_score=geoname.base_score,
            base_score_margin=geoname.base_score - greatest_overlapping_score,
            containing_locations=containing_locations,
            contained_locations=contained_locations,
        )) 
开发者ID:ecohealthalliance,项目名称:EpiTator,代码行数:39,代码来源:geoname_annotator.py

示例10: order_lines

# 需要导入模块: from geopy import distance [as 别名]
# 或者: from geopy.distance import great_circle [as 别名]
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:
                min_dist = d3
                idx = i
                insert_idx = len(ordered_coords)
                reverse = False
  
            if d4 < min_dist:
                min_dist = d4
                idx = i
                insert_idx = len(ordered_coords)
                reverse = True
  
        feature = features.pop(idx)
        coords = feature['geometry']['coordinates']
        coords = coords[::-1] if reverse else coords
        ordered_coords.insert(insert_idx, coords)
    return [item for sublist in ordered_coords for item in sublist] 
开发者ID:metro-ontime,项目名称:performance_tracker,代码行数:50,代码来源:track.py

示例11: geoparse

# 需要导入模块: from geopy import distance [as 别名]
# 或者: from geopy.distance import great_circle [as 别名]
def geoparse(text):
    """
    This function allows one to geoparse text i.e. extract toponyms (place names) and disambiguate to coordinates.
    :param text: to be parsed
    :return: currently only prints results to the screen, feel free to modify to your task
    """
    doc = nlp(text)  # NER with Spacy NER
    for entity in doc.ents:
        if entity.label_ in [u"GPE", u"FACILITY", u"LOC", u"FAC", u"LOCATION"]:
            name = entity.text if not entity.text.startswith('the') else entity.text[4:].strip()
            start = entity.start_char if not entity.text.startswith('the') else entity.start_char + 4
            end = entity.end_char
            near_inp = pad_list(CONTEXT_LENGTH / 2, [x for x in doc[max(0, entity.start - CONTEXT_LENGTH / 2):entity.start]], True, padding) + \
                       pad_list(CONTEXT_LENGTH / 2, [x for x in doc[entity.end: entity.end + CONTEXT_LENGTH / 2]], False, padding)
            far_inp = pad_list(CONTEXT_LENGTH / 2, [x for x in doc[max(0, entity.start - CONTEXT_LENGTH):max(0, entity.start - CONTEXT_LENGTH / 2)]], True, padding) + \
                      pad_list(CONTEXT_LENGTH / 2, [x for x in doc[entity.end + CONTEXT_LENGTH / 2: entity.end + CONTEXT_LENGTH]], False, padding)
            map_vector = text2mapvec(doc=near_inp + far_inp, mapping=ENCODING_MAP_1x1, outliers=OUTLIERS_MAP_1x1, polygon_size=1, db=conn, exclude=name)

            context_words, entities_strings = [], []
            target_string = pad_list(TARGET_LENGTH, [x.text.lower() for x in entity], True, u'0')
            target_string = [word_to_index[x] if x in word_to_index else word_to_index[UNKNOWN] for x in target_string]
            for words in [near_inp, far_inp]:
                for word in words:
                    if word.text.lower() in word_to_index:
                        vec = word_to_index[word.text.lower()]
                    else:
                        vec = word_to_index[UNKNOWN]
                    if word.ent_type_ in [u"GPE", u"FACILITY", u"LOC", u"FAC", u"LOCATION"]:
                        entities_strings.append(vec)
                        context_words.append(word_to_index[u'0'])
                    elif word.is_alpha and not word.is_stop:
                        context_words.append(vec)
                        entities_strings.append(word_to_index[u'0'])
                    else:
                        context_words.append(word_to_index[u'0'])
                        entities_strings.append(word_to_index[u'0'])

            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]


# Example usage of the geoparse function below reading from a directory and parsing all files. 
开发者ID:milangritta,项目名称:Geocoding-with-Map-Vector,代码行数:63,代码来源:geoparse.py


注:本文中的geopy.distance.great_circle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。