ArcGIS Engine提供了一系列对象供开发者管理GIS系统的坐标系统。
对大部分开发者而言了解ProjectedCoordinateSystem, GeographicCoordinateSystem, SpatialReference Environment这三个组件类是非常有必要的,对于高级开发者而言,可能需要自定义坐标系统可以使用这些对象Projection,Datum,AngularUnit,Spheriod,PrimeMeridian和GeoTransformation等。1、ISpatialReference地理坐标系对象(空间参考的设置重要是指地理坐标系对象,设置好它后然后将它赋值给需要的对象)//创建地理坐标系对象ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();ISpatialReference spatialReference = spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);2、改变空间参考
IGeoDatasetSchemaEdit接口的AlterSpatialReference方法可以改变空间参考,在改变前先用CanAlterSpatialReference属性看其能否被改变pGeoDatasetSchemaEdit.AlterSpatialReference(pSpatialReference);实例:
/// <summary>/// 改变图层的空间参考/// </summary>/// <param name="pFeatureLayer">图层</param>/// <param name="pGeoType">空间参考类型</param>private void ChangeLayerRef(IFeatureLayer pFeatureLayer, int gcsType){ try{ IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;//QI到IGeoDatasetIGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;//QI到IGeoDatasetSchemaEditIGeoDatasetSchemaEdit pGeoDatasetSchemaEdit = pGeoDataset as IGeoDatasetSchemaEdit;if (pGeoDatasetSchemaEdit.CanAlterSpatialReference == true){ //创建SpatialReferenceEnvironmentClass对象ISpatialReferenceFactory2 pSpaRefFactory = new SpatialReferenceEnvironmentClass();//创建地理坐标系对象IGeographicCoordinateSystem pNewGeoSys = pSpaRefFactory.CreateGeographicCoordinateSystem(gcsType);//4214代表Beijing1954pGeoDatasetSchemaEdit.AlterSpatialReference(pNewGeoSys);}}catch (Exception Err){ MessageBox.Show(Err.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);}}3、空间坐标枚举
esriSRGeoCSTypeesriSRProjCSType4.自定义坐标系
用ArcMap定义好坐标系后导出成prj文件,再用ISpatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile方法创建坐标系,可以正确使用。
转自:http://www.cnblogs.com/qb371/archive/2011/10/12/2366294.html