对大部分开发者而言了解ProjectedCoordinateSyste
SpatialReference Environment这三个组件类是非常有必要的,
对于高级开发者而言,可能需要自定义坐标系统可以使用
这些对象Projection,Datum,AngularUnit,Spheriod,PrimeMeridian和
GeoTransformation等。
1、ISpatialReference地理坐标系对象
(空间参考的设置重要是指地理坐标系对象,设置好它后然后将它赋值给需要的对象)
//创建地理坐标系对象
ISpatialReferenceFactory
ISpatialReference spatialReference = spatialReferenceFactory.CreateGeographicCoordina
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
{
//创建SpatialReferenceEnvironm
ISpatialReferenceFactory
//创建地理坐标系对象
IGeographicCoordinateSys
pGeoDatasetSchemaEdit.AlterSpatialReference(pNewGeoSys);
}
}
catch (Exception Err)
{
MessageBox.Show(Err.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
3、空间坐标枚举
esriSRGeoCSType
esriSRProjCSType
用ArcMap定义好坐标系后导出成prj文件,再用ISpatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile方法创建坐标系,可以正确使用
。