private void AddStoreMarkerToCluster(MapCluster cluster, IGeoCoordinate store)
        {
            var storeCoordinate = store.GetCoordinate();

            if (cluster.Center == null)
            {
                cluster.Center = storeCoordinate;
            }
            else
            {
                var l   = cluster.ItemsCount + 1;
                var lat = (cluster.Center.Lat * (l - 1) + storeCoordinate.Lat) / l;
                var lng = (cluster.Center.Lng * (l - 1) + storeCoordinate.Lng) / l;
                cluster.Center = new Coordinate(lat, lng);
            }

            var xScale = ZoomLngScales[ZoomLevel];
            var yScale = ZoomLatScales[ZoomLevel];

            cluster.Tile = new Bounds(new Coordinate(cluster.Center.Lat - yScale / 2, cluster.Center.Lng - xScale / 2),
                                      new Coordinate(cluster.Center.Lat + yScale / 2, cluster.Center.Lng + xScale / 2));


            cluster.ItemsCount++;
            cluster.StoreNumber = cluster.ItemsCount == 1 ? store.Id : cluster.StoreNumber + ";" + store.Id;
        }
Exemplo n.º 2
0
        /*
         * Raytracing on grid:
         * http://playtechs.blogspot.de/2007/03/raytracing-on-grid.html
         */

        public double GetAccumulatedPathRating(IGeoCoordinate start, IGeoCoordinate destination,
                                               double failFastThreshold = double.MaxValue)
        {
            return(GetPathValueViaRaycastInGrid(start.Latitude, start.Longitude, destination.Latitude,
                                                destination.Longitude,
                                                failFastThreshold));
        }
 public static bool ContainsPoint(this IBoundingBox boundingBox, IGeoCoordinate coordinate)
 {
     return
         (coordinate.Latitude.Value <= boundingBox.Northeast().Latitude.Value &&
          coordinate.Longitude.Value <= boundingBox.Northeast().Longitude.Value &&
          coordinate.Latitude.Value >= boundingBox.Southwest().Latitude.Value &&
          coordinate.Longitude.Value >= boundingBox.Southwest().Longitude.Value);
 }
Exemplo n.º 4
0
 internal GeoCircle(double latitude, double longitude, IGeoCoordinate latitudeDMS, IGeoCoordinate longitudeDMS, double radius, double minLatitude, double maxLatitude, double minLongitude, double maxLongitude) : base(latitude, longitude, latitudeDMS, longitudeDMS)
 {
     Radius       = radius;
     MinLatitude  = minLatitude;
     MaxLatitude  = maxLatitude;
     MinLongitude = minLongitude;
     MaxLongitude = maxLongitude;
 }
Exemplo n.º 5
0
        public double GetAccumulatedPathRating(IGeoCoordinate start, double speed, double bearing,
                                               double failFastThreshold = double.MaxValue)
        {
            var destination = CalculateNewCoordinates(start.Latitude, start.Longitude, bearing, speed);

            return(GetPathValueViaRaycastInGrid(start.Latitude, start.Longitude, destination.Latitude,
                                                destination.Longitude,
                                                failFastThreshold));
        }
Exemplo n.º 6
0
        public void SetCellRating(IGeoCoordinate position, double cellRating)
        {
            var cell = GetCellForGps(position.Latitude, position.Longitude);

            if (cell == -1)
            {
                return;
            }
            Grid.AddOrUpdate(cell, cellRating, (k, v) => cellRating);
        }
Exemplo n.º 7
0
        public double GeoCoordinateToDouble(IGeoCoordinate value)
        {
            var angle = value.Degrees + (value.Minutes * 60.0 + value.Seconds) / 3600.0;

            if (value.IsNegative)
            {
                return(-angle);
            }
            return(angle);
        }
Exemplo n.º 8
0
        public void AddCellRating(IGeoCoordinate position, double ratingValue)
        {
            var cell = GetCellForGps(position.Latitude, position.Longitude);

            if (cell == -1)
            {
                return;
            }
            Grid.AddOrUpdate(cell, 0.0, (key, oldValue) => oldValue + ratingValue);
        }
Exemplo n.º 9
0
        public BoundingBox(IGeoCoordinate pointOne, IGeoCoordinate pointTwo)
        {
            if (pointOne.Latitude.Value == pointTwo.Latitude.Value || pointOne.Longitude.Value == pointTwo.Longitude.Value)
            {
                throw new ArgumentException("The latitudes and longitudes onf the two points must be different");
            }

            PointOne = pointOne;
            PointTwo = pointTwo;
        }
        public bool InBounds(Bounds source, IGeoCoordinate bound)
        {
            var coordinate = bound.GetCoordinate();

            if (coordinate != null)
            {
                return(source.Contains(coordinate));
            }
            return(false);
        }
        /// <summary>
        /// Returns the initial bearing to take to go from the first point (origin) to the second point (the destination)
        /// </summary>
        /// <remarks>
        /// Note this is an initial bearing.  The bearing of the course changes throughout the journey because you are traversing
        /// a great circle path over a sphere
        /// </remarks>
        /// <param name="origin">The starting location (origin)</param>
        /// <param name="destination">The ending location (the destination)</param>
        /// <returns>An Angle object with the initial bearing in the units of degrees</returns>
        public static Angle InitialBearing(this IGeoCoordinate origin, IGeoCoordinate destination)
        {
            var longitudeDelta = destination.Longitude.ToUnit(AngleUnit.Radian).Value - origin.Longitude.ToUnit(AngleUnit.Radian).Value;
            var y = Math.Sin(longitudeDelta) * Math.Cos(destination.Latitude.ToUnit(AngleUnit.Radian).Value);
            var x = Math.Cos(origin.Latitude.ToUnit(AngleUnit.Radian).Value) * Math.Sin(destination.Latitude.ToUnit(AngleUnit.Radian).Value) -
                    Math.Sin(origin.Latitude.ToUnit(AngleUnit.Radian).Value) * Math.Cos(destination.Latitude.ToUnit(AngleUnit.Radian).Value) * Math.Cos(longitudeDelta);
            var bearingInRadians = Math.Atan2(y, x);

            var degrees = (Angle.FromRadians(bearingInRadians).ToUnit(AngleUnit.Degree).Value + 360) % 360;

            return(Angle.FromDegrees(degrees));
        }
        /// <summary>
        /// Returns the distance between two locations (points) in the distance units specified
        /// </summary>
        /// <param name="origin">The starting location (origin)</param>
        /// <param name="destination">The ending location (the destination)</param>
        /// <param name="unit">An optional LengthUnit value of the units the length should come back in.  If this parameter is not used then the returned length will be in meters</param>
        /// <returns>A Length object of the distance between the two locations</returns>
        public static Length HaversineDistance(this IGeoCoordinate origin, IGeoCoordinate destination, LengthUnit lengthUnit = LengthUnit.Meter)
        {
            var lat = (destination.Latitude - origin.Latitude).ToUnit(AngleUnit.Radian);
            var lng = (destination.Longitude - origin.Longitude).ToUnit(AngleUnit.Radian);
            var h1  = Math.Sin(lat.Value / 2) * Math.Sin(lat.Value / 2) +
                      Math.Cos(origin.Latitude.ToUnit(AngleUnit.Radian).Value) * Math.Cos(destination.Latitude.ToUnit(AngleUnit.Radian).Value) *
                      Math.Sin(lng.Value / 2) * Math.Sin(lng.Value / 2);
            var h2 = 2 * Math.Asin(Math.Min(1, Math.Sqrt(h1)));

            var distanceInMeters = Length.From(EARTH_RADIUS_METERS * h2, LengthUnit.Meter);

            return(distanceInMeters.ToUnit(lengthUnit));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Compares two geo coordinates for equality.
        /// </summary>
        /// <param name="IGeoCoordinate">Another geo coordinate.</param>
        /// <returns>True if both are equal; False otherwise.</returns>
        public Boolean Equals(IGeoCoordinate IGeoCoordinate)
        {
            if (IGeoCoordinate.Latitude.Value != Latitude.Value)
            {
                return(false);
            }

            if (IGeoCoordinate.Longitude.Value != Longitude.Value)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 14
0
        public IGeoLocation Create(IGeoCoordinate latitudeDMS, IGeoCoordinate longitudeDMS)
        {
            if (latitudeDMS.Type != GeoCoordinateType.Latitude)
            {
                throw new ArgumentException("type error", nameof(latitudeDMS));
            }
            if (longitudeDMS.Type != GeoCoordinateType.Longitude)
            {
                throw new ArgumentException("type error", nameof(longitudeDMS));
            }

            var lat = _coordinateMath.GeoCoordinateToDouble(latitudeDMS);
            var lon = _coordinateMath.GeoCoordinateToDouble(longitudeDMS);

            return(new GeoLocation(lat, lon, latitudeDMS, longitudeDMS));
        }
        private void AddToClosestCluster(ClusteringContext context, IGeoCoordinate store)
        {
            var clusterToAdd = context.Clusters.FirstOrDefault(cluster => InBounds(cluster.Tile, store));

            if (clusterToAdd != null)
            {
                AddStoreMarkerToCluster(clusterToAdd, store);
            }
            else
            {
                clusterToAdd = new MapCluster {
                    SearchIndex = context.Clusters.Count + 1
                };
                AddStoreMarkerToCluster(clusterToAdd, store);
                context.Clusters.Add(clusterToAdd);
            }
        }
Exemplo n.º 16
0
        public void Write(IGeoCoordinate value, TextWriter writer)
        {
            switch (value.Type)
            {
            case GeoCoordinateType.Latitude:     // North - South
                var nsValue = $"{(value.IsNegative ? 'S' : 'N')} {value.Degrees}° {value.Minutes:00}' {_formatter.WriteToString(value.Seconds)}\"";
                writer.Write(nsValue);
                break;

            case GeoCoordinateType.Longitude:     // East - West
                var ewValue = $"{(value.IsNegative ? 'W' : 'E')} {value.Degrees}° {value.Minutes:00}' {_formatter.WriteToString(value.Seconds)}\"";
                writer.Write(ewValue);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 17
0
        public IGeoCoordinate GetMaxValueNeighbourCoordinate(IGeoCoordinate position)
        {
            var cell    = GetCellForGps(position.Latitude, position.Longitude);
            var cells   = GetNeighborCells(cell);
            var maxcell = cells.Aggregate(
                (curMaxCell, nextCell) =>
            {
                double nextCellValue;
                double curMaxValue;
                if (!Grid.TryGetValue(nextCell, out nextCellValue) ||
                    !Grid.TryGetValue(curMaxCell, out curMaxValue))
                {
                    return(curMaxCell);
                }
                return(nextCellValue > curMaxValue ? nextCell : curMaxCell);
            }
                );

            return(GetGpsForCell(maxcell));
        }
Exemplo n.º 18
0
        public double TryTakeFromCell(IGeoCoordinate position, double amount)
        {
            var cell        = GetCellForGps(position.Latitude, position.Longitude);;
            var amountTaken = 0.0;

            if (cell == -1)
            {
                return(amountTaken);
            }
            Grid.AddOrUpdate(cell, 0.0,
                             (key, oldValue) =>
            {
                var nV = oldValue - amount;
                if (nV < 0)
                {
                    amountTaken = amount + nV;
                    return(0);
                }
                amountTaken = amount;
                return(nV);
            });
            return(amountTaken);
        }
Exemplo n.º 19
0
        internal GeoLocation(
            double latitude,
            double longitude,
            IGeoCoordinate latitudeDMS,
            IGeoCoordinate longitudeDMS)
        {
            if (latitude < -90.0 || latitude > 90.0)
            {
                throw new ArgumentOutOfRangeException(nameof(latitude), $"latitude must be between -90 to 90. Value: {latitude}");
            }
            if (longitude < -180.0 || longitude > 180.0)
            {
                throw new ArgumentOutOfRangeException(nameof(longitude), $"longitude must be between -180 and +180 degrees. Value: {longitude}");
            }
            if (latitudeDMS == null)
            {
                throw new ArgumentNullException(nameof(latitudeDMS));
            }
            if (longitudeDMS == null)
            {
                throw new ArgumentException(nameof(longitudeDMS));
            }
            if (latitudeDMS.Type != GeoCoordinateType.Latitude)
            {
                throw new ArgumentException($"{nameof(latitudeDMS)} type must be {nameof(GeoCoordinateType.Latitude)}. Value: {latitudeDMS.Type}");
            }
            if (longitudeDMS.Type != GeoCoordinateType.Longitude)
            {
                throw new ArgumentException($"{nameof(longitudeDMS)} type must be {nameof(GeoCoordinateType.Longitude)}. Value: {longitudeDMS.Type}");
            }

            Latitude     = latitude;
            Longitude    = longitude;
            LatitudeDMS  = latitudeDMS;
            LongitudeDMS = longitudeDMS;
        }
Exemplo n.º 20
0
 public void ReduceCellRating(IGeoCoordinate position, double ratingValue)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 21
0
 public double TryTakeFromCell(IGeoCoordinate position, double amount)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 22
0
 public double GetCellRating(IGeoCoordinate position)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 23
0
 public IGeoCoordinate GetMaxValueNeighbourCoordinate(IGeoCoordinate position)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 24
0
 public double GetAccumulatedPathRating(IGeoCoordinate start, IGeoCoordinate destination,
                                        double failFastThreshold = Double.MaxValue)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 25
0
 public string Encode(IGeoCoordinate point)
 {
     return(Encode(new[] { point }));
 }
Exemplo n.º 26
0
 public static string WriteToString(this IGeoCoordinate coordinate, IGeoCoordinateFormatter?formatter = null)
 {
     formatter = formatter ?? new GeoCoordinateFormatter();
     return(formatter.WriteToString(coordinate));
 }
Exemplo n.º 27
0
        public double GetCellRating(IGeoCoordinate position)
        {
            var cell = GetCellForGps(position.Latitude, position.Longitude);

            return(Grid.GetOrAdd(cell, 0.0));
        }
Exemplo n.º 28
0
 public string Encode(IGeoCoordinate point)
 {
     return(_encoder.Encode(point));
 }
Exemplo n.º 29
0
 public void SetCellRating(IGeoCoordinate position, double cellValue)
 {
     throw new NotImplementedException();
 }