/// <summary> /// 目标坐标转源坐标(批量) /// </summary> /// <param name="targetCoordiantes">目标坐标集合</param> /// <returns>源坐标集合</returns> public List <ICoordinate> TargetToSourceBatch(IEnumerable <ICoordinate> targetCoordiantes) { if (targetCoordiantes == null || targetCoordiantes.Count() == 0) { return(null); } List <ICoordinate> result = new List <ICoordinate>(); // 两个中间变量 SpherePoint spTemp = null; PlanePoint ppTemp = null; // 高斯转换 GaussKrugerTransform gauss_source = new GaussKrugerTransform(sourceCS); GaussKrugerTransform gauss_target = new GaussKrugerTransform(targetCS); // 大地坐标转换 GeodeticTransform geo_source = new GeodeticTransform(sourceCS, sourceMeridian); GeodeticTransform geo_target = new GeodeticTransform(targetCS, targetMeridian); // 七参数模型,对空间直角坐标进行转换,转换后同样是空间直角坐标 BursaWolfTransform bursa_target = new BursaWolfTransform(sevenParams.Reverse()); foreach (ICoordinate targetCoordinate in targetCoordiantes) { // 如果目标是平面坐标 // 1.平面坐标转高斯坐标;2.高斯反算,转为球面坐标 if (targetCT == CoordinateType.Plane) { ppTemp = gauss_target.PlaneToGauss((PlanePoint)targetCoordinate); spTemp = gauss_target.GaussKrugerReverse(ppTemp, targetMeridian); } else { spTemp = (SpherePoint)targetCoordinate.Clone(); } // 大地坐标转空间直角坐标 ppTemp = geo_target.GeodeticToThreeDimensions(spTemp); // 七参数模型,对空间直角坐标进行转换,转换后同样是空间直角坐标 ppTemp = (PlanePoint)bursa_target.Transform(ppTemp); // 空间直角坐标转大地坐标 spTemp = geo_source.ThreeDimensionsToGeodetic(ppTemp); // 如果源是平面坐标 // 1.高斯正算,转为高斯坐标;2.高斯坐标转平面坐标 if (sourceCT == CoordinateType.Plane) { ppTemp = gauss_source.GaussKrugerForward(spTemp, sourceMeridian); ppTemp = gauss_source.GaussToPlane(ppTemp); result.Add(ppTemp.Clone()); } else { result.Add(spTemp.Clone()); } } return(result); }
/// <summary> /// 源坐标转目标坐标 /// </summary> /// <param name="sourceCoordinate">源坐标</param> /// <returns>目标坐标</returns> public ICoordinate SourceToTarget(ICoordinate sourceCoordinate) { if (sourceCoordinate == null) { return(null); } // 两个中间变量 SpherePoint spTemp = null; PlanePoint ppTemp = null; // 如果源是平面坐标 // 1.平面坐标转高斯坐标;2.高斯反算,转为球面坐标 if (sourceCT == CoordinateType.Plane) { GaussKrugerTransform gauss_source = new GaussKrugerTransform(sourceCS); ppTemp = gauss_source.PlaneToGauss((PlanePoint)sourceCoordinate); spTemp = gauss_source.GaussKrugerReverse(ppTemp, sourceMeridian); } else { spTemp = (SpherePoint)sourceCoordinate.Clone(); } // 大地坐标转空间直角坐标 GeodeticTransform geo_source = new GeodeticTransform(sourceCS, sourceMeridian); ppTemp = geo_source.GeodeticToThreeDimensions(spTemp); // 七参数模型,对空间直角坐标进行转换,转换后同样是空间直角坐标 BursaWolfTransform bursa_source = new BursaWolfTransform(sevenParams); ppTemp = (PlanePoint)bursa_source.Transform(ppTemp); // 空间直角坐标转大地坐标 GeodeticTransform geo_target = new GeodeticTransform(targetCS, targetMeridian); spTemp = geo_target.ThreeDimensionsToGeodetic(ppTemp); ICoordinate result = null; // 如果目标是平面坐标 // 1.高斯正算,转为高斯坐标;2.高斯坐标转平面坐标 if (targetCT == CoordinateType.Plane) { GaussKrugerTransform gauss_target = new GaussKrugerTransform(targetCS); ppTemp = gauss_target.GaussKrugerForward(spTemp, targetMeridian); ppTemp = gauss_target.GaussToPlane(ppTemp); result = ppTemp.Clone(); } else { result = spTemp.Clone(); } return(result); }
/// <summary> /// 高斯-克吕格 投影反算(平面坐标转换为球面坐标) /// </summary> /// <param name="coordinate">平面坐标</param> /// <param name="centerMeridian">中央经线</param> /// <returns>球面坐标</returns> public SpherePoint GaussKrugerReverse(PlanePoint coordinate, double centerMeridian) { double x = coordinate.x; double y = coordinate.y; double lng = 0; double lat = 0; this.xytoBL(x, y, centerMeridian, out lng, out lat); SpherePoint result = new SpherePoint(lng, lat); return(result); }
/// <summary> /// 火星坐标转WGS84坐标(精确) /// </summary> /// <param name="gcj02Point"></param> /// <returns></returns> public SpherePoint GCJ02_To_WGS84_EXACT(SpherePoint gcj02Point) { double gcj02Lng = gcj02Point.lng; double gcj02Lat = gcj02Point.lat; double wgs84Lng = 0; double wgs84Lat = 0; this.gcj02_to_wgs84_exact(gcj02Lng, gcj02Lat, out wgs84Lng, out wgs84Lat); SpherePoint wgs84Point = new SpherePoint(wgs84Lng, wgs84Lat); return(wgs84Point); }
/// <summary> /// WGS84坐标转火星坐标 /// </summary> /// <param name="wgs84Point"></param> /// <returns></returns> public SpherePoint WGS84_To_GCJ02(SpherePoint wgs84Point) { double wgs84Lng = wgs84Point.lng; double wgs84Lat = wgs84Point.lat; double gcj02Lng = 0; double gcj02Lat = 0; this.wgs84_to_gcj02(wgs84Lng, wgs84Lat, out gcj02Lng, out gcj02Lat); SpherePoint gcj02Point = new SpherePoint(gcj02Lng, gcj02Lat); return(gcj02Point); }
/// <summary> /// Web墨卡托坐标转经纬度坐标 /// </summary> /// <param name="xy"></param> /// <returns></returns> public SpherePoint WebMercator_To_LngLat(PlanePoint xy) { double x = xy.x; double y = xy.y; double lng = 0; double lat = 0; this.webmercator_to_lnglat(x, y, out lng, out lat); SpherePoint lnglat = new SpherePoint(lng, lat); return(lnglat); }
/// <summary> /// 经纬度坐标转Web墨卡托坐标 /// </summary> /// <param name="lnglat"></param> /// <returns></returns> public PlanePoint LngLat_To_WebMercator(SpherePoint lnglat) { double lng = lnglat.lng; double lat = lnglat.lat; double x = 0; double y = 0; this.lnglat_to_webmercator(lng, lat, out x, out y); PlanePoint xy = new PlanePoint(x, y); return(xy); }
/// <summary> /// 百度坐标转火星坐标 /// </summary> /// <param name="bd09Point"></param> /// <returns></returns> public SpherePoint BD09_To_GCJ02(SpherePoint bd09Point) { double bd09Lng = bd09Point.lng; double bd09Lat = bd09Point.lat; double gcj02Lng = 0; double gcj02Lat = 0; this.bd09_to_gcj02(bd09Lng, bd09Lat, out gcj02Lng, out gcj02Lat); SpherePoint gcj02Point = new SpherePoint(gcj02Lng, gcj02Lat); return(gcj02Point); }
/// <summary> /// 火星坐标转百度坐标 /// </summary> /// <param name="gcj02Point"></param> /// <returns></returns> public SpherePoint GCJ02_To_BD09(SpherePoint gcj02Point) { double gcj02Lng = gcj02Point.lng; double gcj02Lat = gcj02Point.lat; double bd09Lng = 0; double bd09Lat = 0; this.gcj02_to_bd09(gcj02Lng, gcj02Lat, out bd09Lng, out bd09Lat); SpherePoint bd09Point = new SpherePoint(bd09Lng, bd09Lat); return(bd09Point); }
/// <summary> /// 高斯-克吕格 投影正算(球面坐标转换为平面坐标) /// </summary> /// <param name="coordinate">球面坐标</param> /// <param name="centerMeridian">中央经线</param> /// <returns>平面坐标</returns> public PlanePoint GaussKrugerForward(SpherePoint coordinate, double centerMeridian) { double lng = coordinate.lng; double lat = coordinate.lat; double x = 0; double y = 0; this.BLtoxy(lng, lat, centerMeridian, out x, out y); PlanePoint result = new PlanePoint(x, y); return(result); }
/// <summary> /// 空间直角坐标转大地坐标 /// </summary> /// <param name="coordinate">空间直角坐标</param> /// <returns></returns> public SpherePoint ThreeDimensionsToGeodetic(PlanePoint coordinate) { double X = coordinate.x; double Y = coordinate.y; double Z = coordinate.z; double B = 0; double L = 0; double H = 0; this.XYZtoBLH(X, Y, Z, out B, out L, out H); SpherePoint result = new SpherePoint(B, L); return(result); }
/// <summary> /// 大地坐标转空间直角坐标 /// </summary> /// <param name="coordinate">大地坐标</param> /// <returns></returns> public PlanePoint GeodeticToThreeDimensions(SpherePoint coordinate) { double B = coordinate.lng; double L = coordinate.lat; double H = coordinate.hgt; double X = 0; double Y = 0; double Z = 0; this.BLHtoXYZ(B, L, H, out X, out Y, out Z); PlanePoint result = new PlanePoint(X, Y, Z); return(result); }
/// <summary> /// 百度坐标转WGS84坐标 /// </summary> /// <param name="bd09Point"></param> /// <returns></returns> public SpherePoint BD09_To_WGS84(SpherePoint bd09Point) { double bd09Lng = bd09Point.lng; double bd09Lat = bd09Point.lat; double gcj02Lng = 0; double gcj02Lat = 0; double wgs84Lng = 0; double wgs84Lat = 0; this.bd09_to_gcj02(bd09Lng, bd09Lat, out gcj02Lng, out gcj02Lat); this.gcj02_to_wgs84(gcj02Lng, gcj02Lat, out wgs84Lng, out wgs84Lat); SpherePoint wgs84Point = new SpherePoint(wgs84Lng, wgs84Lat); return(wgs84Point); }
/// <summary> /// WGS84坐标转百度坐标 /// </summary> /// <param name="wgs84Point"></param> /// <returns></returns> public SpherePoint WGS84_To_BD09(SpherePoint wgs84Point) { double wgs84Lng = wgs84Point.lng; double wgs84Lat = wgs84Point.lat; double gcj02Lng = 0; double gcj02Lat = 0; double bd09Lng = 0; double bd09Lat = 0; this.wgs84_to_gcj02(wgs84Lng, wgs84Lat, out gcj02Lng, out gcj02Lat); this.gcj02_to_bd09(gcj02Lng, gcj02Lat, out bd09Lng, out bd09Lat); SpherePoint bd09Point = new SpherePoint(bd09Lng, bd09Lat); return(bd09Point); }
// https://www.openprocessing.org/sketch/41142 SpherePoint[] FibonacciSphere2(int samples = 2) { float phi = (Mathf.Sqrt(5) + 1) / 2 - 1; // golden ratio float ga = phi * 2 * Mathf.PI; // golden angle SpherePoint[] pts = new SpherePoint[samples]; for (int i = 1; i <= samples; ++i) { float lon = ga * i; lon /= 2 * Mathf.PI; lon -= Mathf.Floor(lon); lon *= 2 * Mathf.PI; if (lon > Mathf.PI) { lon -= 2 * Mathf.PI; } // Convert dome height (which is proportional to surface area) to latitude float lat = Mathf.Asin(-1 + 2 * i / (float)samples); pts[i] = new SpherePoint(lat, lon); } return(pts); }