投影转换

    /// 
    /// 定义单位与投影转换类
    /// 
    public class UnitAndPrjConvert
    {
        /// 
        /// 米转换成为度
        /// 
        /// 
        /// 
        public static double CovertMeterToDegree(double Meter)
        {
            double intDegree = -1;
            try
            {
                intDegree = Meter * 0.000011634222179609;
            }
            catch (Exception ee)
            {
                intDegree = 0;
            }
            return intDegree;
        }

        /// 
        /// 度转换为米
        /// 
        /// 
        /// 
        public static double CovertDegreeToMeter(double Degree)
        {
            double intMeter = 0;
            try
            {
                intMeter = Degree / 0.000011634222179609;
            }
            catch (Exception ee)
            {
                intMeter = 0;
            }
            return intMeter;
        }


        /// 
        /// 转换面积
        /// 
        /// 
        /// 
        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;
        }
        /// 
        /// 转换线长度
        /// 
        /// 
        /// 
        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;
        }
        /// 
        /// 点坐标转换
        /// 
        /// 
        /// 
        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);
        }
        /// 
        /// 获取米转度参数
        /// 
        /// 横坐标转换参数
        /// 纵坐标转换参数
        /// 
        /// 
        /// 
        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;
            }

        }

        /// 
        /// 动态投影度转米比例
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        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;
            }
        }
        /// 
        /// 平面坐标到经纬度转换
        /// 
        /// 
        /// 
        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);
        }
        /// 
        /// 经纬度到平面
        /// 
        /// 
        /// 
        /// 
        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);
        }
    }

你可能感兴趣的:(C#,ArcGIS,Engine)