本文整理匯總了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)
示例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)
示例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()
示例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"))
示例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
示例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
示例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
示例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])
示例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
示例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)
示例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)
示例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)
示例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
示例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())
示例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]