Ejemplo n.º 1
0
def neighbors(hashcode, depth=1):
    if _geohash and len(hashcode) < 25:
        return _geohash.neighbors(hashcode)

    (lat, lon, lat_length, lon_length) = _decode_c2i(hashcode)
    ret = []
    tlat = lat
    for tlon in (lon - 1, lon + 1):
        code = _encode_i2c(tlat, tlon, lat_length, lon_length)
        if code:
            ret.append(code)

    tlat = lat + 1
    if not tlat >> lat_length:
        for tlon in (lon - 1, lon, lon + 1):
            ret.append(_encode_i2c(tlat, tlon, lat_length, lon_length))

    tlat = lat - 1
    if tlat >= 0:
        for tlon in (lon - 1, lon, lon + 1):
            ret.append(_encode_i2c(tlat, tlon, lat_length, lon_length))

#########再往外扩一层##########
    if depth > 1:
        tlat = lat
        for tlon in (lon - 2, lon + 2):
            code = _encode_i2c(tlat, tlon, lat_length, lon_length)
            if code:
                ret.append(code)

        tlat = lat + 1
        if not tlat >> lat_length:
            for tlon in (lon - 2, lon + 2):
                ret.append(_encode_i2c(tlat, tlon, lat_length, lon_length))

        tlat = lat - 1
        if tlat >= 0:
            for tlon in (lon - 2, lon + 2):
                ret.append(_encode_i2c(tlat, tlon, lat_length, lon_length))

        tlat = lat + 2
        if not tlat >> lat_length:
            for tlon in (lon - 2, lon - 1, lon, lon + 1, lon + 2):
                ret.append(_encode_i2c(tlat, tlon, lat_length, lon_length))

        tlat = lat - 2
        if tlat >= 0:
            for tlon in (lon - 2, lon - 1, lon, lon + 1, lon + 2):
                ret.append(_encode_i2c(tlat, tlon, lat_length, lon_length))

    return ret
Ejemplo n.º 2
0
def neighbors(hashcode):
	if _geohash and len(hashcode)<25:
		return _geohash.neighbors(hashcode)
	(lat,lon,lat_length,lon_length) = _decode_c2i(hashcode)
	ret = []
	tlat = lat
	for tlon in (lon-1, lon+1):
		ret.append(_encode_i2c(tlat,tlon,lat_length,lon_length))
	
	tlat = lat+1
	if not tlat >> lat_length:
		for tlon in (lon-1, lon, lon+1):
			ret.append(_encode_i2c(tlat,tlon,lat_length,lon_length))
	
	tlat = lat-1
	if tlat >= 0:
		for tlon in (lon-1, lon, lon+1):
			ret.append(_encode_i2c(tlat,tlon,lat_length,lon_length))
	
	return ret
Ejemplo n.º 3
0
def neighbors(hashcode):
	if _geohash and len(hashcode)<25:
		return _geohash.neighbors(hashcode)
	(lat,lon,lat_length,lon_length) = _decode_c2i(hashcode)
	ret = {}
	tlat = lat
	for tlon, dir in ( ( lon-1, 'west' ), ( lon+1, 'east' ) ):
		ret.update( { dir: _encode_i2c( tlat, tlon, lat_length, lon_length ) } )
	
	tlat = lat+1
	if not tlat >> lat_length:
		for tlon, dir in ( ( lon-1, 'northwest' ), ( lon, 'north' ), ( lon+1, 'northeast' ) ):
			ret.update( { dir: _encode_i2c( tlat, tlon, lat_length, lon_length ) } )
	
	tlat = lat-1
	if tlat >= 0:
		for tlon, dir in ( ( lon-1, 'southwest' ), ( lon, 'south' ), ( lon+1, 'southeast' ) ):
			ret.update( { dir: _encode_i2c( tlat, tlon, lat_length, lon_length ) } )
	
	return ret
Ejemplo n.º 4
0
def neighbors(hashcode):
    if _geohash and len(hashcode) < 25:
        return _geohash.neighbors(hashcode)
    (lat, lon, lat_length, lon_length) = _decode_c2i(hashcode)
    ret = []
    tlat = lat
    for tlon in (lon - 1, lon + 1):
        ret.append(_encode_i2c(tlat, tlon, lat_length, lon_length))

    tlat = lat + 1
    if not tlat >> lat_length:
        for tlon in (lon - 1, lon, lon + 1):
            ret.append(_encode_i2c(tlat, tlon, lat_length, lon_length))

    tlat = lat - 1
    if tlat >= 0:
        for tlon in (lon - 1, lon, lon + 1):
            ret.append(_encode_i2c(tlat, tlon, lat_length, lon_length))

    return ret
Ejemplo n.º 5
0
        input_name = row['geohash'][:5]

        if (index % 1000 == 0):
            print(str(index) + '/' + str(length))

        # In the same community as the last record
        if last_row == input_name:
            last_row = input_name
            all_quantile_50.append(quantile_50_cache)
            continue
        else:
            last_row = input_name

            input_hash = row['geohash']
            input_hash_neighbors = [
                each[:6] for each in _geohash.neighbors(input_hash)
            ]
            input_city = row['city']
            input_div = row['div']

            price = []

            filtered_data = filter(data, input_hash)

            for filtered_index, filtered_row in filtered_data.iterrows():
                ref_hash = filtered_row['geohash']
                if (in_range(input_hash, input_hash_neighbors, ref_hash)):

                    record_price = filtered_row['unitPrice']
                    record_date = filtered_row['transDate']