ARCGIS Engine空间参照系处理

原创 2016年08月29日 18:07:39

题记:本文部分内容为转载,部分内容为原创


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. }  
栅格数据椭球变换
      <pre name="code" class="csharp">    /// <summary>
        /// 栅格椭球转换
        /// </summary>
        /// <param name="rasterDataset">已知参照系的椭球</param>
        /// <param name="outSR">输出的栅格的空间参考</param>
        /// <param name="geoTrans">转换七参数</param>
        public static void ProjectRasterWithDatumTransformation(IRasterDataset2 rasterDataset, ISpatialReference outSR, esriSRGeoTransformation2Type geoTrans)
        {          

            IRaster raster = rasterDataset.CreateFullRaster();
            IRasterProps rasterProps = (IRasterProps)raster;
            rasterProps.SpatialReference = outSR;

            //七参数设置
            ISpatialReferenceFactory2 srFactory = new SpatialReferenceEnvironmentClass();
            IGeoTransformation geoTransformation = (IGeoTransformation)
                srFactory.CreateGeoTransformation((int)geoTrans);

           
            IGeoTransformationOperationSet operationSet = new
                GeoTransformationOperationSetClass();
            operationSet.Set(esriTransformDirection.esriTransformForward, geoTransformation);
            operationSet.Set(esriTransformDirection.esriTransformReverse, geoTransformation);

            //设置转换
            IRaster2 raster2 = (IRaster2)raster;
            raster2.GeoTransformations = operationSet;

            //保存转换记过结果
            ISaveAs saveas = (ISaveAs)raster;
            saveas.SaveAs(@"c:\temp\outputRaster.img", null, "IMAGINE Image");
        }

创建空间参考系,导出,导入等操作判断两个空间参考系是否相同
  /// <summary>
        /// 本代码介绍了定义一个投影坐标系,定义格网、容差、值等。然后介绍了导入导出两种方式。导出是讲参照系找出成一个*.prj文件,
        /// 然后应用*.prj文件内容创建一个坐标系
        /// 
        /// </summary>
        private void ImportExportSR_Example()
        {
            // 创建参照系工作空间
            Type factoryType = Type.GetTypeFromProgID(
                           "esriGeometry.SpatialReferenceEnvironment");
            System.Object obj = Activator.CreateInstance(factoryType);
            ISpatialReferenceFactory3 spatialReferenceFactory = obj as
                ISpatialReferenceFactory3;

            // 创建投影参照系UTM_10,椭球为WGS84椭球.
           
           
            IProjectedCoordinateSystem projectedCoordinateSystem =
                spatialReferenceFactory.CreateProjectedCoordinateSystem((int)
                esriSRProjCSType.esriSRProjCS_WGS1984UTM_10N);

            ISpatialReferenceResolution spatialReferenceResolution =
                projectedCoordinateSystem as ISpatialReferenceResolution;
            ISpatialReferenceTolerance spatialReferenceTolerance = projectedCoordinateSystem
                as ISpatialReferenceTolerance;//设置容差默认0.001米

            spatialReferenceResolution.ConstructFromHorizon();
            spatialReferenceTolerance.SetDefaultXYTolerance();

            // 导出参照系
            String fileName = "c:\\temp\\utm10.prj";
            spatialReferenceFactory.ExportESRISpatialReferenceToPRJFile(fileName,
                projectedCoordinateSystem);

            // 根据投影文件在创建一个新的坐标系
            ISpatialReference projectedCoordinateSystem2 =
                spatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile(fileName);

            // 检查两个坐标系是否相同
            IClone comparison = projectedCoordinateSystem as IClone;            
            System.Windows.Forms.MessageBox.Show((comparison.IsEqual
                (projectedCoordinateSystem2 as IClone)).ToString());

            ISpatialReference2 comparePrecisions = projectedCoordinateSystem as
                ISpatialReference2;

            // Should be false, .prj files do not persist coordinate grid information.
            System.Windows.Forms.MessageBox.Show((comparePrecisions.IsXYPrecisionEqual
                (projectedCoordinateSystem2)).ToString());
        }

修改地图的空间参考
///<summary>Use the SpatialReferenceDialog to change the coordinate system or spatial reference of the map.</summary>
///
///<param name="hWnd">The application window handle.</param>
///<param name="map">An IMap interface.</param>
/// 
///<remarks></remarks>
public void ChangeMapSpatialReference(System.Int32 hWnd, ESRI.ArcGIS.Carto.IMap map)
{
  if(map == null)
  {
    return;
  }
  
  ESRI.ArcGIS.CatalogUI.ISpatialReferenceDialog2 spatialReferenceDialog = new ESRI.ArcGIS.CatalogUI.SpatialReferenceDialogClass();
  ESRI.ArcGIS.Geometry.ISpatialReference spatialReference = spatialReferenceDialog.DoModalCreate(true, false, false, hWnd);
  if ((!(map.SpatialReferenceLocked)))
  {
    map.SpatialReference = spatialReference; 
  }
}





相关文章推荐

ArcGIS Engine中空间参照(地理坐标)相关方法总结

本文主要介绍空间参考的创建、获取与修改功能的实现,并以要素集、要素层、要素类为基础进行探讨,希望对大家有所帮助。...

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

oracle查询表空间大小很缓慢

oracle 11gR2在查询表空间的sql很缓慢 sql语句 SELECT A.TABLESPACE_NAME "表空间名称", 100 - ROUND((NVL(B.BYT...
  • weeknd
  • weeknd
  • 2017年04月14日 10:26
  • 825

AE 调用 GP 以及调用过程中产生的若干问题

最近在做二次开发,遇到矢量图层和栅格图层叠加运算 ,用多边形裁切栅格影像的问题 一直没有解决, 花好久时间在这上面, 想尽思路寻找矢量和栅格叠加运算, 来解决问题,可问题依然在,要不就是遍历栅格影像来...

ArcGIS Engine中空间参照(地理坐标)相关方法总结

转载于:http://www.bubuko.com/infodetail-328261.html 1.创建空间参考 /// /// 根据prj文件创建空间参考...

ArcGIS Engine代码共享-工作空间(workspace)对象操作

public class WorkspaceHelper { public static string GISConnectionString; public ...

ArcGIS Engine实现图层间空间选择的优化策略

转自:https://github.com/xinying180/QueryByLayer 如果您是ArcGIS Engine开发人员,也许会有这样的困惑:为什么对两个要素图层进行空间选择,ArcM...

C#+ArcGIS Engine 空间查询

C#+ArcGIS Engine 空间查询 实现利用图层进行空间查询的功能,其功能界面如下: 其功能模块代码如下://从地图中读取目标图层和源图层 private void checkedL...

ArcGIS Engine实现图层间空间选择的优化策略

如果您是ArcGIS Engine开发人员,也许会有这样的困惑:为什么对两个要素图层进行空间选择,ArcMap中瞬间就出结果了,而Engine中则慢很多倍,尤其是当数据量大时,该速率甚至无法忍受。图层...

ArcGIS Engine代码共享-工作空间(workspace)

public class WorkspaceHelper { public static string GISConnectionString; p...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:ARCGIS Engine空间参照系处理
举报原因:
原因补充:

(最多只允许输入30个字)