private GeoHash(double latitude, double longitude, int desiredPrecision) { m_point = new WGS84Point(latitude, longitude); desiredPrecision = Math.Min(desiredPrecision, MAX_BIT_PRECISION); bool isEvenBit = true; double[] latitudeRange = new double[] { -90, 90 }; double[] longitudeRange = new double[] { -180, 180 }; while (m_significantBits < desiredPrecision) { if (isEvenBit) { DivideRangeEncode(longitude, longitudeRange); } else { DivideRangeEncode(latitude, latitudeRange); } isEvenBit = !isEvenBit; } SetBoundingBox(this, latitudeRange, longitudeRange); m_bits <<= (MAX_BIT_PRECISION - desiredPrecision); }
/// <inheritdoc /> public override bool Equals(object obj) { if (obj is WGS84Point) { WGS84Point other = (WGS84Point)obj; return(m_latitude == other.m_latitude && m_longitude == other.m_longitude); } return(false); }
/// <summary> /// /// </summary> /// <param name="other"></param> public WGS84Point(WGS84Point other) : this(other.m_latitude, other.m_longitude) { }
/// <summary> /// create a new <seealso cref="GeoHash"/> with the given number of bits accuracy. This /// at the same time defines this hash's bounding box. /// </summary> /// <param name="point">Location to create <seealso cref="GeoHash"/> for</param> /// <param name="numberOfBits">How may bits precision to use (64 is recommended)</param> /// <returns></returns> public static GeoHash withBitPrecision(WGS84Point point, int numberOfBits) { return(WithBitPrecision(point.Latitude, point.Longitude, numberOfBits)); }
/// <summary> /// ? /// </summary> /// <param name="point">?</param> /// <param name="radius">?</param> /// <returns>?</returns> public bool EnclosesCircleAroundPoint(WGS84Point point, double radius) { return(false); }
/// <summary> /// find out if the given point lies within this hashes bounding box. /// <i>Note: this operation checks the bounding boxes coordinates, i.e. does /// not use the <seealso cref="GeoHash"/>s special abilities.s</i> /// </summary> public bool Contains(WGS84Point point) { return(m_boundingBox.Contains(point)); }
/// <summary> /// create a bounding box defined by two coordinates /// </summary> public BoundingBox(WGS84Point p1, WGS84Point p2) : this(p1.Latitude, p2.Latitude, p1.Longitude, p2.Longitude) { }
/// <summary> /// Is <see cref="WGS84Point"/> within <see cref="BoundingBox"/> /// </summary> /// <param name="point"><see cref="WGS84Point"/> for containment check</param> /// <returns><c>true</c> if contained; otherwise <c>false</c></returns> public virtual bool Contains(WGS84Point point) { return((point.Latitude >= m_minLat) && (point.Longitude >= m_minLon) && (point.Latitude <= m_maxLat) && (point.Longitude <= m_maxLon)); }