0
点赞
收藏
分享

微信扫一扫

平面坐标和经纬度坐标相互转换

圣杰 2022-03-30 阅读 68
 /// <summary>
        /// 将经纬度点转换为平面坐标。
        /// </summary>
        /// <param name="map"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public static IPoint GetProject(IMap map, double x, double y)
        {
            try
            {
                IMap pMap = map;
                IPoint pt = new PointClass();
                ISpatialReferenceFactory pfactory = new SpatialReferenceEnvironmentClass();
                ISpatialReference flatref = pMap.SpatialReference;
                ISpatialReference earthref = pfactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
                pt.PutCoords(x, y);
                IGeometry geo = (IGeometry)pt;
                geo.SpatialReference = earthref;
                geo.Project(flatref);
                return pt;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 将经纬度点转换为平面坐标点。
        /// </summary>
        /// <param name="map"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public static IPoint GetProject(IMap map, IPoint point)
        {
            double x = point.X;
            double y = point.Y;
            try
            {
                IMap pMap = map;
                IPoint pt = new PointClass();
                ISpatialReferenceFactory pfactory = new SpatialReferenceEnvironmentClass();
                ISpatialReference flatref = pMap.SpatialReference;
                ISpatialReference earthref = pfactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
                pt.PutCoords(x, y);
                IGeometry geo = (IGeometry)pt;
                geo.SpatialReference = earthref;
                geo.Project(flatref);
                return pt;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 将平面坐标转换为经纬度。
        /// </summary>
        /// <param name="map"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public static IPoint GetGeo(IMap map, double x, double y)
        {
            try
            {
                IMap pMap = map;
                IPoint pt = new PointClass();
                ISpatialReferenceFactory pfactory = new SpatialReferenceEnvironmentClass();
                ISpatialReference flatref = pMap.SpatialReference;
                ISpatialReference earthref = pfactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
                pt.PutCoords(x, y);
                IGeometry geo = (IGeometry)pt;
                geo.SpatialReference = flatref;
                geo.Project(earthref);
                double xx = pt.X;
                return pt;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 将平面坐标点转换为经纬度点。
        /// </summary>
        /// <param name="map"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public static IPoint GetGeo(IMap map, IPoint point)
        {
            double x = point.X;
            double y = point.Y;
            try
            {
                IMap pMap = map;
                IPoint pt = new PointClass();
                ISpatialReferenceFactory pfactory = new SpatialReferenceEnvironmentClass();
                ISpatialReference flatref = pMap.SpatialReference;
                ISpatialReference earthref = pfactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
                pt.PutCoords(x, y);
                IGeometry geo = (IGeometry)pt;
                geo.SpatialReference = flatref;
                geo.Project(earthref);
                double xx = pt.X;
                return pt;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
举报

相关推荐

0 条评论