Arcengine设置坐标系

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到IGeoDataset
IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;
//QI到IGeoDatasetSchemaEdit
IGeoDatasetSchemaEdit pGeoDatasetSchemaEdit = pGeoDataset as IGeoDatasetSchemaEdit;
if (pGeoDatasetSchemaEdit.CanAlterSpatialReference == true)
{
//创建SpatialReferenceEnvironmentClass对象
ISpatialReferenceFactory2 pSpaRefFactory = new SpatialReferenceEnvironmentClass();
//创建地理坐标系对象
IGeographicCoordinateSystem pNewGeoSys = pSpaRefFactory.CreateGeographicCoordinateSystem(gcsType);//4214代表Beijing1954
pGeoDatasetSchemaEdit.AlterSpatialReference(pNewGeoSys);
}
}
catch (Exception Err)
{
MessageBox.Show(Err.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

3、空间坐标枚举
esriSRGeoCSType
esriSRProjCSType

4.自定义坐标系

用ArcMap定义好坐标系后导出成prj文件,再用ISpatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile方法创建坐标系,可以正确使用。

你可能感兴趣的:(ArcEngine)