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 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; }
public virtual void ExpandToInclude(BoundingBox other) { if (other.m_minLon < m_minLon) { m_minLon = other.m_minLon; } if (other.m_maxLon > m_maxLon) { m_maxLon = other.m_maxLon; } if (other.m_minLat < m_minLat) { m_minLat = other.m_minLat; } if (other.m_maxLat > m_maxLat) { m_maxLat = other.m_maxLat; } }
public BoundingBox(BoundingBox that) : this(that.m_minLat, that.m_maxLat, that.m_minLon, that.m_maxLon) { }
public virtual bool Intersects(BoundingBox other) { return !(other.m_minLon > m_maxLon || other.m_maxLon < m_minLon || other.m_minLat > m_maxLat || other.m_maxLat < m_minLat); }