예제 #1
0
 /// <summary>
 /// create a <seealso cref="GeoHashCircleQuery"/> with the given center point and a
 /// radius in meters.
 /// </summary>
 public GeoHashCircleQuery(WGS84Point center, double radius)
 {
   m_radius = radius;
   m_center = center;
   WGS84Point northEast = VincentyGeodesy.MoveInDirection(VincentyGeodesy.MoveInDirection(center, 0, radius), 90, radius);
   WGS84Point southWest = VincentyGeodesy.MoveInDirection(VincentyGeodesy.MoveInDirection(center, 180, radius), 270, radius);
   BoundingBox bbox = new BoundingBox(northEast, southWest);
   m_query = new GeoHashBoundingBoxQuery(bbox);
 }
예제 #2
0
        /// <summary>
        /// create a <seealso cref="GeoHashCircleQuery"/> with the given center point and a
        /// radius in meters.
        /// </summary>
        public GeoHashCircleQuery(WGS84Point center, double radius)
        {
            m_radius = radius;
            m_center = center;
            WGS84Point  northEast = VincentyGeodesy.MoveInDirection(VincentyGeodesy.MoveInDirection(center, 0, radius), 90, radius);
            WGS84Point  southWest = VincentyGeodesy.MoveInDirection(VincentyGeodesy.MoveInDirection(center, 180, radius), 270, radius);
            BoundingBox bbox      = new BoundingBox(northEast, southWest);

            m_query = new GeoHashBoundingBoxQuery(bbox);
        }
예제 #3
0
 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;
 }
예제 #4
0
    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;
    }