private IPoint PRJtoGCS( double x, double y) { IPoint pPoint = new PointClass(); pPoint.PutCoords(x, y); ISpatialReferenceFactory pSRF = new SpatialReferenceEnvironmentClass(); pPoint.SpatialReference = pSRF.CreateProjectedCoordinateSystem( 2414 ); pPoint.Project(pSRF.CreateGeographicCoordinateSystem(( int )esriSRGeoCSType.esriSRGeoCS_Beijing1954)); return pPoint; }
其中,
pPoint.SpatialReference = pSRF.CreateProjectedCoordinateSystem( 2414 );
这行代码是设置pPoint 的空间参考,也就是要转化的点的投影坐标。如果不知道投影坐标的话,转化会报异常。
2414 为该投影的enum 值,如果要查询坐标系的WKID,请点击地理坐标系:www.cnblogs.com/hyqing/p/3660611.html和投影坐标系www.cnblogs.com/hyqing/p/3660662.html
pPoint.Project(pSRF.CreateGeographicCoordinateSystem(( int )esriSRGeoCSType.esriSRGeoCS_Beijing1954));
将该点的投影坐标转化为经纬度。
经纬度到投影:
private IPoint GCStoPRJ(IPoint pPoint, int GCSType, int PRJType) { ISpatialReferenceFactory pSRF = new SpatialReferenceEnvironmentClass(); pPoint.SpatialReference = pSRF.CreateGeographicCoordinateSystem(GCSType); pPoint.Project(pSRF.CreateProjectedCoordinateSystem(PRJType)); return pPoint; }
如果出现:无法嵌入互操作类型提示,右键点击引入的AE库,将其属性中的“嵌入互操作类型”改为False