Esempio n. 1
0
        public static double Distance(
            Coords loc1,
            Coords loc2,
            UnitSystem unitSystem           = UnitSystem.SI,
            DistanceFormula distanceFormula =
            DistanceFormula.SphericalEarthProjection)
        {
            switch (distanceFormula)
            {
            case DistanceFormula.Haversine:
                return(DistanceHaversine(loc1, loc2, unitSystem));

            case DistanceFormula.SphericalEarthProjection:
                return(DistanceSEP(loc1, loc2, unitSystem));

            case DistanceFormula.SphericalLawOfCosines:
                return(DistanceSLC(loc1, loc2, unitSystem));

            default:
                return(DistanceSEP(loc1, loc2, unitSystem));
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Returns the distance between the latitude and longitude coordinates that are specified by this GeoCoordinate and
        ///     another specified GeoCoordinate using the defined formula
        /// </summary>
        /// <returns>
        ///     The distance between the two coordinates, in meters.
        /// </returns>
        /// <param name="other">The GeoCoordinate for the location to calculate the distance to.</param>
        /// <param name="Formula">The formula to use to calculate distance</param>
        public double GetDistanceTo(GeoCoordinate other, DistanceFormula distanceFormula)
        {
            if (double.IsNaN(Latitude) || double.IsNaN(Longitude) || double.IsNaN(other.Latitude) ||
                double.IsNaN(other.Longitude))
            {
                throw new ArgumentException("Argument latitude or longitude is not a number");
            }

            switch (distanceFormula)
            {
            case DistanceFormula.Haversine:
                return(GetDistanceHaversine(other));

            case DistanceFormula.SphericalLawOfCosinus:
                return(GetDistanceSphericalLawOfCosines(other));

            case DistanceFormula.Vicenty:
                return(GetDistanceVicenty(other));

            default:
                throw new NotImplementedException();
            }
        }
Esempio n. 3
0
        public IOrderedEnumerable <NodeDistance <KDTreeNode <Face> > > GetNeighbors(double[] query, DistanceFormula distanceFormula)
        {
            /* https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.DistanceMetric.html */

            sw.Restart();
            switch (distanceFormula)
            {
            case DistanceFormula.Manhattan:
                Tree.Distance = new Accord.Math.Distances.Manhattan();
                break;

            case DistanceFormula.Euclidean:
                Tree.Distance = new Accord.Math.Distances.Euclidean();
                break;

            case DistanceFormula.Chebyshev:
                Tree.Distance = new Accord.Math.Distances.Chebyshev();
                break;
            }
            var neighbours = Tree.Nearest(query, neighbors: _neighbors);

            sw.Stop();
            WriteLineColored($"\nThe first {_neighbors} neighbours for {Tree.Count} nodes [{sw.ElapsedMilliseconds} ms]:", ConsoleColor.Cyan);

            return(neighbours.OrderBy(n => n.Distance));
        }