本文整理汇总了Python中geohash.decode方法的典型用法代码示例。如果您正苦于以下问题:Python geohash.decode方法的具体用法?Python geohash.decode怎么用?Python geohash.decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geohash
的用法示例。
在下文中一共展示了geohash.decode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: decode
# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import decode [as 别名]
def decode(self, words):
"""Decode `words` to latitude and longitude"""
words = words.split("-")
if len(words) == 3:
i = self.rugbits_to_int([self.three_wordlist.index(w) for w in words])
elif len(words) == 4:
i = self.quads_to_int([self.four_wordlist.index(w) for w in words])
i = self.unpad(i)
elif len(words) == 6:
i = self.bytes_to_int([self.six_wordlist.index(w) for w in words])
i = self.unpad(i)
else:
raise RuntimeError("Do not know how to decode a set of %i words."%(len(words)))
geo_hash = self.int_to_geo(i)
return geohash.decode(geo_hash)
示例2: geohash_decode
# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import decode [as 别名]
def geohash_decode(
df: DataFrame, geohash: str, longitude: str, latitude: str
) -> DataFrame:
"""
Decode a geohash column into longitude and latitude
:param df: DataFrame containing geohash data
:param geohash: Name of source column containing geohash location.
:param longitude: Name of new column to be created containing longitude.
:param latitude: Name of new column to be created containing latitude.
:return: DataFrame with decoded longitudes and latitudes
"""
try:
lonlat_df = DataFrame()
lonlat_df["latitude"], lonlat_df["longitude"] = zip(
*df[geohash].apply(geohash_lib.decode)
)
return _append_columns(
df, lonlat_df, {"latitude": latitude, "longitude": longitude}
)
except ValueError:
raise QueryObjectValidationError(_("Invalid geohash string"))
示例3: search
# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import decode [as 别名]
def search(ghash):
latitude, longitude = geohash.decode(ghash)
return _search(latitude, longitude)
示例4: test_decode
# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import decode [as 别名]
def test_decode(self):
for test, expect in self.test_geohashes:
value = geohash.decode(test)
self.assertAlmostEqual(value[0], expect[0])
self.assertAlmostEqual(value[1], expect[1])
示例5: test_roundtrip
# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import decode [as 别名]
def test_roundtrip(self):
for test, expect in self.test_geohashes:
encoded = geohash.decode(test)
decoded = geohash.encode(encoded)
assert test == decoded
示例6: reverse_geohash_decode
# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import decode [as 别名]
def reverse_geohash_decode(geohash_code: str) -> Tuple[str, str]:
lat, lng = geohash.decode(geohash_code)
return (lng, lat)
示例7: reverse_geohash_decode
# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import decode [as 别名]
def reverse_geohash_decode(geohash_code):
lat, lng = geohash.decode(geohash_code)
return (lng, lat)
示例8: from_python
# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import decode [as 别名]
def from_python(self, value, validate=False):
try:
return base64.b64encode(value).decode()
except (ValueError, TypeError):
if validate:
raise ValidationError(
'Cannot decode value from base64: {!r}'.format(value)
)
else:
raise
示例9: to_python
# 需要导入模块: import geohash [as 别名]
# 或者: from geohash import decode [as 别名]
def to_python(self, value):
if value is None:
return None
if isinstance(value, (list, tuple)):
value = list(reversed(value))
if isinstance(value, string_types):
if self.LAT_LON_SEPARATOR in value:
value = list(value.split(self.LAT_LON_SEPARATOR))
elif GEOHASH_IMPORTED:
value = list(geohash.decode(value))
elif isinstance(value, dict):
value = [value.get('lat'), value.get('lon')]
return {'lat': float(value[0]), 'lon': float(value[1])}