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


Python geohash.encode方法代码示例

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


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

示例1: index

# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import encode [as 别名]
def index(request):
    token = request.headers.get("X-Token")
    if token not in G.config.tokens:
        C["global"].update({"401": 1})
        raise SanicException("Unauthorized", status_code=401)
    try:
        latitude = float(request.args.get("lat", default=None))
        longitude = float(request.args.get("lon", default=None))
        ghash = geohash.encode(latitude, longitude, G.config.precision)
    except:
        C["stats"][token[:6]].update({"400": 1})
        raise SanicException("Bad Request", status_code=400)
    try:
        data = search(ghash)
        if data is None:
            C["stats"][token[:6]].update({"404": 1})
            return jsonify(G.config.fallback)
        else:
            C["stats"][token[:6]].update({"200": 1})
            return jsonify(data)
    except:
        C["stats"][token[:6]].update({"500": 1})
        return jsonify(G.config.fallback) 
开发者ID:uol,项目名称:geo-br,代码行数:25,代码来源:sapp.py

示例2: index_documents

# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import encode [as 别名]
def index_documents(docs):
    pipe = DB.pipeline(transaction=False)
    for doc in docs:
        if not doc:
            continue
        if doc.get('_action') in ['delete', 'update']:
            key = keys.document_key(doc['_id']).encode()
            known_doc = get_document(key)
            if known_doc:
                deindex_document(known_doc)
        if doc.get('_action') in ['index', 'update', None]:
            index_document(pipe, doc)
        yield doc
    try:
        pipe.execute()
    except redis.RedisError as e:
        msg = 'Error while importing document:\n{}\n{}'.format(doc, str(e))
        raise ValueError(msg) 
开发者ID:addok,项目名称:addok,代码行数:20,代码来源:index.py

示例3: __call__

# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import encode [as 别名]
def __call__(self, lat, lon, limit=1, **filters):
        self.lat = lat
        self.lon = lon
        self.keys = set([])
        self.results = []
        self.wanted = limit
        self.fetched = []
        self.check_housenumber = filters.get('type') in [None, "housenumber"]
        self.filters = [dbkeys.filter_key(k, v) for k, v in filters.items()]
        geoh = geohash.encode(lat, lon, config.GEOHASH_PRECISION)
        hashes = self.expand([geoh])
        self.fetch(hashes)
        if not self.keys:
            hashes = self.expand(hashes)
            self.fetch(hashes)
        return self.convert() 
开发者ID:addok,项目名称:addok,代码行数:18,代码来源:core.py

示例4: geohash_encode

# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import encode [as 别名]
def geohash_encode(
    df: DataFrame, geohash: str, longitude: str, latitude: str,
) -> DataFrame:
    """
    Encode longitude and latitude into geohash

    :param df: DataFrame containing longitude and latitude data
    :param geohash: Name of new column to be created containing geohash location.
    :param longitude: Name of source column containing longitude.
    :param latitude: Name of source column containing latitude.
    :return: DataFrame with decoded longitudes and latitudes
    """
    try:
        encode_df = df[[latitude, longitude]]
        encode_df.columns = ["latitude", "longitude"]
        encode_df["geohash"] = encode_df.apply(
            lambda row: geohash_lib.encode(row["latitude"], row["longitude"]), axis=1,
        )
        return _append_columns(df, encode_df, {"geohash": geohash})
    except ValueError:
        QueryObjectValidationError(_("Invalid longitude/latitude")) 
开发者ID:apache,项目名称:incubator-superset,代码行数:23,代码来源:pandas_postprocessing.py

示例5: three_words

# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import encode [as 别名]
def three_words(self, lat_long):
        """Convert coordinate to a combination of three words

        The coordinate is defined by latitude and longitude
        in degrees.
        """
        lat, lon = lat_long
        gh = geohash.encode(lat, lon, 9)
        words = "-".join(self.three_wordlist[p] for p in self.to_rugbits(self.geo_to_int(gh)))
        return words 
开发者ID:Placeware,项目名称:ThisPlace,代码行数:12,代码来源:thisplace.py

示例6: four_words

# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import encode [as 别名]
def four_words(self, lat_long):
        """Convert coordinate to a combination of four words

        The coordinate is defined by latitude and longitude
        in degrees.
        """
        lat, lon = lat_long
        gh = geohash.encode(lat, lon, 9)
        words = "-".join(self.four_wordlist[p] for p in self.to_quads(self.pad(gh)))
        return words 
开发者ID:Placeware,项目名称:ThisPlace,代码行数:12,代码来源:thisplace.py

示例7: six_words

# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import encode [as 别名]
def six_words(self, lat_long):
        """Convert coordinate to a combination of six words

        The coordinate is defined by latitude and longitude
        in degrees.

        With six words the word list contains only words
        which are short, easy to pronounce and easy distinguish.
        """
        lat, lon = lat_long
        gh = geohash.encode(lat, lon, 9)
        words = "-".join(self.six_wordlist[p] for p in self.to_bytes(self.pad(gh)))
        return words 
开发者ID:Placeware,项目名称:ThisPlace,代码行数:15,代码来源:thisplace.py

示例8: test_encode

# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import encode [as 别名]
def test_encode(self):
    for expect, test in self.test_geohashes:
      value = geohash.encode(test)
      self.assertAlmostEqual(value[0], expect[0])
      self.assertAlmostEqual(value[1], expect[1]) 
开发者ID:transitland,项目名称:mapzen-geohash,代码行数:7,代码来源:test_geohash.py

示例9: test_roundtrip

# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import encode [as 别名]
def test_roundtrip(self):
    for test, expect in self.test_geohashes:
      encoded = geohash.decode(test)
      decoded = geohash.encode(encoded)
      assert test == decoded 
开发者ID:transitland,项目名称:mapzen-geohash,代码行数:7,代码来源:test_geohash.py

示例10: get_point_hash

# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import encode [as 别名]
def get_point_hash(self, point):
        """
        return geohash for given point with self.precision
        :param point: GeoPoint instance
        :return: string
        """
        return geohash.encode(point.latitude, point.longitude, self.precision) 
开发者ID:gusdan,项目名称:geoindex,代码行数:9,代码来源:geo_grid_index.py

示例11: index_geohash

# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import encode [as 别名]
def index_geohash(pipe, key, lat, lon):
    lat = float(lat)
    lon = float(lon)
    geoh = geohash.encode(lat, lon, config.GEOHASH_PRECISION)
    geok = keys.geohash_key(geoh)
    pipe.sadd(geok, key) 
开发者ID:addok,项目名称:addok,代码行数:8,代码来源:index.py

示例12: deindex_geohash

# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import encode [as 别名]
def deindex_geohash(key, lat, lon):
    lat = float(lat)
    lon = float(lon)
    geoh = geohash.encode(lat, lon, config.GEOHASH_PRECISION)
    geok = keys.geohash_key(geoh)
    DB.srem(geok, key) 
开发者ID:addok,项目名称:addok,代码行数:8,代码来源:index.py

示例13: geohash_key

# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import encode [as 别名]
def geohash_key(self):
        if self.lat and self.lon and self._geohash_key is None:
            geoh = geohash.encode(self.lat, self.lon, config.GEOHASH_PRECISION)
            self._geohash_key = compute_geohash_key(geoh)
            if self._geohash_key:
                self.debug('Computed geohash key %s', self._geohash_key)
            else:
                self.debug('Empty geohash key, deleting %s', self._geohash_key)
        return self._geohash_key 
开发者ID:addok,项目名称:addok,代码行数:11,代码来源:core.py

示例14: doc_by_id

# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import encode [as 别名]
def doc_by_id(_id):
    return get_document(keys.document_key(_id).encode()) 
开发者ID:addok,项目名称:addok,代码行数:4,代码来源:shell.py

示例15: geohash

# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import encode [as 别名]
def geohash(cls, lat, lon, geohash_precision=DEFAULT_GEOHASH_PRECISION):
        return geohash.encode(lat, lon)[:geohash_precision] 
开发者ID:openvenues,项目名称:lieu,代码行数:4,代码来源:geo_word_index.py


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