ArcEngine、C#中经纬度坐标、投影坐标之间的转换

  
  // 将经纬度点转换为平面坐标。
         
        private IPoint GetProject(IActiveViewpActiveView,double x, double y)
        {
            try
            {
                IMap pMap =pActiveView.FocusMap;
                IPoint pt = newPointClass();
                ISpatialReferenceFactory pfactory = new SpatialReferenceEnvironm entClass();
                ISpatialReference flatref =pMap.SpatialReference;
                ISpatialReference earthref =pfactory.CreateGeographicCoordina teSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
                pt.PutCoords(x, y);
                IGeometry geo =(IGeometry)pt;
                geo.SpatialReference =earthref;
                geo.Project(flatref);
                return pt;
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
                 
            }
        }
        // 将平面坐标转换为经纬度。
        private IPoint GetGeo(IActiveViewpActiveView,double x, double y)
        {
            try
            {
                IMap pMap =pActiveView.FocusMap;
                IPoint pt = newPointClass();
                ISpatialReferenceFactory pfactory = new SpatialReferenceEnvironm entClass();
                ISpatialReference flatref =pMap.SpatialReference;
                ISpatialReference earthref =pfactory.CreateGeographicCoordina teSystem((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)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
        }

在使用时:IActiveView pActiveView = axMapControl1.ActiveView;

其他参考:::
        public static void bj54tojingweiduAo(IActiveViewpActiveView, double inx, double iny, ref string outx, ref stringouty)
        {
            try
            {
                IMap pMap =pActiveView.FocusMap;
                SpatialReferenceEnvironm entpSpRE = new SpatialReferenceEnvironm ent();
                IGeographicCoordinateSys tempGeoCS =pSpRE.CreateGeographicCoordina teSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
                ISpatialReference pSpr =pGeoCS;
                IPoint pPoint = newESRI.ArcGIS.Geometry.Point();
                pPoint.X = inx;
                pPoint.Y = iny;
                IGeometry pGeo =pPoint;
                pGeo.SpatialReference =pMap.SpatialReference;
                pGeo.Project(pSpr);//坐标转换,由当前地图坐标转为北京54经纬度坐标
                double jwd_jd =pPoint.X;
                double jwd_wd =pPoint.Y;
                //转化成度、分、秒
                //经度
                int Jd, Wd, Jf, Wf;
                double temp;
                Single Jm, Wm;
                Jd = (int)jwd_jd; //度
                temp = (jwd_jd - Jd) *60;
                Jf = (int)temp; //分
                temp = (temp - Jf) *60;
                Jm = Convert.ToInt32(temp);//秒
                //纬度
                Wd = (int)jwd_wd; //度
                temp = (jwd_wd - Wd) *60;
                Wf = (int)temp; //分
                temp = (temp - Wf) *60;
                Wm = Convert.ToInt32(temp);//秒
                outx = Jd + "度" + Jf + "分" +Jm + "秒";
                outy = Wd + "度" + Wf + "分" +Wm + "秒";
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值