经纬度与平面坐标的互相转换

两个函数,实现 经纬度与平面坐标的互相转换。 GetGeo输入平面坐标的x、y坐标,返回一个转化后的IPoint。两个方法都是将x、y坐标转化后返回IPoint。
其中32649代表的坐标系如下:
// 将平面坐标转换为经纬度。 获取的而是map的坐标系统。而不是layer的。
 private IPoint GetGeo(double x, double y)
        {
            try
            {                
                IPoint pt = new PointClass();
                ISpatialReferenceFactory pfactory = new SpatialReferenceEnvironmentClass();
                IGeoDataset gd = _line_layer as IGeoDataset;
                ISpatialReference flatref = gd.SpatialReference;
                //转化为经纬度
                ISpatialReference earthref = pfactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
                pt.PutCoords(x, y);
                IGeometry geo = (IGeometry)pt;
                geo.SpatialReference = flatref;
                geo.Project(earthref);
                return pt;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
        }
// 将经纬度转换为平面坐标.
        private IPoint GetProject(double x, double y)
        {

            ISpatialReferenceFactory pfactory = new SpatialReferenceEnvironmentClass();

            ISpatialReference flatref = pfactory.CreateProjectedCoordinateSystem(32649);

            ISpatialReference earthref = pfactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_NAD1983);

            IPoint pt = new PointClass();

            pt.PutCoords(x, y);
            IGeometry geo = (IGeometry)pt;
            geo.SpatialReference = earthref;
            geo.Project(flatref);

            return pt;
        }

你可能感兴趣的:(AE开发)