1. 程式人生 > >ArcGIS Engine中空間參照(地理坐標)相關方法總結轉

ArcGIS Engine中空間參照(地理坐標)相關方法總結轉

lte board nbsp file 創建 nvi red 空間範圍 phi

ArcGIS Engine中空間參照(地理坐標)相關方法總結

來自:http://blog.csdn.net/u011170962/article/details/38776101

1.創建空間參考

[csharp] view plain copy print?
  1. /// <summary>
  2. /// 根據prj文件創建空間參考
  3. /// </summary>
  4. /// <param name="strProFile">空間參照文件</param>
  5. /// <returns></returns>
  6. public static ISpatialReference CreateSpatialReference(string strProFile)
  7. {
  8. ISpatialReferenceFactory pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass();
  9. ISpatialReference pSpatialReference = pSpatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile(strProFile);
  10. return pSpatialReference;
  11. }
[csharp] view plain copy
print?
  1. /// <summary>
  2. /// 創建地理坐標系
  3. /// </summary>
  4. /// <param name="gcType">esriSRProjCS4Type</param>
  5. /// <returns></returns>
  6. public static ISpatialReference CreateGeographicCoordinate(esriSRProjCS4Type gcsType)
  7. {
  8. ISpatialReferenceFactory pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass();
  9. ISpatialReference pSpatialReference = pSpatialReferenceFactory.CreateGeographicCoordinateSystem((int)gcsType);
  10. return pSpatialReference;
  11. }
[csharp] view plain copy print?
  1. /// <summary>
  2. /// 創建投影坐標系
  3. /// </summary>
  4. /// <param name="pcType">esriSRProjCS4Type</param>
  5. /// <returns></returns>
  6. public static ISpatialReference CreateProjectedCoordinate(esriSRProjCS4Type pcsType)
  7. {
  8. ISpatialReferenceFactory2 pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass();
  9. ISpatialReference pSpatialReference = pSpatialReferenceFactory.CreateProjectedCoordinateSystem((int)pcsType);
  10. return pSpatialReference;
  11. }
[csharp] view plain copy print?
  1. /// <summary>
  2. /// 獲取空投影
  3. /// </summary>
  4. /// <returns></returns>
  5. public static ISpatialReference CreateUnKnownSpatialReference()
  6. {
  7. ISpatialReference pSpatialReference = new UnknownCoordinateSystemClass();
  8. pSpatialReference.SetDomain(0, 99999999, 0, 99999999);//設置空間範圍
  9. return pSpatialReference;
  10. }

2.獲取空間參考

[csharp] view plain copy print?
  1. /// <summary>
  2. /// 獲取要素集空間參考
  3. /// </summary>
  4. /// <param name="pFeatureDataset">要素集</param>
  5. /// <returns></returns>
  6. public static ISpatialReference GetSpatialReference(IFeatureDataset pFeatureDataset)
  7. {
  8. IGeoDataset pGeoDataset = pFeatureDataset as IGeoDataset;
  9. ISpatialReference pSpatialReference = pGeoDataset.SpatialReference;
  10. return pSpatialReference;
  11. }
[csharp] view plain copy print?
  1. /// <summary>
  2. /// 獲取要素層空間參考
  3. /// </summary>
  4. /// <param name="pFeatureLayer">要素層</param>
  5. /// <returns></returns>
  6. public static ISpatialReference GetSpatialReferenc(IFeatureLayer pFeatureLayer)
  7. {IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
  8. IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;
  9. ISpatialReference pSpatialReference = pGeoDataset.SpatialReference;
  10. return pSpatialReference;
  11. }
[csharp] view plain copy print?
  1. /// <summary>
  2. /// 獲取要素類空間參考
  3. /// </summary>
  4. /// <param name="pFeatureClass">要素類</param>
  5. /// <returns></returns>
  6. public static ISpatialReference GetSpatialReference(IFeatureClass pFeatureClass)
  7. {
  8. IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;
  9. ISpatialReference pSpatialReference = pGeoDataset.SpatialReference;
  10. return pSpatialReference;
  11. }

3.修改空間參考

[csharp] view plain copy print?
  1. /// <summary>
  2. /// 修改要素集空間參考
  3. /// </summary>
  4. /// <param name="pFeatureDataset">要素集</param>
  5. /// <param name="pSpatialReference">新空間參考</param>
  6. public static void AlterSpatialReference(IFeatureDataset pFeatureDataset, ISpatialReference pSpatialReference)
  7. {
  8. IGeoDataset pGeoDataset = pFeatureDataset as IGeoDataset;
  9. IGeoDatasetSchemaEdit pGeoDatasetSchemaEdit = pGeoDataset as IGeoDatasetSchemaEdit;
  10. if (pGeoDatasetSchemaEdit.CanAlterSpatialReference == true)
  11. pGeoDatasetSchemaEdit.AlterSpatialReference(pSpatialReference);
  12. }
[csharp] view plain copy print?
  1. /// <summary>
  2. /// 修改要素類空間參考
  3. /// </summary>
  4. /// <param name="pFeatureClass">要素類</param>
  5. /// <param name="pSpatialReference">新空間參考</param>
  6. public static void AlterSpatialReference(IFeatureClass pFeatureClass, ISpatialReference pSpatialReference)
  7. {
  8. IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;
  9. IGeoDatasetSchemaEdit pGeoDatasetSchemaEdit = pGeoDataset as IGeoDatasetSchemaEdit;
  10. if (pGeoDatasetSchemaEdit.CanAlterSpatialReference == true)
  11. pGeoDatasetSchemaEdit.AlterSpatialReference(pSpatialReference);
  12. }

ArcGIS Engine中空間參照(地理坐標)相關方法總結轉