示例#1
0
def encode(lat, lon, precision=12):
    if _geohash and precision <= 64:
        ints = _geohash.encode_int(lat, lon)
        ret = ""
        for intu in ints:
            for i in range(int(_geohash.intunit / 2)):
                if len(ret) > precision:
                    break
                ret += "0213"[(intu >> (_geohash.intunit - 2 - i * 2)) & 0x03]

        return ret[:precision]

    b = 1 << precision
    return _encode_i2c(int(b * (lat + 90.0) / 180.0), int(b * (lon + 180.0) / 360.0), precision)
示例#2
0
def encode(lat, lon, precision=12):
    if _geohash and precision <= 64:
        ints = _geohash.encode_int(lat, lon)
        ret = ""
        for intu in ints:
            for i in range(int(_geohash.intunit / 2)):
                if len(ret) > precision:
                    break
                ret += "0213"[(intu >> (_geohash.intunit - 2 - i * 2)) & 0x03]

        return ret[:precision]

    b = 1 << precision
    return _encode_i2c(int(b * (lat + 90.0) / 180.0),
                       int(b * (lon + 180.0) / 360.0), precision)
示例#3
0
def encode_uint64(latitude, longitude):
	if latitude >= 90.0 or latitude < -90.0:
		raise ValueError("Latitude must be in the range of (-90.0, 90.0)")
	while longitude < -180.0:
		longitude += 360.0
	while longitude >= 180.0:
		longitude -= 360.0
	
	if _geohash:
		ui128 = _geohash.encode_int(latitude,longitude)
		if _geohash.intunit == 64:
			return ui128[0]
		elif _geohash.intunit == 32:
			return (ui128[0]<<32) + ui128[1]
		elif _geohash.intunit == 16:
			return (ui128[0]<<48) + (ui128[1]<<32) + (ui128[2]<<16) + ui128[3]
	
	lat = int(((latitude + 90.0)/180.0)*(1<<32))
	lon = int(((longitude+180.0)/360.0)*(1<<32))
	return _uint64_interleave(lat, lon)
示例#4
0
文件: geohash.py 项目: lixinsu/test
def encode_uint64(latitude, longitude):
    if latitude >= 90.0 or latitude < -90.0:
        raise ValueError("Latitude must be in the range of (-90.0, 90.0)")
    while longitude < -180.0:
        longitude += 360.0
    while longitude >= 180.0:
        longitude -= 360.0

    if _geohash:
        ui128 = _geohash.encode_int(latitude, longitude)
        if _geohash.intunit == 64:
            return ui128[0]
        elif _geohash.intunit == 32:
            return (ui128[0] << 32) + ui128[1]
        elif _geohash.intunit == 16:
            return (ui128[0] << 48) + (ui128[1] << 32) + (ui128[2] << 16) + ui128[3]

    lat = int(((latitude + 90.0) / 180.0) * (1 << 32))
    lon = int(((longitude + 180.0) / 360.0) * (1 << 32))
    return _uint64_interleave(lat, lon)