ArcGIS Engine中空間參照(地理坐標)相關方法總結轉
阿新 • • 發佈:2017-05-30
lte board nbsp file 創建 nvi red 空間範圍 phi
print?
ArcGIS Engine中空間參照(地理坐標)相關方法總結
來自:http://blog.csdn.net/u011170962/article/details/38776101
1.創建空間參考
[csharp] view plain copy print?- /// <summary>
- /// 根據prj文件創建空間參考
- /// </summary>
- /// <param name="strProFile">空間參照文件</param>
- /// <returns></returns>
- public static ISpatialReference CreateSpatialReference(string strProFile)
- {
- ISpatialReferenceFactory pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass();
- ISpatialReference pSpatialReference = pSpatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile(strProFile);
- return pSpatialReference;
- }
- /// <summary>
- /// 創建地理坐標系
- /// </summary>
- /// <param name="gcType">esriSRProjCS4Type</param>
- /// <returns></returns>
- public static ISpatialReference CreateGeographicCoordinate(esriSRProjCS4Type gcsType)
- {
- ISpatialReferenceFactory pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass();
- ISpatialReference pSpatialReference = pSpatialReferenceFactory.CreateGeographicCoordinateSystem((int)gcsType);
- return pSpatialReference;
- }
- /// <summary>
- /// 創建投影坐標系
- /// </summary>
- /// <param name="pcType">esriSRProjCS4Type</param>
- /// <returns></returns>
- public static ISpatialReference CreateProjectedCoordinate(esriSRProjCS4Type pcsType)
- {
- ISpatialReferenceFactory2 pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass();
- ISpatialReference pSpatialReference = pSpatialReferenceFactory.CreateProjectedCoordinateSystem((int)pcsType);
- return pSpatialReference;
- }
- /// <summary>
- /// 獲取空投影
- /// </summary>
- /// <returns></returns>
- public static ISpatialReference CreateUnKnownSpatialReference()
- {
- ISpatialReference pSpatialReference = new UnknownCoordinateSystemClass();
- pSpatialReference.SetDomain(0, 99999999, 0, 99999999);//設置空間範圍
- return pSpatialReference;
- }
2.獲取空間參考
[csharp] view plain copy print?- /// <summary>
- /// 獲取要素集空間參考
- /// </summary>
- /// <param name="pFeatureDataset">要素集</param>
- /// <returns></returns>
- public static ISpatialReference GetSpatialReference(IFeatureDataset pFeatureDataset)
- {
- IGeoDataset pGeoDataset = pFeatureDataset as IGeoDataset;
- ISpatialReference pSpatialReference = pGeoDataset.SpatialReference;
- return pSpatialReference;
- }
- /// <summary>
- /// 獲取要素層空間參考
- /// </summary>
- /// <param name="pFeatureLayer">要素層</param>
- /// <returns></returns>
- public static ISpatialReference GetSpatialReferenc(IFeatureLayer pFeatureLayer)
- {IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
- IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;
- ISpatialReference pSpatialReference = pGeoDataset.SpatialReference;
- return pSpatialReference;
- }
- /// <summary>
- /// 獲取要素類空間參考
- /// </summary>
- /// <param name="pFeatureClass">要素類</param>
- /// <returns></returns>
- public static ISpatialReference GetSpatialReference(IFeatureClass pFeatureClass)
- {
- IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;
- ISpatialReference pSpatialReference = pGeoDataset.SpatialReference;
- return pSpatialReference;
- }
3.修改空間參考
[csharp] view plain copy print?- /// <summary>
- /// 修改要素集空間參考
- /// </summary>
- /// <param name="pFeatureDataset">要素集</param>
- /// <param name="pSpatialReference">新空間參考</param>
- public static void AlterSpatialReference(IFeatureDataset pFeatureDataset, ISpatialReference pSpatialReference)
- {
- IGeoDataset pGeoDataset = pFeatureDataset as IGeoDataset;
- IGeoDatasetSchemaEdit pGeoDatasetSchemaEdit = pGeoDataset as IGeoDatasetSchemaEdit;
- if (pGeoDatasetSchemaEdit.CanAlterSpatialReference == true)
- pGeoDatasetSchemaEdit.AlterSpatialReference(pSpatialReference);
- }
- /// <summary>
- /// 修改要素類空間參考
- /// </summary>
- /// <param name="pFeatureClass">要素類</param>
- /// <param name="pSpatialReference">新空間參考</param>
- public static void AlterSpatialReference(IFeatureClass pFeatureClass, ISpatialReference pSpatialReference)
- {
- IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;
- IGeoDatasetSchemaEdit pGeoDatasetSchemaEdit = pGeoDataset as IGeoDatasetSchemaEdit;
- if (pGeoDatasetSchemaEdit.CanAlterSpatialReference == true)
- pGeoDatasetSchemaEdit.AlterSpatialReference(pSpatialReference);
- }
ArcGIS Engine中空間參照(地理坐標)相關方法總結轉