コード例 #1
0
        public GeoHashQuery JoinWith(GeoHashQuery other)
        {
            if (other.IsPrefix(this))
            {
                return(new GeoHashQuery(_startValue, other._endValue));
            }

            if (IsPrefix(other))
            {
                return(new GeoHashQuery(other._startValue, _endValue));
            }

            if (IsSuperQuery(other))
            {
                return(other);
            }

            if (other.IsSuperQuery(this))
            {
                return(this);
            }

            throw new ArgumentException("Can't join these 2 queries: " + this + ", " + other);
        }
コード例 #2
0
        public static HashSet <GeoHashQuery> QueriesAtLocation(GeoPoint location, double radius)
        {
            var queryBits        = Math.Max(1, Utils.BitsForBoundingBox(location, radius));
            var geoHashPrecision = (int)Math.Ceiling((float)queryBits / Base32Utils.BitsPerBase32Char);

            var latitude            = location.Latitude;
            var longitude           = location.Longitude;
            var latitudeDegrees     = radius / Constants.MetersPerDegreeLatitude;
            var latitudeNorth       = Math.Min(90, latitude + latitudeDegrees);
            var latitudeSouth       = Math.Max(-90, latitude - latitudeDegrees);
            var longitudeDeltaNorth = GeoUtils.DistanceToLongitudeDegrees(radius, latitudeNorth);
            var longitudeDeltaSouth = GeoUtils.DistanceToLongitudeDegrees(radius, latitudeSouth);
            var longitudeDelta      = Math.Max(longitudeDeltaNorth, longitudeDeltaSouth);

            var queries = new HashSet <GeoHashQuery>();

            var geoHash  = new GeoHash(latitude, longitude, geoHashPrecision);
            var geoHashW = new GeoHash(latitude, GeoUtils.WrapLongitude(longitude - longitudeDelta), geoHashPrecision);
            var geoHashE = new GeoHash(latitude, GeoUtils.WrapLongitude(longitude + longitudeDelta), geoHashPrecision);

            var geoHashN  = new GeoHash(latitudeNorth, longitude, geoHashPrecision);
            var geoHashNw = new GeoHash(latitudeNorth, GeoUtils.WrapLongitude(longitude - longitudeDelta), geoHashPrecision);
            var geoHashNE = new GeoHash(latitudeNorth, GeoUtils.WrapLongitude(longitude + longitudeDelta), geoHashPrecision);

            var geoHashS  = new GeoHash(latitudeSouth, longitude, geoHashPrecision);
            var geoHashSW = new GeoHash(latitudeSouth, GeoUtils.WrapLongitude(longitude - longitudeDelta), geoHashPrecision);
            var geoHashSE = new GeoHash(latitudeSouth, GeoUtils.WrapLongitude(longitude + longitudeDelta), geoHashPrecision);

            queries.Add(QueryForGeoHash(geoHash, queryBits));
            queries.Add(QueryForGeoHash(geoHashE, queryBits));
            queries.Add(QueryForGeoHash(geoHashW, queryBits));
            queries.Add(QueryForGeoHash(geoHashN, queryBits));
            queries.Add(QueryForGeoHash(geoHashNE, queryBits));
            queries.Add(QueryForGeoHash(geoHashNw, queryBits));
            queries.Add(QueryForGeoHash(geoHashS, queryBits));
            queries.Add(QueryForGeoHash(geoHashSE, queryBits));
            queries.Add(QueryForGeoHash(geoHashSW, queryBits));

            // Join queries
            bool didJoin;

            do
            {
                GeoHashQuery query1 = null;
                GeoHashQuery query2 = null;
                foreach (var query in queries)
                {
                    foreach (var other in queries.Where(other => query != other && query.CanJoinWith(other)))
                    {
                        query1 = query;
                        query2 = other;
                        break;
                    }
                }
                if (query1 != null && query2 != null)
                {
                    queries.Remove(query1);
                    queries.Remove(query2);
                    queries.Add(query1.JoinWith(query2));
                    didJoin = true;
                }
                else
                {
                    didJoin = false;
                }
            } while (didJoin);

            return(queries);
        }
コード例 #3
0
 protected bool Equals(GeoHashQuery other)
 {
     return(_startValue == other._startValue && _endValue == other._endValue);
 }
コード例 #4
0
 public bool CanJoinWith(GeoHashQuery other)
 {
     return(IsPrefix(other) || other.IsPrefix(this) || IsSuperQuery(other) || other.IsSuperQuery(this));
 }
コード例 #5
0
        private bool IsSuperQuery(GeoHashQuery other)
        {
            var startCompare = Compare(other._startValue, this._startValue, StringComparison.Ordinal);

            return(startCompare <= 0 && Compare(other._endValue, this._endValue, StringComparison.Ordinal) >= 0);
        }
コード例 #6
0
 private bool IsPrefix(GeoHashQuery other)
 {
     return(Compare(other._endValue, this._startValue, StringComparison.Ordinal) >= 0 &&
            Compare(other._startValue, this._startValue, StringComparison.Ordinal) < 0 &&
            Compare(other._endValue, this._endValue, StringComparison.Ordinal) < 0);
 }