Esempio n. 1
0
        //---------------------------------------------------------------------
        /// <summary>
        /// Returns an altitude submatrix delimited by the specified waypoints.
        /// </summary>
        /// <param name="bottomLeft">Bottom left corner waypoint.</param>
        /// <param name="topRight">Top right corner waypoint.</param>
        /// <returns>The altiude submatrix.</returns>
        //---------------------------------------------------------------------
        public override Dem getSelection(Point bottomLeft,
                                         Point topRight)
        {
            bottomLeft = new HayPoint(bottomLeft.toWgs());
            topRight   = new HayPoint(topRight.toWgs());
            Index indBottomLeft =
                new Index(pointToIndex(bottomLeft).getRow() + 2,
                          pointToIndex(bottomLeft).getCol() - 2);
            Index indTopRight =
                new Index(pointToIndex(topRight).getRow() - 2,
                          pointToIndex(topRight).getCol() + 2);

            int selectRows =
                (int)(indBottomLeft.getRow() - indTopRight.getRow() + 1);
            int selectCols =
                (int)(indTopRight.getCol() - indBottomLeft.getCol() + 1);

            double[,] selection = new double[selectRows, selectCols];
            for (int i = indTopRight.getRow();
                 i < (indTopRight.getRow() + selectRows);
                 i++)
            {
                for (int j = indBottomLeft.getCol();
                     j < (indBottomLeft.getCol() + selectCols);
                     j++)
                {
                    selection[i - indTopRight.getRow(), j - indBottomLeft.getCol()]
                        = this.altitude[i - 1, j];
                }
            }
            return(new Icc(selectRows, selectCols, bottomLeft, selection));
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public HayPoint(WgsPoint p)
            : base()
        {
            HayPoint hayPoint = new HayPoint();

            hayPoint       = (HayPoint)hayPoint.fromWgs(p);
            this.latitude  = hayPoint.latitude;
            this.longitude = hayPoint.longitude;
            this.altitude  = hayPoint.altitude;
            this.timeZone  = hayPoint.timeZone;
            this.utmX      = hayPoint.utmX;
            this.utmY      = hayPoint.utmY;
        }
Esempio n. 4
0
        //---------------------------------------------------------------------
        /// <summary>
        /// Checks whether Icc data is avaliable.
        /// </summary>
        /// <param name="p">
        /// The included point.
        /// </param>
        /// <returns>
        /// TRUE if there is avaliable data.
        /// Otherwise, FALSE.
        /// </returns>
        //---------------------------------------------------------------------
        private static bool couldBeICCInfo(Point p)
        {
            //TODO:: Hemisphere issues?
            HayPoint hayPoint = new HayPoint(p.toWgs());
            double   utmX     = hayPoint.getUtmX();
            double   utmY     = hayPoint.getUtmY();

            if (utmX > Icc.MINHAYUTMX && utmX < Icc.MAXHAYUTMX && utmY > Icc.MINHAYUTMY && utmY < Icc.MAXHAYUTMY)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 5
0
        //---------------------------------------------------------------------
        /// <summary>
        /// Returns the terrain altitude from a specified waypoint.
        /// </summary>
        /// <param name="p">
        /// The waypoint you want to know the terrain altitude.
        /// </param>
        /// <returns>
        /// The terrain altitude.
        /// </returns>
        //---------------------------------------------------------------------
        public override double getAltitudeFromCoords(Point p)
        {
            if (getRefSystem() == Point.refSystem.HAYFORD)
            {
                p = new HayPoint(p.toWgs());
            }
            else if (getRefSystem() == Point.refSystem.WGS84)
            {
                p = p.toWgs();
            }

            int indY = (int)
                       ((p.getUtmY() - this.bottomLeft.getUtmY()) / this.cellSize);

            indY = this.rows - indY;
            int indX = (int)
                       ((p.getUtmX() - this.bottomLeft.getUtmX()) / this.cellSize);

            return(this.altitude[indY, indX]);
        }
Esempio n. 6
0
        //---------------------------------------------------------------------
        /// <summary>
        /// Returns the terrain altitude from a specified waypoint.
        /// </summary>
        /// <param name="p">
        /// The waypoint you want to know the terrain altitude.
        /// </param>
        /// <returns>
        /// The terrain altitude
        /// </returns>
        //---------------------------------------------------------------------
        public override double getAltitudeFromCoords(Point p)
        {
            if (p is HayPoint)
            {
                HayPoint hay = (HayPoint)p;
                p = hay.toWgs();
            }
            int indY = (int)((p.getLatitude() - this.bottomLeft.getLatitude()) / this.cellSize);

            indY = this.rows - indY;
            int indX = (int)((p.getLongitude() - this.bottomLeft.getLongitude()) / this.cellSize);

            if (indX >= this.cols || indY >= this.rows)
            {
                return(double.MaxValue);
            }
            else
            {
                return(this.altitude[indY, indX]);
            }
        }
Esempio n. 7
0
        //---------------------------------------------------------------------
        /// <summary>
        /// STATIC: Creates the DEM that complies with the input parametres.
        /// </summary>
        /// <param name="bottomLeft">
        /// A <see cref="Point"/> representing the bottom left corner 
        /// coordinates
        /// </param>
        /// <param name="topRight">
        /// A <see cref="Point"/> representing the top right corner coordinates
        /// </param>
        /// <param name="demList">
        /// A List of <see cref="Dem"/>.
        /// </param>
        /// <param name="precision">
        /// A <see cref="Dem.Precision"/>.
        /// </param>
        /// <returns>
        /// The created <see cref="Dem"/>.
        /// </returns>
        //---------------------------------------------------------------------
        public static Dem createDem(Point bottomLeft, 
            Point topRight,List<Dem> demList, Dem.Precision precision)
        {
            Dem dem = null;
            DemType demType = selectDemGenerator(precision);
            if (demType == DemType.Icc)
            {
                if (!couldBeICCInfo(bottomLeft) || !couldBeICCInfo(topRight))
                {
                    return null;
                }
                else
                {
                    bottomLeft = new HayPoint(bottomLeft.toWgs());
                    topRight = new HayPoint(topRight.toWgs());
                    string path1 = buildPath(bottomLeft, demType);
                    string path2 = buildPath(topRight, demType);
                    if (path1 != path2)
                    {
                        Icc icc1 = new Icc(path1);
                        Icc icc2 = new Icc(path2);
                        dem = Dem.concatenate(icc1, icc2);

                    }
                    else
                    {
                        dem = new Icc(path1);
                    }
                    return dem;
                }
            }
            else if (demType == DemType.Srtm3)
            {
                List<Dem> aux = new List<Dem>();
                bottomLeft = bottomLeft.toWgs();
                topRight = topRight.toWgs();
                int latBL = 
                    Convert.ToInt32(Math.Floor(bottomLeft.getLatitude()));
                int lonBL = 
                    Convert.ToInt32(Math.Floor(bottomLeft.getLongitude()));
                int latTR = 
                    Convert.ToInt32(Math.Floor(topRight.getLatitude()));
                int lonTR = 
                    Convert.ToInt32(Math.Floor(topRight.getLongitude()));
                List<string> paths = new List<string>();
                for (int i = latBL; i <= latTR; i++)
                {
                    for (int j = lonBL; j <= lonTR; j++)
                    {
                        Point p = new WgsPoint(i, j, null);
                        paths.Add(buildPath(p, demType));
                    }
                }
                bool ok = false;
                foreach (string path in paths)
                {
                    foreach (Dem d in demList)
                    {
                        if (d.getPath() == path)
                        {
                            ok = true;
                            aux.Add(d);
                        }
                    }
                    if (!ok && existsPath(demType, path, demList))
                    {
                        aux.Add(new Srtm3(path));
                    }
                    ok = false;
                }
                dem = aux[0];
                List<Dem> aux2 = new List<Dem>();
                int count = 0;
                for (int i = latBL; i <= (latTR); i++)
                {
                    for (double j = lonBL; j <= (lonTR - 1); j++)
                    {
                        count++;
                        dem = Dem.concatenate(dem, aux[count]);
                    }
                    aux2.Add(dem);
                    count++;
                    if (count < aux.Count)
                        dem = aux[count];
                }
                dem = aux2[0];
                for (int i = 1; i < aux2.Count; i++)
                    dem = Dem.concatenate(dem, aux2[i]);
            }
            else if (demType == DemType.Srtm30)
            {
                List<Dem> aux = new List<Dem>();
                bottomLeft = bottomLeft.toWgs();
                topRight = topRight.toWgs();
                int latBL = 
                    Convert.ToInt32(Math.Floor(bottomLeft.getLatitude()));
                int lonBL = 
                    Convert.ToInt32(Math.Floor(bottomLeft.getLongitude()));
                int latTR =
                    Convert.ToInt32(Math.Floor(topRight.getLatitude()));
                int lonTR = 
                    Convert.ToInt32(Math.Floor(topRight.getLongitude()));
                List<string> paths = new List<string>();
                for (double i = latBL; i <= latTR; i = i + 60)
                {
                    for (double j = lonBL; j <= lonTR; j = j + 40)
                    {
                        Point p = new WgsPoint(i, j, null);
                        paths.Add(buildPath(p, demType));
                    }
                }
                bool ok = false;
                foreach (string path in paths)
                {
                    foreach (Dem d in demList)
                    {
                        if (d.getPath() == path)
                        {
                            ok = true;
                            aux.Add(d);
                        }
                    }
                  
                    if (!ok && existsPath(demType, path, demList))
                    {
                        aux.Add(
                            new Srtm30(
                                path, string.Format(
                                    path.Split('.')[0] + ".HDR")));
                    }
                    ok = false;
                }
                dem = aux[0];
                List<Dem> aux2 = new List<Dem>();
                int count = 0;
                bool isFirst = true;
                for (double i = latBL; isFirst || i <= latTR; i = i + 60)
                {
                    for (double j = lonBL; j <= (lonTR - 40); j = j + 40)
                    {
                        count++;
                        dem = Dem.concatenate(dem, aux[count]);
                    }
                    aux2.Add(dem);
                    count++;
                    if(count < aux.Count)
                        dem = aux[count];
                    isFirst = false;
                }
                dem = aux2[0];
                for (int i = 1; i < aux2.Count; i++)
                    dem = Dem.concatenate(dem, aux2[i]);
            }
            return dem;
        }
Esempio n. 8
0
 //---------------------------------------------------------------------
 /// <summary>
 /// Checks whether Icc data is avaliable.
 /// </summary>
 /// <param name="p">
 /// The included point.
 /// </param>
 /// <returns>
 /// TRUE if there is avaliable data. 
 /// Otherwise, FALSE.
 /// </returns>
 //---------------------------------------------------------------------
 private static bool couldBeICCInfo(Point p)
 {
     //TODO:: Hemisphere issues?
     HayPoint hayPoint = new HayPoint(p.toWgs());
     double utmX = hayPoint.getUtmX();
     double utmY = hayPoint.getUtmY();
     if (utmX > Icc.MINHAYUTMX && utmX < Icc.MAXHAYUTMX && utmY > Icc.MINHAYUTMY && utmY < Icc.MAXHAYUTMY)
         return true;
     else
         return false;
 }
Esempio n. 9
0
        //---------------------------------------------------------------------
        /// <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;
        }
Esempio n. 10
0
        //---------------------------------------------------------------------
        /// <summary>
        /// Returns the terrain altitude from a specified waypoint.
        /// </summary>
        /// <param name="p">
        /// The waypoint you want to know the terrain altitude.
        /// </param>
        /// <returns>
        /// The terrain altitude.
        /// </returns>
        //---------------------------------------------------------------------
        public override double getAltitudeFromCoords(Point p)
        {
            if (getRefSystem() == Point.refSystem.HAYFORD)
                p = new HayPoint(p.toWgs());
            else if (getRefSystem() == Point.refSystem.WGS84)
                p = p.toWgs();

            int indY = (int)
                ((p.getUtmY() - this.bottomLeft.getUtmY()) / this.cellSize);
            indY = this.rows - indY;
            int indX = (int)
                ((p.getUtmX() - this.bottomLeft.getUtmX()) / this.cellSize);
            return this.altitude[indY, indX];
        }
Esempio n. 11
0
 public HayPoint(WgsPoint p)
     : base()
 {
     HayPoint hayPoint = new HayPoint();
     hayPoint = (HayPoint)hayPoint.fromWgs(p);
     this.latitude = hayPoint.latitude;
     this.longitude = hayPoint.longitude;
     this.altitude = hayPoint.altitude;
     this.timeZone = hayPoint.timeZone;
     this.utmX = hayPoint.utmX;
     this.utmY = hayPoint.utmY;
 }
Esempio n. 12
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;
        }
Esempio n. 13
0
        //---------------------------------------------------------------------
        /// <summary>
        /// Returns an altitude submatrix delimited by the specified waypoints.
        /// </summary>
        /// <param name="bottomLeft">Bottom left corner waypoint.</param>
        /// <param name="topRight">Top right corner waypoint.</param>
        /// <returns>The altiude submatrix.</returns>
        //---------------------------------------------------------------------
        public override Dem getSelection(Point bottomLeft, 
            Point topRight)
        {
            bottomLeft = new HayPoint(bottomLeft.toWgs());
            topRight = new HayPoint(topRight.toWgs());
            Index indBottomLeft = 
                new Index(pointToIndex(bottomLeft).getRow() + 2, 
                                pointToIndex(bottomLeft).getCol() - 2);
            Index indTopRight = 
                new Index(pointToIndex(topRight).getRow() - 2, 
                                pointToIndex(topRight).getCol() + 2);

            int selectRows = 
                (int)(indBottomLeft.getRow() - indTopRight.getRow() + 1);
            int selectCols = 
                (int)(indTopRight.getCol() - indBottomLeft.getCol() + 1);
            double[,] selection = new double[selectRows, selectCols];
            for (int i = indTopRight.getRow();
                i < (indTopRight.getRow() + selectRows);
                i++)
            {
                for (int j = indBottomLeft.getCol();
                    j < (indBottomLeft.getCol() + selectCols);
                    j++)
                {
                    selection[i - indTopRight.getRow(), j - indBottomLeft.getCol()] 
                        =  this.altitude[i - 1, j];
                }
            }
            return new Icc(selectRows, selectCols, bottomLeft, selection);
        }
Esempio n. 14
0
        //---------------------------------------------------------------------
        /// <summary>
        /// STATIC: Creates the DEM that complies with the input parametres.
        /// </summary>
        /// <param name="bottomLeft">
        /// A <see cref="Point"/> representing the bottom left corner
        /// coordinates
        /// </param>
        /// <param name="topRight">
        /// A <see cref="Point"/> representing the top right corner coordinates
        /// </param>
        /// <param name="demList">
        /// A List of <see cref="Dem"/>.
        /// </param>
        /// <param name="precision">
        /// A <see cref="Dem.Precision"/>.
        /// </param>
        /// <returns>
        /// The created <see cref="Dem"/>.
        /// </returns>
        //---------------------------------------------------------------------
        public static Dem createDem(Point bottomLeft,
                                    Point topRight, List <Dem> demList, Dem.Precision precision)
        {
            Dem     dem     = null;
            DemType demType = selectDemGenerator(precision);

            if (demType == DemType.Icc)
            {
                if (!couldBeICCInfo(bottomLeft) || !couldBeICCInfo(topRight))
                {
                    return(null);
                }
                else
                {
                    bottomLeft = new HayPoint(bottomLeft.toWgs());
                    topRight   = new HayPoint(topRight.toWgs());
                    string path1 = buildPath(bottomLeft, demType);
                    string path2 = buildPath(topRight, demType);
                    if (path1 != path2)
                    {
                        Icc icc1 = new Icc(path1);
                        Icc icc2 = new Icc(path2);
                        dem = Dem.concatenate(icc1, icc2);
                    }
                    else
                    {
                        dem = new Icc(path1);
                    }
                    return(dem);
                }
            }
            else if (demType == DemType.Srtm3)
            {
                List <Dem> aux = new List <Dem>();
                bottomLeft = bottomLeft.toWgs();
                topRight   = topRight.toWgs();
                int latBL =
                    Convert.ToInt32(Math.Floor(bottomLeft.getLatitude()));
                int lonBL =
                    Convert.ToInt32(Math.Floor(bottomLeft.getLongitude()));
                int latTR =
                    Convert.ToInt32(Math.Floor(topRight.getLatitude()));
                int lonTR =
                    Convert.ToInt32(Math.Floor(topRight.getLongitude()));
                List <string> paths = new List <string>();
                for (int i = latBL; i <= latTR; i++)
                {
                    for (int j = lonBL; j <= lonTR; j++)
                    {
                        Point p = new WgsPoint(i, j, null);
                        paths.Add(buildPath(p, demType));
                    }
                }
                bool ok = false;
                foreach (string path in paths)
                {
                    foreach (Dem d in demList)
                    {
                        if (d.getPath() == path)
                        {
                            ok = true;
                            aux.Add(d);
                        }
                    }
                    if (!ok && existsPath(demType, path, demList))
                    {
                        aux.Add(new Srtm3(path));
                    }
                    ok = false;
                }
                dem = aux[0];
                List <Dem> aux2  = new List <Dem>();
                int        count = 0;
                for (int i = latBL; i <= (latTR); i++)
                {
                    for (double j = lonBL; j <= (lonTR - 1); j++)
                    {
                        count++;
                        dem = Dem.concatenate(dem, aux[count]);
                    }
                    aux2.Add(dem);
                    count++;
                    if (count < aux.Count)
                    {
                        dem = aux[count];
                    }
                }
                dem = aux2[0];
                for (int i = 1; i < aux2.Count; i++)
                {
                    dem = Dem.concatenate(dem, aux2[i]);
                }
            }
            else if (demType == DemType.Srtm30)
            {
                List <Dem> aux = new List <Dem>();
                bottomLeft = bottomLeft.toWgs();
                topRight   = topRight.toWgs();
                int latBL =
                    Convert.ToInt32(Math.Floor(bottomLeft.getLatitude()));
                int lonBL =
                    Convert.ToInt32(Math.Floor(bottomLeft.getLongitude()));
                int latTR =
                    Convert.ToInt32(Math.Floor(topRight.getLatitude()));
                int lonTR =
                    Convert.ToInt32(Math.Floor(topRight.getLongitude()));
                List <string> paths = new List <string>();
                for (double i = latBL; i <= latTR; i = i + 60)
                {
                    for (double j = lonBL; j <= lonTR; j = j + 40)
                    {
                        Point p = new WgsPoint(i, j, null);
                        paths.Add(buildPath(p, demType));
                    }
                }
                bool ok = false;
                foreach (string path in paths)
                {
                    foreach (Dem d in demList)
                    {
                        if (d.getPath() == path)
                        {
                            ok = true;
                            aux.Add(d);
                        }
                    }

                    if (!ok && existsPath(demType, path, demList))
                    {
                        aux.Add(
                            new Srtm30(
                                path, string.Format(
                                    path.Split('.')[0] + ".HDR")));
                    }
                    ok = false;
                }
                dem = aux[0];
                List <Dem> aux2    = new List <Dem>();
                int        count   = 0;
                bool       isFirst = true;
                for (double i = latBL; isFirst || i <= latTR; i = i + 60)
                {
                    for (double j = lonBL; j <= (lonTR - 40); j = j + 40)
                    {
                        count++;
                        dem = Dem.concatenate(dem, aux[count]);
                    }
                    aux2.Add(dem);
                    count++;
                    if (count < aux.Count)
                    {
                        dem = aux[count];
                    }
                    isFirst = false;
                }
                dem = aux2[0];
                for (int i = 1; i < aux2.Count; i++)
                {
                    dem = Dem.concatenate(dem, aux2[i]);
                }
            }
            return(dem);
        }
Esempio n. 15
0
        //---------------------------------------------------------------------
        /// <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);
        }