Ejemplo n.º 1
0
 void GeohashGetCoordRange(ref GeoHashRange longRange, ref GeoHashRange latRange)
 {
     /* These are constraints from EPSG:900913 / EPSG:3785 / OSGEO:41001 */
     /* We can't geocode at the north/south pole. */
     longRange.Max = GeoLongMax;
     longRange.Min = GeoLongMin;
     latRange.Max  = GeoLatMax;
     latRange.Min  = GeoLatMin;
 }
Ejemplo n.º 2
0
        int GeohashEncode(GeoHashRange longRange, GeoHashRange latRange, double longitude, double latitude,
                          ushort step, ref GeoHashBits hash)
        {
            /* Check basic arguments sanity. */
            if (step > 32 || step == 0 ||
                Rangepiszero(latRange) || Rangepiszero(longRange))
            {
                return(0);
            }

            /* Return an error when trying to index outside the supported
             * constraints. */
            if (longitude > GeoLongMax)
            {
                return(0);
            }
            if (longitude < GeoLongMin)
            {
                return(0);
            }
            if (latitude > GeoLatMax)
            {
                return(0);
            }
            if (latitude < GeoLatMin)
            {
                return(0);
            }

            hash.Bits = 0;
            hash.Step = step;

            if (latitude < latRange.Min || latitude > latRange.Max ||
                longitude < longRange.Min || longitude > longRange.Max)
            {
                return(0);
            }

            double latOffset =
                (latitude - latRange.Min) / (latRange.Max - latRange.Min);
            double longOffset =
                (longitude - longRange.Min) / (longRange.Max - longRange.Min);

            /* convert to fixed point based on the step size */
            latOffset  *= (1UL << step);
            longOffset *= (1UL << step);
            hash.Bits   = Interleave64((uint)latOffset, (uint)longOffset);
            return(1);
        }
Ejemplo n.º 3
0
 private bool Rangeiszero(GeoHashRange r)
 {
     return(r.Max == 0.0 && r.Min == 0.0);
 }
Ejemplo n.º 4
0
 private bool Rangepiszero(GeoHashRange r)
 {
     return(Rangeiszero(r));
 }
Ejemplo n.º 5
0
 int GeohashDecodeType(GeoHashBits hash, GeoHashArea area)
 {
     GeoHashRange[] r = new GeoHashRange[2];
     GeohashGetCoordRange(ref r[0], ref r[1]);
     return(GeohashDecode(r[0], r[1], hash, area));
 }
Ejemplo n.º 6
0
 int GeohashEncodeType(double longitude, double latitude, ushort step, ref GeoHashBits hash)
 {
     GeoHashRange[] r = new GeoHashRange[2];
     GeohashGetCoordRange(ref r[0], ref r[1]);
     return(GeohashEncode(r[0], r[1], longitude, latitude, step, ref hash));
 }