码迷,mamicode.com
首页 > 数据库 > 详细

Geodatabase - 打开栅格数据

时间:2014-10-31 06:23:36      阅读:296      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   ar   使用   sp   strong   文件   数据   

打开栅格数据

  和打开要素类的方式类似,打开栅格数据集需要用 IRasterWorkspace,如

 1 //获得栅格工作空间(普通目录).
 2         public ESRI.ArcGIS.DataSourcesRaster.IRasterWorkspace GetRasterWorkspace(string rasterWorkspacePath) {
 3             ESRI.ArcGIS.Geodatabase.IWorkspaceFactory wsf = new ESRI.ArcGIS.DataSourcesRaster.RasterWorkspaceFactoryClass();    //使用RasterWorkspaceFactoryClass.
 4             ESRI.ArcGIS.Geodatabase.IWorkspace ws = wsf.OpenFromFile(rasterWorkspacePath, 0);
 5             ESRI.ArcGIS.DataSourcesRaster.IRasterWorkspace rws = (ESRI.ArcGIS.DataSourcesRaster.IRasterWorkspace)ws;
 6             return rws;
 7         }
 8 
 9         /// <summary>
10         /// 打开栅格数据集(普通目录).
11         /// </summary>
12         /// <param name="foldName">目录名称(普通目录),如,foldName="G:\doc\gis\1.400\data\raster".</param>
13         /// <param name="fileName">栅格数据集的名称,如fileName="srtm_58_09.tif"</param>
14         /// <returns></returns>
15         public ESRI.ArcGIS.Geodatabase.IRasterDataset OpenRasterDataset(string foldName, string fileName) {
16             ESRI.ArcGIS.DataSourcesRaster.IRasterWorkspace rws = GetRasterWorkspace(foldName);
17             return rws.OpenRasterDataset(fileName);
18         }
19 
20         //获得栅格工作空间(数据库中).
21         //如rasterWorkspaceExPath="G:\doc\gis\1.400\data\pdb.mdb"
22         public ESRI.ArcGIS.Geodatabase.IRasterWorkspaceEx GetRasterWorkspaceEx(string rasterWorkspaceExPath) {
23             ESRI.ArcGIS.Geodatabase.IWorkspaceFactory wsf = new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass();   //使用专门数据库.
24             ESRI.ArcGIS.Geodatabase.IWorkspace ws = wsf.OpenFromFile(rasterWorkspaceExPath, 0);
25             ESRI.ArcGIS.Geodatabase.IRasterWorkspaceEx rwsEx = (ESRI.ArcGIS.Geodatabase.IRasterWorkspaceEx)ws;
26             return rwsEx;
27         }
28 
29         /// <summary>
30         /// 打开栅格数据集(数据库中)
31         /// </summary>
32         /// <param name="rasterWorkspaceEx"></param>
33         /// <param name="rasterDatasetName">栅格数据集名称,如"rds"</param>
34         /// <returns></returns>
35         public ESRI.ArcGIS.Geodatabase.IRasterDataset OpenRasterDataset(ESRI.ArcGIS.Geodatabase.IRasterWorkspaceEx rasterWorkspaceEx, string rasterDatasetName) {
36             return rasterWorkspaceEx.OpenRasterDataset(rasterDatasetName);
37         }

 

需要指出的是,当我们的数据是存储在SDE数据库,FileGeodatabase或PersonalGeodatabase时,要用IRasterWorkspaceEx,而不是IRasterWorkspace.

IRasterWorkspace与IRasterWorkspaceEx的区别

    1)IRasterWorkspace主要是用来读取以文件格式存储在本地的栅格数据.

    2)IRasteWorkspaceEx接口主要是用来读取GeoDatabase中的栅格数据集和栅格目录.

 

打开栅格目录

  打开栅格目录需要用IRasterWorkspaceEx,可以从以上(打开栅格数据集的第20~27行获取IRasterWorkspaceEx对象,然后通过OpenRasterCatalog获取.如

1 /// <summary>
2         /// 打开栅格目录.
3         /// </summary>
4         /// <param name="rasterWorkspaceEx"></param>
5         /// <param name="rasterCatalogName">栅格目录名,如rasterCatalogName="r_catalog"</param>
6         /// <returns></returns>
7         public ESRI.ArcGIS.Geodatabase.IRasterCatalog OpenRasterCatalog(ESRI.ArcGIS.Geodatabase.IRasterWorkspaceEx rasterWorkspaceEx, string rasterCatalogName) {
8             return rasterWorkspaceEx.OpenRasterCatalog(rasterCatalogName);
9         }

 打开栅格目录中的数据

1 //打开栅格目录中的数据.
2         ESRI.ArcGIS.Geodatabase.IRasterDataset GetRasterCatalogItem(ESRI.ArcGIS.Geodatabase.IRasterCatalog rasterCatalog, int objectId) {
3             ESRI.ArcGIS.Geodatabase.IFeatureClass fc = (ESRI.ArcGIS.Geodatabase.IFeatureClass)rasterCatalog;
4             ESRI.ArcGIS.Geodatabase.IRasterCatalogItem rCataItem = (ESRI.ArcGIS.Geodatabase.IRasterCatalogItem)fc.GetFeature(objectId);
5             return rCataItem.RasterDataset;
6         }

 

Geodatabase - 打开栅格数据

标签:style   blog   color   ar   使用   sp   strong   文件   数据   

原文地址:http://www.cnblogs.com/listened/p/4064131.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!