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; }
//--------------------------------------------------------------------- /// <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; }
//--------------------------------------------------------------------- /// <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); }
/// <summary> /// Geoid Conversion from WGS84 origin geoid to current waypoint geoid. /// </summary> /// <param name="p">The object waypoint.</param> /// <returns>Converted waypoint.</returns> public abstract Point fromWgs(WgsPoint p);
//--------------------------------------------------------------------- /// <summary> /// Alternative Constructor. /// </summary> /// <param name="rows"> /// Number of rows of the altitude matrix. /// </param> /// <param name="cols"> /// Number of columns of the altitude matrix. /// </param> /// <param name="bottomLeft"> /// Waypoint that represents the bottom left corner position of /// altitude matrix. /// </param> /// <param name="altitude"> /// The altitude matrix. /// </param> /// <param name="noData"> /// The value that represent whether there is no altitude data in a /// specified cell. /// </param> //--------------------------------------------------------------------- public Srtm30(int rows, int cols, WgsPoint bottomLeft, double[,] altitude) : base(rows, cols, bottomLeft, altitude, NODATA, CELLSIZE, METCELLSIZE, Precision.low) { }
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> /// Geoid Conversion from Waypoint origin geoid to WGS84 geoid. /// </summary> /// <returns>WgsPoint converted waypoint</returns> public override WgsPoint toWgs() { double lat = this.latitude * Math.PI / 180.0; double lon = this.longitude * Math.PI / 180.0; double n = Math.Pow(hayMajorAxis, 2) / Math.Sqrt( Math.Pow(hayMajorAxis, 2) * Math.Pow(Math.Cos(lat), 2) + (Math.Pow(hayMinorAxis, 2) * Math.Pow(Math.Sin(lat), 2))); double z; if (this.altitude == null) z = 0; else z = (double)this.altitude; double x = (n + z) * Math.Cos(lat) * Math.Cos(lon); double y = (n + z) * Math.Cos(lat) * Math.Sin(lon); z = ((Math.Pow((hayMinorAxis / hayMajorAxis), 2)) * n + z) * Math.Sin(lat); double x_, y_, z_; x_ = dX + (1 + e) * (x + rZ * y - rY * z); y_ = dY + (1 + e) * (-rZ * x + y + rX * z); z_ = dZ + (1 + e) * (rY * x - rX * y + z); double p = Math.Sqrt(Math.Pow(x_, 2) + Math.Pow(y_, 2)); double theta = Math.Atan((z_ * wgsMajorAxis) / (p * wgsMinorAxis)); double pow_eccentricity = (Math.Pow(wgsMajorAxis, 2) - Math.Pow(wgsMinorAxis, 2)) / Math.Pow(wgsMajorAxis, 2); double pow_second_eccentricity = (Math.Pow(wgsMajorAxis, 2) - Math.Pow(wgsMinorAxis, 2)) / Math.Pow(wgsMinorAxis, 2); double latf = Math.Atan((z_ + pow_second_eccentricity * wgsMinorAxis * Math.Pow(Math.Sin(theta), 3)) / (p - pow_eccentricity * wgsMajorAxis * Math.Pow(Math.Cos(theta), 3))); double lonf = Math.Atan(y_ / x_); double nf = Math.Pow(wgsMajorAxis, 2) / Math.Sqrt( Math.Pow(wgsMajorAxis, 2) * Math.Pow(Math.Cos(latf), 2) + Math.Pow(wgsMinorAxis, 2) * Math.Pow(Math.Sin(latf), 2)); double hf = (p / Math.Cos(latf)) - nf; latf = latf * 180 / Math.PI; lonf = lonf * 180 / Math.PI; WgsPoint point = new WgsPoint(latf, lonf, hf); return point; }
/// <summary> /// Do nothing. /// </summary> /// <returns>The same waypoint.</returns> public override Point fromWgs(WgsPoint p) { return p; }
//--------------------------------------------------------------------- /// <summary> /// Alternative Constructor. /// </summary> /// <param name="bottomLeft"> /// Waypoint that represents the bottom left corner position of /// altitude matrix. /// </param> /// <param name="altitude"> /// The altitude matrix. /// </param> //--------------------------------------------------------------------- public Srtm3(WgsPoint bottomLeft, double[,] altitude) : base(1201, 1201, bottomLeft, altitude, NODATA, CELLSIZE, METCELLSIZE, Precision.medium) { }