将栅格数据(IRasterDataset)直接保存到数据库中很常见,但是保存到栅格目录下就比较少见,好不容易才找到,在这里记录一下。
1 public void saveRasterDs2Catalog(IRasterDataset rasterDs, IRasterCatalog rasterCatalog) 2 { 3 //保存前先设置rasterCatalog的坐标系,不然保存的栅格数据坐标系为空 4 IRasterProps rProps = rasterDs.CreateDefaultRaster() as IRasterProps; 5 rasterCatalog.AlterRasterSpatialReference(rProps.SpatialReference); 6 7 IFeatureClass featureclass = rasterCatalog as IFeatureClass; 8 IFeature feature = featureclass.CreateFeature(); 9 10 IRasterValue rValue = new RasterValueClass(); 11 rValue.RasterDataset = rasterDs; 12 feature.set_Value(rasterCatalog.RasterFieldIndex, rValue); 13 //如果栅格目录里还有其他属性,也可以在这里设置 14 feature.Store(); 15 } 16 17 /// <summary> 18 /// 把一个文件夹里的栅格数据都保存到rastercatalog中 19 /// </summary> 20 /// <param name="propertySet">数据库的连接属性</param> 21 /// <param name="catalogName">rastercatalog的名称</param> 22 /// <param name="rasterFolder">包含有栅格数据的文件夹</param> 23 public void loadDir2Catalog(IPropertySet propertySet,String catalogName,String rasterFolder) 24 { 25 //IWorkspaceFactory wkspFactory = new SdeWorkspaceFactoryClass(); 26 //IWorkspace wksp = wkspFactory.Open(propertySet, 0); 27 //IRasterWorkspaceEx rasterWkspEx = wksp as IRasterWorkspaceEx; 28 //IRasterCatalog rasterCatalog = rasterWkspEx.OpenRasterCatalog(catalogName); 29 30 ITrackCancel pTrackCancel = new TrackCancel(); 31 IRasterCatalogLoader rCatalogLoader = new RasterCatalogLoaderClass(); 32 rCatalogLoader.ConnectionProperties = propertySet; 33 rCatalogLoader.Load(catalogName, rasterFolder, pTrackCancel); 34 }