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); }
public static HashSet<GeoObj> SearchGeoHashIndex(SessionBase session, double lat, double lon, double radius) { HashSet<GeoObj> resultSet = new HashSet<GeoObj>(); WGS84Point center = new WGS84Point(lat, lon); GeoHashCircleQuery query = new GeoHashCircleQuery(center, radius); // radius in meters BoundingBox bbox = query.BoundingBox; var btreeSet = session.AllObjects<BTreeSet<GeoObj>>().FirstOrDefault(); foreach (GeoHash hash in query.SearchHashes) { var itr = btreeSet.Iterator(); itr.GoTo(new GeoObj(hash.LongValue)); var current = itr.Current(); while (current != null) { GeoHash geoHash = GeoHash.FromLongValue(current.GeoHash); if ((geoHash.SignificantBits >= hash.SignificantBits && geoHash.Within(hash)) || (geoHash.SignificantBits < hash.SignificantBits && hash.Within(geoHash))) { if (!(current.Latitude < bbox.MinLat || current.Latitude > bbox.MaxLat || current.Longitude < bbox.MinLon || current.Longitude > bbox.MaxLon)) resultSet.Add(current); current = itr.Next(); } else break; } } return resultSet; }
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); }
public static HashSet<GeoObj> SearchGeoHashIndex(SessionBase session, double minLat, double minLon, double maxLat, double maxLon) { HashSet<GeoObj> resultSet = new HashSet<GeoObj>(); if (minLat > maxLat) { double t = minLat; minLat = maxLat; maxLat = t; } if (minLon > maxLon) { double t = minLon; minLon = maxLon; maxLon = t; } WGS84Point min = new WGS84Point(minLat, minLon); WGS84Point max = new WGS84Point(maxLat, maxLon); BoundingBox bbox = new BoundingBox(min, max); GeoHashBoundingBoxQuery query = new GeoHashBoundingBoxQuery(bbox); var btreeSet = session.AllObjects<BTreeSet<GeoObj>>().FirstOrDefault(); foreach (GeoHash hash in query.SearchHashes) { var itr = btreeSet.Iterator(); itr.GoTo(new GeoObj(hash.LongValue)); var current = itr.Current(); while (current != null) { GeoHash geoHash = GeoHash.FromLongValue(current.GeoHash); if ((geoHash.SignificantBits >= hash.SignificantBits && geoHash.Within(hash)) || (geoHash.SignificantBits < hash.SignificantBits && hash.Within(geoHash))) { if (!(current.Latitude < bbox.MinLat || current.Latitude > bbox.MaxLat || current.Longitude < bbox.MinLon || current.Longitude > bbox.MaxLon)) resultSet.Add(current); current = itr.Next(); } else break; } } return resultSet; }
public WGS84Point(WGS84Point other) : this(other.m_latitude, other.m_longitude) { }
public static GeoHash withBitPrecision(WGS84Point point, int numberOfBits) { return(WithBitPrecision(point.Latitude, point.Longitude, numberOfBits)); }
public bool EnclosesCircleAroundPoint(WGS84Point point, double radius) { return(false); }
/// <summary> /// find out if the given point lies within this hashes bounding box.<br> /// <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)); }
public static HashSet<Person> SearchGeoHashIndex(string bootDirectory, double minLat, double minLon, double maxLat, double maxLon) { HashSet<Person> resultSet = new HashSet<Person>(); if (minLat > maxLat) { double t = minLat; minLat = maxLat; maxLat = t; } if (minLon > maxLon) { double t = minLon; minLon = maxLon; maxLon = t; } WGS84Point min = new WGS84Point(minLat, minLon); WGS84Point max = new WGS84Point(maxLat, maxLon); BoundingBox bbox = new BoundingBox(min, max); GeoHashBoundingBoxQuery query = new GeoHashBoundingBoxQuery(bbox); using (SessionNoServer session = new SessionNoServer(bootDirectory)) { session.BeginRead(); BTreeMap<Int64, VelocityDbList<Person>> btreeMap = session.AllObjects<BTreeMap<Int64, VelocityDbList<Person>>>().FirstOrDefault(); foreach (GeoHash hash in query.SearchHashes) { BTreeMapIterator<Int64, VelocityDbList<Person>> itr = btreeMap.Iterator(); itr.GoTo(hash.LongValue); var current = itr.Current(); while (current.Value != null) { GeoHash geoHash = GeoHash.FromLongValue(current.Key); if (geoHash.Within(hash) || (geoHash.SignificantBits > hash.SignificantBits && hash.Within(geoHash))) { foreach (Person person in current.Value) { resultSet.Add(person); } current = itr.Next(); } else break; } } // actual geohash bounding box may be including some that are not within requested bounding box so remove such items if any HashSet<Person> notWithin = new HashSet<Person>(); foreach (Person person in resultSet) { if (person.Lattitude < min.Latitude || person.Lattitude > max.Latitude || person.Longitude < min.Longitude || person.Lattitude > max.Latitude) notWithin.Add(person); } foreach (Person person in notWithin) resultSet.Remove(person); foreach (Person person in resultSet) { Console.WriteLine(person.ToString() + " Lattitude: " + person.Lattitude + " Longitude: " + person.Longitude); } session.Commit(); } return resultSet; }
/// <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) { }
public virtual bool Contains(WGS84Point point) { return (point.Latitude >= m_minLat) && (point.Longitude >= m_minLon) && (point.Latitude <= m_maxLat) && (point.Longitude <= m_maxLon); }
public virtual bool Contains(WGS84Point point) { return((point.Latitude >= m_minLat) && (point.Longitude >= m_minLon) && (point.Latitude <= m_maxLat) && (point.Longitude <= m_maxLon)); }