コード例 #1
0
ファイル: geo.go プロジェクト: cinnabardk/exp
// https://github.com/yinqiwen/ardb/blob/master/doc/spatial-index.md
// http://gis.stackexchange.com/questions/18330/would-it-be-possible-to-use-geohash-for-proximity-searches
func (_ Test) GeoHashInt() {
	lat := 56.162939
	long := 10.203921
	hash := geoInt.EncodeInt(lat, long, 52) //  0.5971 meters
	hash = geoInt.EncodeInt(lat, long, 18)  // 78 km
	e.InfoLog.Println(hash)

	neighbours := geoInt.EncodeNeighborsInt(hash, 18)
	neighbours = append(neighbours, hash)
	sortUint64.Asc(neighbours)
	e.InfoLog.Println(neighbours)
}
コード例 #2
0
ファイル: georedis.go プロジェクト: winiceo/georedis
// AddCoordinates adds coordinates to the set
func AddCoordinates(client *redis.Client, bucketName string, bitDepth uint8, coordinates ...GeoKey) (int64, error) {
	encodedCoordinates := make([]redis.Z, len(coordinates))

	for key, value := range coordinates {
		encodedCoordinate := geohash.EncodeInt(
			value.Lat,
			value.Lon,
			bitDepth,
		)
		encodedCoordinates[key] = redis.Z{
			Score:  float64(encodedCoordinate),
			Member: value.Label,
		}
	}

	return client.ZAdd(bucketName, encodedCoordinates...).Result()
}
コード例 #3
0
ファイル: georedis.go プロジェクト: winiceo/georedis
func getQueryRangesFromBitDepth(lat, lon float64, radiusBitDepth, bitDepth uint8) ([]geoRange, error) {
	bitDiff := bitDepth - radiusBitDepth
	if bitDiff < 0 {
		return []geoRange{}, fmt.Errorf("bitDepth must be high enough to calculate range within radius")
	}

	hash := geohash.EncodeInt(lat, lon, radiusBitDepth)
	neighbors := geohash.EncodeNeighborsInt(hash, radiusBitDepth)

	neighbors = append(neighbors, hash)
	sort.Sort(uint64Slice(neighbors))

	if radiusBitDepth <= 4 {
		neighbors = uniqueInSlice(neighbors)
	}

	ranges := []geoRange{}

	for i := 0; i < len(neighbors); i++ {
		lowerRange := float64(neighbors[i])
		upperRange := lowerRange + 1

		for len(neighbors) > i+1 && float64(neighbors[i+1]) == upperRange {
			neighbors = neighbors[1:]
			upperRange = float64(neighbors[i] + 1)
		}

		ranges = append(ranges, geoRange{Lower: lowerRange, Upper: upperRange})
	}

	for key := range ranges {
		ranges[key].Lower = leftShift(ranges[key].Lower, bitDiff)
		ranges[key].Upper = leftShift(ranges[key].Upper, bitDiff)
	}

	return ranges, nil
}