Exemple #1
0
        public override Point fromWgs(WgsPoint point)
        {
            double lat = point.getLatitude() * Math.PI / 180.0;
            double lon = point.getLongitude() * Math.PI / 180.0;
            double n   = Math.Pow(wgsMajorAxis, 2) /
                         Math.Sqrt(
                Math.Pow(wgsMajorAxis, 2) * Math.Pow(Math.Cos(lat), 2) +
                (Math.Pow(wgsMinorAxis, 2) * Math.Pow(Math.Sin(lat), 2)));
            double z;

            if (point.getAltitude() == null)
            {
                z = 0;
            }
            else
            {
                z = (double)point.getAltitude();
            }
            double x = (n + z) * Math.Cos(lat) * Math.Cos(lon);
            double y = (n + z) * Math.Cos(lat) * Math.Sin(lon);

            z = ((Math.Pow((wgsMinorAxis / wgsMajorAxis), 2)) * n + z)
                * Math.Sin(point.getLatitude() * Math.PI / 180.0);

            double x_, y_, z_;

            x_ = -dX + (1 + (-1) * e) * (x - rZ * y + rY * z);
            y_ = -dY + (1 + (-1) * e) * (rZ * x + y - rX * z);
            z_ = -dZ + (1 + (-1) * e) * (-rY * x + rX * y + z);

            double p     = Math.Sqrt(Math.Pow(x_, 2) + Math.Pow(y_, 2));
            double theta = Math.Atan((z_ * hayMajorAxis)
                                     / (p * hayMinorAxis));
            double pow_eccentricity = (Math.Pow(hayMajorAxis, 2)
                                       - Math.Pow(hayMinorAxis, 2))
                                      / Math.Pow(hayMajorAxis, 2);
            double pow_second_eccentricity = (Math.Pow(hayMajorAxis, 2)
                                              - Math.Pow(hayMinorAxis, 2))
                                             / Math.Pow(hayMinorAxis, 2);
            double latf = Math.Atan((z_ + pow_second_eccentricity
                                     * hayMinorAxis * Math.Pow(Math.Sin(theta), 3))
                                    / (p - pow_eccentricity * hayMajorAxis
                                       * Math.Pow(Math.Cos(theta), 3)));
            double lonf = Math.Atan(y_ / x_);
            double nf   = Math.Pow(hayMajorAxis, 2) /
                          Math.Sqrt(
                Math.Pow(hayMajorAxis, 2) * Math.Pow(Math.Cos(latf), 2) +
                Math.Pow(hayMinorAxis, 2) * Math.Pow(Math.Sin(latf), 2));
            double hf = (p / Math.Cos(latf)) - nf;

            latf = latf * 180 / Math.PI;
            lonf = lonf * 180 / Math.PI;
            HayPoint _point = new HayPoint(latf, lonf, hf);

            return(_point);
        }
Exemple #2
0
        //---------------------------------------------------------------------
        /// <summary>
        /// Returns a
        /// </summary>
        /// <param name="bottomLeft">
        /// </param>
        /// <param name="topRight">
        /// </param>
        /// <param name="precision">
        /// </param>
        /// <returns></returns>
        //---------------------------------------------------------------------
        public Dem getSelection(Point bottomLeft, Point topRight,
                                Dem.Precision precision)
        {
            if (bottomLeft.getLatitude() > topRight.getLatitude())
            {
                if (bottomLeft.getLongitude() > topRight.getLongitude())
                {
                    Point aux = bottomLeft;
                    bottomLeft = topRight;
                    topRight   = aux;
                }
                else
                {
                    WgsPoint aux  = bottomLeft.toWgs();
                    WgsPoint aux2 = topRight.toWgs();
                    bottomLeft = new WgsPoint(aux2.getLatitude(),
                                              aux.getLongitude(), aux.getAltitude());
                    topRight = new WgsPoint(aux.getLatitude(),
                                            aux2.getLongitude(), aux2.getAltitude());
                }
            }
            else
            {
                if (bottomLeft.getLongitude() > topRight.getLongitude())
                {
                    WgsPoint aux  = bottomLeft.toWgs();
                    WgsPoint aux2 = topRight.toWgs();
                    bottomLeft = new WgsPoint(aux.getLatitude(),
                                              aux2.getLongitude(), aux.getAltitude());
                    topRight = new WgsPoint(aux2.getLatitude(),
                                            aux.getLongitude(), aux2.getAltitude());
                }
            }
            Dem dem = this.addDem(bottomLeft, topRight, precision);

            return(dem.getSelection(bottomLeft, topRight));
        }
Exemple #3
0
        public override Point fromWgs(WgsPoint point)
        {
            double lat = point.getLatitude() * Math.PI / 180.0;
            double lon = point.getLongitude() * Math.PI / 180.0;
            double n = Math.Pow(wgsMajorAxis, 2) /
            Math.Sqrt(
                Math.Pow(wgsMajorAxis, 2) * Math.Pow(Math.Cos(lat), 2) +
                (Math.Pow(wgsMinorAxis, 2) * Math.Pow(Math.Sin(lat), 2)));
            double z;
            if (point.getAltitude() == null)
                z = 0;
            else
                z = (double)point.getAltitude();
            double x = (n + z) * Math.Cos(lat) * Math.Cos(lon);
            double y = (n + z) * Math.Cos(lat) * Math.Sin(lon);
            z = ((Math.Pow((wgsMinorAxis / wgsMajorAxis), 2)) * n + z)
                * Math.Sin(point.getLatitude()*Math.PI/180.0);

            double x_, y_, z_;

            x_ = -dX + (1 + (-1) * e) * (x - rZ * y + rY * z);
            y_ = -dY + (1 + (-1) * e) * (rZ * x + y - rX * z);
            z_ = -dZ + (1 + (-1) * e) * (-rY * x + rX * y + z);

            double p = Math.Sqrt(Math.Pow(x_, 2) + Math.Pow(y_, 2));
            double theta = Math.Atan((z_ * hayMajorAxis)
                / (p * hayMinorAxis));
            double pow_eccentricity = (Math.Pow(hayMajorAxis, 2)
                - Math.Pow(hayMinorAxis, 2))
                / Math.Pow(hayMajorAxis, 2);
            double pow_second_eccentricity = (Math.Pow(hayMajorAxis, 2)
                - Math.Pow(hayMinorAxis, 2))
                / Math.Pow(hayMinorAxis, 2);
            double latf = Math.Atan((z_ + pow_second_eccentricity
                * hayMinorAxis * Math.Pow(Math.Sin(theta), 3))
                / (p - pow_eccentricity * hayMajorAxis
                * Math.Pow(Math.Cos(theta), 3)));
            double lonf = Math.Atan(y_ / x_);
            double nf = Math.Pow(hayMajorAxis, 2) /
                Math.Sqrt(
                    Math.Pow(hayMajorAxis, 2) * Math.Pow(Math.Cos(latf), 2) +
                    Math.Pow(hayMinorAxis, 2) * Math.Pow(Math.Sin(latf), 2));
            double hf = (p / Math.Cos(latf)) - nf;
            latf = latf * 180 / Math.PI;
            lonf = lonf * 180 / Math.PI;
            HayPoint _point = new HayPoint(latf, lonf, hf);
            return _point;
        }
        //---------------------------------------------------------------------
        /// <summary>
        /// Builds the specified file path.
        /// </summary>
        /// <param name="p">The included waypoint.</param>
        /// <param name="demType">The DEM type</param>
        /// <returns>The file path(s)</returns>
        //---------------------------------------------------------------------
        private static string buildPath(Point p, DemType demType)
        {
            string   path     = string.Empty;
            HayPoint hayPoint = new HayPoint(p.toWgs());
            WgsPoint wgsPoint = p.toWgs();

            if (demType == DemType.Icc)
            {
                if (couldBeICCInfo(p))
                {
                    if (hayPoint.getUtmX() <
                        (Icc.MAXHAYUTMX + Icc.MINHAYUTMX) / 2)
                    {
                        path = Icc.PATHWEST;
                    }
                    else
                    {
                        path = Icc.PATHEAST;
                    }
                }
                else
                {
                    path = string.Empty;
                }
            }
            else if (demType == DemType.Srtm3)
            {
                int lon = Convert.ToInt32(Math.Floor(wgsPoint.getLongitude()));
                int lat = Convert.ToInt32(Math.Floor(wgsPoint.getLatitude()));
                if (lat < 0)
                {
                    path += "S";
                }
                else
                {
                    path += "N";
                }
                if (Math.Abs(lat) < 10)
                {
                    path += "0" + Math.Abs(lat);
                }
                else
                {
                    path += Math.Abs(lat);
                }
                if (lon < 0)
                {
                    path += "W";
                }
                else
                {
                    path += "E";
                }
                if (Math.Abs(lon) < 10)
                {
                    path += "00" + Math.Abs(lon);
                }
                else if (Math.Abs(lon) < 100)
                {
                    path += "0" + Math.Abs(lon);
                }
                else
                {
                    path += Math.Abs(lon);
                }
                path += ".hgt";
            }
            else if (demType == DemType.Srtm30)
            {
                int lon = Convert.ToInt32(Math.Floor(wgsPoint.getLongitude()));
                int lat = Convert.ToInt32(Math.Floor(wgsPoint.getLatitude()));
                if (lat > -60)
                {
                    if (lon < -140)
                    {
                        path += "w180";
                    }
                    else if (lon < -100)
                    {
                        path += "w140";
                    }
                    else if (lon < -60)
                    {
                        path += "w100";
                    }
                    else if (lon < -20)
                    {
                        path += "w060";
                    }
                    else if (lon < 20)
                    {
                        path += "w020";
                    }
                    else if (lon < 60)
                    {
                        path += "e020";
                    }
                    else if (lon < 100)
                    {
                        path += "e060";
                    }
                    else if (lon < 140)
                    {
                        path += "e100";
                    }
                    else
                    {
                        path += "e140";
                    }
                }
                else
                {
                    if (lon < -120)
                    {
                        path += "w180";
                    }
                    else if (lon < -60)
                    {
                        path += "w120";
                    }
                    else if (lon < 0)
                    {
                        path += "w060";
                    }
                    else if (lon < 60)
                    {
                        path += "e000";
                    }
                    else if (lon < 120)
                    {
                        path += "e060";
                    }
                    else
                    {
                        path += "e120";
                    }
                }
                if (lat < -60)
                {
                    path += "s60";
                }
                else if (lat < -10)
                {
                    path += "s10";
                }
                else if (lat < 40)
                {
                    path += "n40";
                }
                else
                {
                    path += "n90";
                }

                path += ".dem";
            }
            return(path);
        }