private void button_xyzTogeo_Click(object sender, EventArgs e) { try { string splliter = "\t"; AngleUnit unit = AngleUnit; Geo.Referencing.Ellipsoid ellipsoid = Ellipsoid; List <XYZ> xyzs = new List <XYZ>(); foreach (var item in this.textBox_xyz.Lines) { if (item == "") { continue; } xyzs.Add(XYZ.Parse(item)); } StringBuilder sb = new StringBuilder(); var spliter = IsOutSplitByTab ? "\t" : ", "; foreach (var item in xyzs) { GeoCoord geeCoord = CoordTransformer.XyzToGeoCoord(item, ellipsoid, unit); sb.AppendLine(geeCoord.ToString("0.0000000000", spliter)); } this.textBox_geo.Text = sb.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 由空间直角坐标转换为椭球坐标。默认角度单位为度。 /// </summary> /// <param name="xyz"></param> /// <param name="ellipsoid"></param> /// <param name="angeUnit"></param> /// <returns></returns> public static GeoCoord XyzToGeoCoord(IXYZ xyz, Geo.Referencing.Ellipsoid ellipsoid, AngleUnit angeUnit = AngleUnit.Degree) { double x = xyz.X; double y = xyz.Y; double z = xyz.Z; double a = ellipsoid.SemiMajorAxis; double e = ellipsoid.FirstEccentricity; return(XyzToGeoCoord(x, y, z, a, e, angeUnit)); }
/// <summary> /// 由地心地固空间直角坐标计算大地坐标。 /// </summary> /// <param name="pos">空间直角坐标</param> /// <param name="date">儒略日</param> /// <param name="ellipsoid">参考椭球</param> /// <param name="unit">角度单位</param> /// <returns></returns> public static GeoCoord XyzToGeoCoord(IXYZ pos, Julian date, Geo.Referencing.Ellipsoid ellipsoid = null, AngleUnit unit = AngleUnit.Degree) { if (ellipsoid == null) { ellipsoid = Geo.Referencing.Ellipsoid.WGS84; } double f = ellipsoid.Flattening; double a = ellipsoid.SemiMajorAxis; double TwoPi = 2 * CoordConsts.PI; double x = pos.X; double y = pos.Y; double z = pos.Z; double theta = (GeoMath.AcTan(pos.Y, pos.X) - date.GetGreenwichMeanSiderealTime()) % TwoPi; theta = theta % TwoPi; if (theta < 0.0) { // "wrap" negative modulo theta += TwoPi; } double r = Math.Sqrt(x * x + y * y); double e2 = f * (2.0 - f); double lat = GeoMath.AcTan(z, r); const double DELTA = 1.0e-07; double phi; double c; do { phi = lat; c = 1.0 / Math.Sqrt(1.0 - e2 * GeoMath.Sqr(Sin(phi))); lat = GeoMath.AcTan(pos.Z + a * c * e2 * Sin(phi), r); }while (Math.Abs(lat - phi) > DELTA); double Altitude = (r / Cos(lat)) - a * c; if (unit == AngleUnit.Degree) { lat *= AngularConvert.RadToDegMultiplier; theta *= AngularConvert.RadToDegMultiplier; } double Lat = lat; double Lon = theta; return(new GeoCoord(Lon, Lat, Altitude, unit)); }
/// <summary> /// 大地坐标转为空间直角坐标。 /// </summary> /// <param name="ellipsoidCoord"></param> /// <returns></returns> public static XYZ GeoCoordToXyz(IGeodeticCoord ellipsoidCoord, Geo.Referencing.Ellipsoid el = null) { if (el == null) { el = Geo.Referencing.Ellipsoid.WGS84; } double lon = ellipsoidCoord.Lon; double lat = ellipsoidCoord.Lat; double height = ellipsoidCoord.Height; double a = el.SemiMajorAxis; double e = el.FirstEccentricity; return(GeoCoordToXyz(lon, lat, height, a, e, ellipsoidCoord.Unit)); }
private void button_geoToxyz_Click(object sender, EventArgs e) { try { AngleUnit unit = AngleUnit; Geo.Referencing.Ellipsoid ellipsoid = Ellipsoid; List <GeoCoord> sources = new List <GeoCoord>(); foreach (var item in this.textBox_geo.Lines) { if (item == "") { continue; } string[] strs = item.Split(new char[] { ',', '\t', ' ', ',' }, StringSplitOptions.RemoveEmptyEntries); DMS lon = DMS.Parse(strs[0], unit); DMS lat = DMS.Parse(strs[1], unit); double height = Double.Parse(strs[2]); sources.Add(new GeoCoord(lon.Degrees, lat.Degrees, height, AngleUnit.Degree)); } StringBuilder sb = new StringBuilder(); var spliter = IsOutSplitByTab ? "\t" : ", "; foreach (var item in sources) { XYZ xYZ = CoordTransformer.GeoCoordToXyz(item, ellipsoid); sb.AppendLine(xYZ.ToString("0.0000000", spliter)); } this.textBox_xyz.Text = sb.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public override int GetHashCode() { return(Ellipsoid.GetHashCode() * 3 + PrimeMeridian.GetHashCode() * 13); }
/// <summary> /// 站心极坐标转换为地心大地坐标 /// </summary> /// <param name="localPolar">目标在地心极坐标的位置</param> /// <param name="sitePosInGeoCenter">测站大地坐标</param> /// <param name="el">参考椭球</param> /// <param name="unit">角度单位</param> /// <returns></returns> public static GeoCoord LocalPolarToGeoCoord(Polar localPolar, GeoCoord sitePosInGeoCenter, Geo.Referencing.Ellipsoid el = null, AngleUnit unit = AngleUnit.Degree) { if (el == null) { el = Geo.Referencing.Ellipsoid.WGS84; } NEU neu = PolarToNeu(localPolar); XYZ xyz = NeuToXyz(neu, sitePosInGeoCenter); return(XyzToGeoCoord(xyz, unit)); }
/// <summary> /// 空间直角坐标系到地心椭球坐标系。此法没有循环,会快一些。与另一方法相比高程有分米以下差别。 /// </summary> /// <param name="xyz"></param> /// <param name="ellipsoid"></param> /// <param name="unit"></param> /// <returns></returns> public static GeoCoord XyzToGeoCoord2(XYZ xyz, Geo.Referencing.Ellipsoid ellipsoid, AngleUnit unit = AngleUnit.Degree) { return(XyzToGeoCoord2(xyz, ellipsoid.SemiMajorAxis, ellipsoid.SemiMinorAxis, unit)); }