using System; using System.Collections.Generic; using System.Linq; using System.Text; using ForeStar.GIS.Geometry; using ForeStar.GIS.SpatialReference; using ForeStar.GIS.Util; using ForeStar.GIS.MapZone.Geometry; namespace Forestar.GZ.YZL.Utils { /// <summary> /// 定义单位与投影转换类 /// </summary> public class UnitAndPrjConvert { /// <summary> /// 米转换成为度 /// </summary> /// <param name="Meter"></param> /// <returns></returns> public static double CovertMeterToDegree(double Meter) { double intDegree = -1; try { intDegree = Meter * 0.000011634222179609; } catch (Exception ee) { intDegree = 0; } return intDegree; } /// <summary> /// 度转换为米 /// </summary> /// <param name="Meter"></param> /// <returns></returns> public static double CovertDegreeToMeter(double Degree) { double intMeter = 0; try { intMeter = Degree / 0.000011634222179609; } catch (Exception ee) { intMeter = 0; } return intMeter; } /// <summary> /// 转换面积 /// </summary> /// <param name="pPolygon"></param> /// <returns></returns> public static double CovertArea(IPolygon pPolygon, SpatialInfoType pSpatialInfoType, int pDaiHao, DaiHaoType pDHType) { if (pPolygon == null) return 0; ForeStar.GIS.SpatialReference.CoordinateCreateParams coordinateCreateParams = new ForeStar.GIS.SpatialReference.CoordinateCreateParams(); coordinateCreateParams.DaiHao = pDaiHao; coordinateCreateParams.DaiHaoType = pDHType; //coordinateCreateParams.SpatialInfoType = ForeStar.GIS.SpatialReference.SpatialInfoType.SpatialInfo80; coordinateCreateParams.SpatialInfoType = pSpatialInfoType; coordinateCreateParams.Name = "test"; coordinateCreateParams.AddDiaHao = true; coordinateCreateParams.CoordianteType = ForeStar.GIS.SpatialReference.CoordianteType.ProjectCoordiante; ICoordinateSystem project = ForeStar.GISUI.Utils.SpatialReferenceUtils.GetSelectSpatialReference(coordinateCreateParams); pPolygon.Project(project); double area = pPolygon.GetArea(); //area = Math.Round(area / 10000*15, 2); area = Math.Round(area / 10000 * 15, 1);//TODO YCL return area; } /// <summary> /// 转换线长度 /// </summary> /// <param name="pLine"></param> /// <returns></returns> public static double ConvertLength(IPolyline pLine, SpatialInfoType pSpatialInfoType, int pDaiHao, DaiHaoType pDHType) { if (pLine == null) return 0; ForeStar.GIS.SpatialReference.CoordinateCreateParams coordinateCreateParams = new ForeStar.GIS.SpatialReference.CoordinateCreateParams(); coordinateCreateParams.DaiHao = pDaiHao; coordinateCreateParams.DaiHaoType = pDHType; coordinateCreateParams.SpatialInfoType = pSpatialInfoType; coordinateCreateParams.Name = "test"; coordinateCreateParams.AddDiaHao = true; coordinateCreateParams.CoordianteType = ForeStar.GIS.SpatialReference.CoordianteType.ProjectCoordiante; ICoordinateSystem project = ForeStar.GISUI.Utils.SpatialReferenceUtils.GetSelectSpatialReference(coordinateCreateParams); pLine.Project(project); double dLength = pLine.Lenght; dLength = Math.Round(dLength, 4); if (dLength == null) return 0; return dLength; } /// <summary> /// 点坐标转换 /// </summary> /// <param name="pPolygon"></param> /// <returns></returns> public static void CovertPointZB(ref IPoint pPoint, SpatialInfoType pSpatialInfoType, int pDaiHao, DaiHaoType pDHType) { ForeStar.GIS.SpatialReference.CoordinateCreateParams coordinateCreateParams = new ForeStar.GIS.SpatialReference.CoordinateCreateParams(); coordinateCreateParams.DaiHao = pDaiHao; coordinateCreateParams.DaiHaoType = pDHType; coordinateCreateParams.SpatialInfoType = pSpatialInfoType; coordinateCreateParams.Name = "PointConvert"; coordinateCreateParams.AddDiaHao = true; coordinateCreateParams.CoordianteType = ForeStar.GIS.SpatialReference.CoordianteType.ProjectCoordiante; ICoordinateSystem project = ForeStar.GISUI.Utils.SpatialReferenceUtils.GetSelectSpatialReference(coordinateCreateParams); pPoint.Project(project); } public static void ConvertPointZB2(ref IPoint pPoint, int iDaiHao, SpatialInfoType pSpatialInfoType, DaiHaoType pDHType) { ForeStar.GIS.SpatialReference.CoordinateCreateParams coordinateCreateParams = new ForeStar.GIS.SpatialReference.CoordinateCreateParams(); coordinateCreateParams.DaiHao = iDaiHao; coordinateCreateParams.DaiHaoType = pDHType; coordinateCreateParams.SpatialInfoType = pSpatialInfoType; coordinateCreateParams.Name = "PointConvert"; coordinateCreateParams.AddDiaHao = true; coordinateCreateParams.CoordianteType = ForeStar.GIS.SpatialReference.CoordianteType.ProjectCoordiante; ICoordinateSystem project = ForeStar.GISUI.Utils.SpatialReferenceUtils.GetSelectSpatialReference(coordinateCreateParams); pPoint.Project(project); } public static void ConvertGeometryZB(ref IGeometry geometry, int iDaiHao, SpatialInfoType pSpatialInfoType, DaiHaoType pDHType) { if (geometry == null) return; ForeStar.GIS.SpatialReference.CoordinateCreateParams coordinateCreateParams = new ForeStar.GIS.SpatialReference.CoordinateCreateParams(); coordinateCreateParams.DaiHao = iDaiHao; coordinateCreateParams.DaiHaoType = pDHType; coordinateCreateParams.SpatialInfoType = pSpatialInfoType; coordinateCreateParams.Name = "GeometryConvert"; coordinateCreateParams.AddDiaHao = false; coordinateCreateParams.CoordianteType = ForeStar.GIS.SpatialReference.CoordianteType.ProjectCoordiante; ICoordinateSystem project = ForeStar.GISUI.Utils.SpatialReferenceUtils.GetSelectSpatialReference(coordinateCreateParams); geometry.Project(project); } /// <summary> /// 获取米转度参数 /// </summary> /// <param name="X">横坐标转换参数</param> /// <param name="Y">纵坐标转换参数</param> /// <param name="RateX"></param> /// <param name="RateY"></param> /// <returns></returns> public static bool MeterToDegreeRate(double X, double Y, out double RateX, out double RateY, SpatialInfoType pSpatialInfoType, DaiHaoType pDHType) { try { ForeStar.GIS.SpatialReference.CoordinateCreateParams coordinateCreateParams1 = new ForeStar.GIS.SpatialReference.CoordinateCreateParams(); coordinateCreateParams1.SpatialInfoType = pSpatialInfoType; coordinateCreateParams1.Name = "PointConvert"; coordinateCreateParams1.CoordianteType = ForeStar.GIS.SpatialReference.CoordianteType.GeoCoordinate; ICoordinateSystem project1 = ForeStar.GISUI.Utils.SpatialReferenceUtils.GetSelectSpatialReference(coordinateCreateParams1); int iDaiHao = MapSpatialReferenceUtils.GetDaihao(X, false); IPoint Point1 = new PointClass(); Point1.X = X; Point1.Y = Y; Point1.CoordinateSystem = project1; ConvertPointZB2(ref Point1, iDaiHao, pSpatialInfoType, pDHType); //IPoint Point2 = new PointClass(); Point1.X = Point1.X + 10; Point1.Y = Point1.Y + 10; //Point2.CoordinateSystem = project2; //CommonClass.ConvertPointZB3(ref Point2, iDaiHao); ConvertPointZB3(ref Point1, iDaiHao, pSpatialInfoType, pDHType); RateX = (Point1.X - X) / 10; RateY = (Point1.Y - Y) / 10; return true; } catch (Exception e) { LogManage.WriteLog("平面坐标到经纬度坐标转换失败" + e.Message); RateX = 0.000011634222179609; RateY = 0.000011634222179609; return false; } } /// <summary> /// 动态投影度转米比例 /// </summary> /// <param name="X"></param> /// <param name="Y"></param> /// <param name="RateX"></param> /// <param name="RateY"></param> /// <returns></returns> public static bool DegreerToMetreRate(double X, double Y, out double RateX, out double RateY, SpatialInfoType pSpatialInfoType, DaiHaoType pDHType) { try { ForeStar.GIS.SpatialReference.CoordinateCreateParams coordinateCreateParams1 = new ForeStar.GIS.SpatialReference.CoordinateCreateParams(); coordinateCreateParams1.SpatialInfoType = pSpatialInfoType; coordinateCreateParams1.Name = "PointConvert"; coordinateCreateParams1.CoordianteType = ForeStar.GIS.SpatialReference.CoordianteType.GeoCoordinate; ICoordinateSystem project1 = ForeStar.GISUI.Utils.SpatialReferenceUtils.GetSelectSpatialReference(coordinateCreateParams1); int iDaiHao = MapSpatialReferenceUtils.GetDaihao(X, false); IPoint Point1 = new PointClass(); Point1.X = X; Point1.Y = Y; Point1.CoordinateSystem = project1; ConvertPointZB2(ref Point1, iDaiHao, pSpatialInfoType, pDHType); //IPoint Point2 = new PointClass(); Point1.X = Point1.X + 10; Point1.Y = Point1.Y + 10; //Point2.CoordinateSystem = project2; //CommonClass.ConvertPointZB3(ref Point2, iDaiHao); ConvertPointZB3(ref Point1, iDaiHao, pSpatialInfoType, pDHType); RateX = 10 / (Point1.X - X); RateY = 10 / (Point1.Y - Y); return true; } catch (Exception e) { LogManage.WriteLog("经纬度坐标到地理坐标转换失败" + e.Message); RateX = 1 / 0.000011634222179609; RateY = 1 / 0.000011634222179609; return false; } } /// <summary> /// 平面坐标到经纬度转换 /// </summary> /// <param name="pPoint"></param> /// <param name="iDaiHao"></param> public static void ConvertPointZB3(ref IPoint pPoint, int iDaiHao, SpatialInfoType pSpatialInfoType, DaiHaoType pDHType) { if (pPoint == null) return; ForeStar.GIS.SpatialReference.CoordinateCreateParams coordinateCreateParams = new ForeStar.GIS.SpatialReference.CoordinateCreateParams(); coordinateCreateParams.DaiHao = iDaiHao; coordinateCreateParams.DaiHaoType = pDHType; coordinateCreateParams.SpatialInfoType = pSpatialInfoType; coordinateCreateParams.Name = "PointConvert"; coordinateCreateParams.AddDiaHao = true; coordinateCreateParams.CoordianteType = ForeStar.GIS.SpatialReference.CoordianteType.GeoCoordinate; ICoordinateSystem project = ForeStar.GISUI.Utils.SpatialReferenceUtils.GetSelectSpatialReference(coordinateCreateParams); pPoint.Project(project); } /// <summary> /// 经纬度到平面 /// </summary> /// <param name="geometry"></param> /// <param name="DaiHao"></param> /// <param name="addDaiHao"></param> public static void ConvertGeometryZB(ref IGeometry geometry, int DaiHao, bool addDaiHao, SpatialInfoType pSpatialInfoType, DaiHaoType pDHType) { if (geometry == null) return; ForeStar.GIS.SpatialReference.CoordinateCreateParams coordinateCreateParams = new ForeStar.GIS.SpatialReference.CoordinateCreateParams(); coordinateCreateParams.DaiHao = DaiHao; coordinateCreateParams.DaiHaoType = pDHType; coordinateCreateParams.SpatialInfoType = pSpatialInfoType; coordinateCreateParams.Name = "ProjectConvert"; coordinateCreateParams.AddDiaHao = addDaiHao; coordinateCreateParams.CoordianteType = ForeStar.GIS.SpatialReference.CoordianteType.ProjectCoordiante; ICoordinateSystem project = ForeStar.GISUI.Utils.SpatialReferenceUtils.GetSelectSpatialReference(coordinateCreateParams); geometry.Project(project); } } }