Пример #1
0
        /// <summary>
        /// Projects the given coordinates onto the xy-coordinate system.
        /// </summary>
        /// <param name="coordinate">The geographical coordinates to be projected.</param>
        /// <returns>The given coordinates projected onto the xy-coordinate system.</returns>
        public Point Project(GeoCoordinate coordinate)
        {
            const double RadianConversionFactor = Math.PI / 180;

            double lat = Math.Max(Math.Min(MaxLatitude, coordinate.Latitude), -MaxLatitude);
            double sin = Math.Sin(lat * RadianConversionFactor);
            double x = R * coordinate.Longitude * RadianConversionFactor;
            double y = R * Math.Log((1 + sin) / (1 - sin)) / 2;

            return new Point(x, y);
        }
Пример #2
0
        /// <summary>
        /// Calculates distance between this and another <see cref="GeoCoordinate"/> value.
        /// </summary>
        /// <param name="other">Other <see cref="GeoCoordinate"/>.</param>
        /// <returns>Distance between two <see cref="GeoCoordinate"/> values.</returns>
        public double Distance(GeoCoordinate other)
        {
            const double RadianConversionFactor = Math.PI / 180.0D;

            double r = 6378137;
            double lambda1 = Longitude * RadianConversionFactor;
            double lambda2 = other.Longitude * RadianConversionFactor;
            double phi1 = Latitude * RadianConversionFactor;
            double phi2 = other.Latitude * RadianConversionFactor;
            double dPhi = phi2 - phi1;
            double dLambda = lambda2 - lambda1;

            double a = Math.Sin(dPhi / 2) * Math.Sin(dPhi / 2) +
                    Math.Cos(phi1) * Math.Cos(phi2) *
                    Math.Sin(dLambda / 2) * Math.Sin(dLambda / 2);

            double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));

            return r * c;
        }
Пример #3
0
 /// <summary>
 /// Translates the given geographical coordinate
 /// to a cartesian point at the given zoom level.
 /// </summary>
 /// <param name="coordinate">The coordinate to be translated.</param>
 /// <param name="zoom">The zoom level.</param>
 /// <returns>The cartesian point corresponding to the given coordinate.</returns>
 public virtual Point Translate(GeoCoordinate coordinate, double zoom)
 {
     Point projectedPoint = Projection.Project(coordinate);
     double scale = Scale(zoom);
     return Transformation.Transform(projectedPoint, scale);
 }
Пример #4
0
 /// <summary>
 /// Returns the distance between two geographical coordinates.
 /// </summary>
 /// <param name="coordinate1">The first geographical coordinate.</param>
 /// <param name="coordinate2">The second geographical coordinate.</param>
 /// <returns>The distance between two geographical coordinates.</returns>
 public abstract double Distance(GeoCoordinate coordinate1, GeoCoordinate coordinate2);