Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
 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);
 }
Esempio n. 4
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;
 }
Esempio n. 5
0
 public WGS84Point(WGS84Point other) : this(other.m_latitude, other.m_longitude)
 {
 }
Esempio n. 6
0
 public static GeoHash withBitPrecision(WGS84Point point, int numberOfBits)
 {
     return(WithBitPrecision(point.Latitude, point.Longitude, numberOfBits));
 }
Esempio n. 7
0
 public bool EnclosesCircleAroundPoint(WGS84Point point, double radius)
 {
     return(false);
 }
Esempio n. 8
0
 /// <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));
 }
Esempio n. 9
0
 public WGS84Point(WGS84Point other) : this(other.m_latitude, other.m_longitude)
 {
 }
Esempio n. 10
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;
    }
Esempio n. 11
0
 /// <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)
 {
 }
Esempio n. 12
0
 public virtual bool Contains(WGS84Point point)
 {
   return (point.Latitude >= m_minLat) && (point.Longitude >= m_minLon) && (point.Latitude <= m_maxLat) && (point.Longitude <= m_maxLon);
 }
Esempio n. 13
0
 /// <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)
 {
 }
Esempio n. 14
0
 public virtual bool Contains(WGS84Point point)
 {
     return((point.Latitude >= m_minLat) && (point.Longitude >= m_minLon) && (point.Latitude <= m_maxLat) && (point.Longitude <= m_maxLon));
 }