我是靠谱客的博主 超级大侠,最近开发中收集的这篇文章主要介绍arcengine镶嵌数据集的基本操作(C#),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

1.创建新的镶嵌数据集。

  /// <summary> 
  /// 创建镶嵌数据集 
  /// </summary> 
  /// <param name="pFgdbWorkspace">工作空间</param> 
  /// <param name="pMDame">名称</param> 
  /// <param name="pSrs">空间参考</param>
  /// <returns>镶嵌数据集</returns>
  public static IMosaicDataset CreateMosaicDataset(IWorkspace pFgdbWorkspace, string pMDame, ISpatialReference pSrs)
  {
      try
      {
          IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactory();               
          ICreateMosaicDatasetParameters pCreationPars = new CreateMosaicDatasetParametersClass();

          pCreationPars.BandCount = 3;
          pCreationPars.PixelType = rstPixelType.PT_UCHAR;
          IMosaicWorkspaceExtensionHelper pMosaicExentionHelper = new MosaicWorkspaceExtensionHelperClass();
          IMosaicWorkspaceExtension pMosaicExtention = pMosaicExentionHelper.FindExtension(pFgdbWorkspace);
          return pMosaicExtention.CreateMosaicDataset(pMDame, pSrs, pCreationPars, "DOM");
      }
      catch (Exception)
      {               
          return null; 
      }            
  }

2.获取已有镶嵌数据集

 /// <summary>
 /// 获取镶嵌数据集
 /// </summary>
 /// <param name="MosaicName">数据集名称</param>
 /// <param name="workspace">数据集所在工作空间</param>
 /// <returns>镶嵌数据集</returns>
 public static IMosaicDataset GetMosaicDataset(string MosaicName, IWorkspace workspace)
 {
     IMosaicDataset pMosicDataset = null;
     IMosaicWorkspaceExtensionHelper pMosaicWsExHelper = new MosaicWorkspaceExtensionHelperClass();
     IMosaicWorkspaceExtension pMosaicWsExt = pMosaicWsExHelper.FindExtension(workspace);
     if (pMosaicWsExt != null)
     {
         try
         {
             pMosicDataset = pMosaicWsExt.OpenMosaicDataset(MosaicName);
         }
         catch (Exception ex)
         {
             return pMosicDataset;
         }
     }
     return pMosicDataset;
 }

3.获取已有镶嵌数据表

/// <summary>
 /// 获取镶嵌数据表
 /// </summary>
 /// <param name="pMosaicDataset">镶嵌数据集</param>
 /// <returns>镶嵌数据表</returns>
 public static ITable GetMosaicDatasetTable(IMosaicDataset pMosaicDataset)
 {
     ITable pTable = null;
     IEnumName pEnumName = pMosaicDataset.Children;
     pEnumName.Reset();
     ESRI.ArcGIS.esriSystem.IName pName;
     while ((pName = pEnumName.Next()) != null)
     {
         pTable = pName.Open() as ITable;
         int i = pTable.Fields.FieldCount;
         if (i >= 21) break;
     }
     return pTable;
 }

4.删除某个镶嵌数据集

 /// <summary>
 /// 删除镶嵌数据集
 /// </summary>
 /// <param name="rasterName">名称</param>
 /// <param name="workspace">工作空间</param>
 /// <returns>删除成功时返回true,否则返回false</returns>
 public static bool DeleteMosaic(string rasterName, IWorkspace workspace)
 {
     try
     {               
         IMosaicWorkspaceExtensionHelper pMosaicWsExHelper = new MosaicWorkspaceExtensionHelperClass();
         IMosaicWorkspaceExtension pMosaicWsExt = pMosaicWsExHelper.FindExtension(workspace);
         pMosaicWsExt.DeleteMosaicDataset(rasterName);
         return true;
     }
     catch (Exception ex)
     {
         return false;
     }
 }

5.在镶嵌数据集中添加删格数据

  /// <summary>
 /// 导入栅格数据
 /// </summary>
 /// <param name="filePath">导入文件路径</param>
 /// <param name="mosaicDataSet">镶嵌数据集</param>
 public static bool ImportRasterToMosaic(string filePath, IMosaicDataset mosaicDataSet)
 {
     try
     {
         IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();
         IRasterWorkspace rasterWorkspace = workspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(filePath), 0) as IRasterWorkspace;
         IMosaicDatasetOperation mOp = (IMosaicDatasetOperation)mosaicDataSet;
         IAddRastersParameters addRs = new AddRastersParametersClass();
         IRasterDatasetCrawler rsDsetCrawl = new RasterDatasetCrawlerClass();
         rsDsetCrawl.RasterDataset = rasterWorkspace.OpenRasterDataset(System.IO.Path.GetFileName(filePath));
         IRasterTypeFactory rsFact = new RasterTypeFactoryClass();
         IRasterType rsType = rsFact.CreateRasterType("Raster dataset");
         rsType.FullName = rsDsetCrawl.DatasetName;
         addRs.Crawler = (IDataSourceCrawler)rsDsetCrawl;
         addRs.RasterType = rsType;
         mOp.AddRasters(addRs, null);
         //计算cellSize 和边界
         // Create a calculate cellsize ranges parameters object.
         ICalculateCellSizeRangesParameters computeArgs = new CalculateCellSizeRangesParametersClass();
         // Use the mosaic dataset operation interface to calculate cellsize ranges.
         mOp.CalculateCellSizeRanges(computeArgs, null);
         // Create a build boundary parameters object.
         IBuildBoundaryParameters boundaryArgs = new BuildBoundaryParametersClass();
         // Set flags that control boundary generation.
         boundaryArgs.AppendToExistingBoundary = true;
         // Use the mosaic dataset operation interface to build boundary.
         mOp.BuildBoundary(boundaryArgs, null);
         return true;
     }
     catch (Exception)
     {

         return false;
     }

 }

6.导出镶嵌数据集

  /// <summary>
 /// 导出镶嵌数据集为删格数据
 /// </summary>
 /// <param name="RasterName">数据名称</param>
 /// <param name="workspaceDB">工作空间</param>
 /// <param name="DownLoadLocation">保存路径</param>
 /// <returns>成功返回true,失败返回false</returns>
 public static bool DownLoadMosaic( string RasterName,IWorkspace workspaceDB,string DownLoadLocation)
 {
     try
     {
         IWorkspace wsGDB = null;
         IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();
         //判断是GDB文件还是普通文件夹
         string locationForm =DownLoadLocation.Substring(DownLoadLocation.Length - 4, 4).ToUpper();
         if (locationForm == ".GDB")
         {
              wsGDB = workspaceFactory.OpenFromFile(@"" + DownLoadLocation, 0);
         }
         else
         {
             IRasterWorkspace rasterWorkspace = SetRasterWorkspace(DownLoadLocation);
             wsGDB = (IWorkspace)rasterWorkspace;
         }               
         IMosaicWorkspaceExtensionHelper mosaicHelper = new  MosaicWorkspaceExtensionHelperClass();
         IMosaicWorkspaceExtension mosaicWs = mosaicHelper.FindExtension(workspaceDB);
         IMosaicDataset mosaic = mosaicWs.OpenMosaicDataset(RasterName);
         IFunctionRasterDataset functionDS = (IFunctionRasterDataset)mosaic;

         ISaveAs rasterSaveAs = (ISaveAs)functionDS;                
         if (locationForm == ".GDB")
         {
             rasterSaveAs.SaveAs(RasterName, wsGDB, "GDB");
         }
         else
         {                   
             rasterSaveAs.SaveAs(RasterName+".tif", wsGDB, "TIFF");
         }

         return true;
     }
     catch
     {
         return false;
     }
 }

最后

以上就是超级大侠为你收集整理的arcengine镶嵌数据集的基本操作(C#)的全部内容,希望文章能够帮你解决arcengine镶嵌数据集的基本操作(C#)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部