一、获取要素类的空间参考坐标系
//打开工作空间中的要素类
IWorkspaceFactory wf = new ShapefileWorkspaceFactoryClass();
IWorkspace ws = wf.OpenFromFile(shpPath, 0);// shpPath为D://test 文件夹
IFeatureClass mFeatureclass =(ws as IFeatureWorkspace).OpenFeatureClass("地块");//地块为文件夹中的shp文件名
//获取要素类的空间参考坐标系
IGeoDataset mGeoDataset = mFeatureclass as IGeoDataset;
ISpatialReference pSpatialReference = mGeoDataset.SpatialReference;
二、修改要素类的空间参考坐标系
//修改要素类的空间参考坐标系
IGeoDataset pGeoDataset = pFeatureclass as IGeoDataset;
IGeoDatasetSchemaEdit pGeoDatasetSchemaEdit = pGeoDataset as IGeoDatasetSchemaEdit;
if (pGeoDatasetSchemaEdit.CanAlterSpatialReference == true)
{
pGeoDatasetSchemaEdit.AlterSpatialReference(pSpatialReference);
}
三、修改mxd文件数据框的空间参考坐标系
string mxdPath = "D:\\test.mxd";
IMapDocument pMapDocument = new MapDocumentClass();
pMapDocument.Open(mxdPath , "");//打开mxd文件
axPageLayoutControl1.PageLayout = pMapDocument.PageLayout;
IActiveView pActiveView = this.axPageLayoutControl1.PageLayout as IActiveView;
IGraphicsContainer pGrapContainer = pActiveView as IGraphicsContainer;
IMapFrame pMapFrame = pGrapContainer.FindFrame(pActiveView.FocusMap) as IMapFrame;
pMapFrame.Map.SpatialReference = pSpatialReference;//修改数据框坐标系