标签:
来自:http://zhihu.esrichina.com.cn/?/question/6858
解决办法】:
首先创建自定义geotransformation,然后用IGeometry.ProjectEx进行投影转换。参考代码(以wgs1984转到Xian80为例):
private void func1ToolStripMenuItem_Click(object sender, EventArgs e) { Type t = Type.GetTypeFromProgID(esriGeometry.SpatialReferenceEnvironment); System.Object obj = Activator.CreateInstance(t); ISpatialReferenceFactory srFact = obj as ISpatialReferenceFactory; IGeographicCoordinateSystem wgs84GCS = srFact.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984); IProjectedCoordinateSystem xian80PCS = srFact.CreateProjectedCoordinateSystem((int)esriSRProjCS4Type.esriSRProjCS_Xian1980_3_Degree_GK_CM_102E); IGeoTransformation geoTrans = CreateGeoTransformation((ISpatialReference)wgs84GCS, (ISpatialReference)xian80PCS); IWorkspaceFactory wksfac = new FileGDBWorkspaceFactoryClass(); IFeatureWorkspace feawks = wksfac.OpenFromFile(@E:TEST.gdb,0) as IFeatureWorkspace; IFeatureClass fc = feawks.OpenFeatureClass(POINT); IFeature fea = fc.Search(null, false).NextFeature(); IGeometry5 geometry; IPoint point = fea.ShapeCopy as IPoint; geometry = point as IGeometry5; geometry.SpatialReference = wgs84GCS; geometry.ProjectEx(xian80PCS, esriTransformDirection.esriTransformForward, geoTrans, false, 0.0, 0.0); point = geometry as IPoint; MessageBox.Show(point.X.ToString(),point.Y.ToString()); } private IGeoTransformation CreateGeoTransformation(ISpatialReference pInputSR, ISpatialReference pOutputSR) { IGeoTransformation pGeoTrans; pGeoTrans = new CoordinateFrameTransformationClass(); ((ICoordinateFrameTransformation)pGeoTrans).PutSpatialReferences(pInputSR, pOutputSR); ((ICoordinateFrameTransformation)pGeoTrans).PutParameters(p1, p2, p3, p4, p5, p6, p7); return pGeoTrans; }
标签:
原文地址:http://www.cnblogs.com/gisoracle/p/5210047.html