/// <summary> /// 栅格保存为数据集(并创建金字塔) /// </summary> /// <param name="raster">栅格</param> /// <param name="outFile">输出文件</param> public static void SaveRasterAsDataset(IRaster raster, string outFile) { //文件已存在,则返回 if (File.Exists(outFile) || raster == null) { return; } IRasterBandCollection pRasBandCol = raster as IRasterBandCollection; if (pRasBandCol == null) { return; } string fileName = Path.GetFileName(outFile); IWorkspace workspace = RasterDataInfoClass.GetRasterWorkspace(outFile); //保存波段集合为数据集 IDataset dataset = pRasBandCol.SaveAs(fileName, workspace, "IMAGINE Image"); ITemporaryDataset pRsGeo = dataset as ITemporaryDataset; if (pRsGeo != null && pRsGeo.IsTemporary()) { pRsGeo.MakePermanent(); } RasterDataInfoClass.CreatePyramid(outFile); //创建金字塔 }
/// <summary> /// 复制获取临时栅格数据集 /// </summary> /// <param name="rasterLayerFile">栅格图层文件</param> /// <returns></returns> public static IRasterDataset CopyAsTempRasterDataset(string rasterLayerFile) { //复制原始栅格为临时栅格 string tempFile = TempFile.CreateNewTempFile(); CopyRasterLayer(rasterLayerFile, tempFile); return(RasterDataInfoClass.GetRasterDataset(tempFile)); }
/// <summary> /// 设置栅格分析环境的输出空间为临时文件夹 /// </summary> /// <param name="rasterAnalysisEnvironment">栅格分析环境</param> public static void SetRasterAnalysisOutWorkspace(IRasterAnalysisEnvironment rasterAnalysisEnvironment) { if (rasterAnalysisEnvironment == null) { return; } //获取临时目录 string finalTemPath = TempFile.CreateNewTempDirectory(); IWorkspace workspace = RasterDataInfoClass.GetRasterWorkspace(finalTemPath); //设置输出工作空间 rasterAnalysisEnvironment.OutWorkspace = workspace; }
/// <summary> /// 复制栅格图层 /// </summary> /// <param name="inFile">输入路径</param> /// <param name="outFile">输出路径</param> public static ILayer CopyRasterLayer(string inFile, string outFile) { IRasterDataset rasterDataset = RasterDataInfoClass.GetRasterDataset(inFile); return(DatasetHelper.CopyDatasetAsRasterLayer(rasterDataset as IDataset, outFile)); }
/// <summary> /// 建立默认属性表 /// </summary> /// <param name="rasterLayer"></param> private static void BuildRasterAttributeTable(IRasterLayer rasterLayer) { IRasterDataset rasterDataset = RasterDataInfoClass.GetRasterDataset(rasterLayer.FilePath); BuildRasterAttributeTable(rasterDataset); }