Exemple #1
0
// 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)
}
Exemple #2
0
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
}