/// <summary> /// 获取操作的文件 /// </summary> /// <param name="inputFileName"></param> /// <param name="writeMode"></param> /// <param name="outputFileName"></param> /// <returns></returns> private void GetOperateFileName(string inputFileName, HDFWriteMode writeMode, string outputFileName) { //如果为另存模式 if (writeMode == HDFWriteMode.SaveAS) { if (string.IsNullOrEmpty(outputFileName)) { MessageBox.Show("输出文件不能为空", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!Directory.Exists(outputFileName.Substring(0, outputFileName.LastIndexOf(@"\")))) { Directory.CreateDirectory(outputFileName.Substring(0, outputFileName.LastIndexOf(@"\"))); } fileName = outputFileName; File.Copy(inputFileName, fileName, true); } else { //如果为覆盖模式 fileName = inputFileName.Substring(0, inputFileName.LastIndexOf('.')) + "_Cpoy" + inputFileName.Substring(inputFileName.LastIndexOf('.')); File.Copy(inputFileName, fileName, true); } }
/// <summary> /// HDF5数据去条带 /// </summary> /// <param name="mappingDataSet">数据集和波段号的映射关系</param> /// <param name="inputFileName">需要操作的文件</param> /// <param name="writeMode">操作模式</param> /// <param name="outputFileName">输出文件</param> public void RemoveLines(Dictionary <string, int> mappingDataSet, string inputFileName, HDFWriteMode writeMode, string outputFileName, Action <int, string> progressCallback) { if (mappingDataSet == null || mappingDataSet.Count == 0) { MessageBox.Show("缺少波段映射关系!"); return; } try { //获取将要处理的文件 GetOperateFileName(inputFileName, writeMode, outputFileName); if (string.IsNullOrEmpty(fileName)) { return; } float percent = (float)(1 / (float)mappingDataSet.Count); int progessIndex = 0; //打印进度 if (progressCallback != null) { progressCallback(0, "开始处理数据..."); } int bandWidth, bandHeight; enumDataType dataType; object data = null; foreach (KeyValuePair <string, int> dataSet in mappingDataSet) { //打印进度 if (progressCallback != null) { progressCallback(0, "正在处理数据..."); } ReadOldDataSetData(dataSet.Key, dataSet.Value, out bandWidth, out bandHeight, out dataType, out data); DoRemoveLineOperate(dataSet.Key, dataType, data, dataSet.Value, bandWidth, bandHeight, progessIndex, percent, progressCallback); progessIndex++; } if (writeMode == HDFWriteMode.ReWrite) { File.Copy(fileName, inputFileName, true); File.Delete(fileName); } } catch (Exception e) { } }
/// <summary> /// HDF5数据去条带 /// </summary> /// <param name="bandNo">指定波段号的数据集</param> /// <param name="inputFileName">需要操作的文件</param> /// <param name="writeMode">操作模式</param> /// <param name="outputFileName">输出文件</param> public void RemoveLines(int[] bandNo, string inputFileName, HDFWriteMode writeMode, string outputFileName, Action <int, string> progressCallback) { IRasterDataProvider prd = null; //获取将要处理的文件 GetOperateFileName(inputFileName, writeMode, outputFileName); if (bandNo == null || bandNo.Length == 0 || string.IsNullOrEmpty(fileName)) { return; } try { List <Dictionary <string, int> > count = new List <Dictionary <string, int> >(); for (int i = 0; i < bandNo.Length; i++) { count.Add(GetMappingInfo(bandNo[i])); } if (count == null || count.Count == 0) { MessageBox.Show("缺少波段对应关系!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } float percent = (float)(1 / (float)count.Count); int progessIndex = 0; //打印进度 if (progressCallback != null) { progressCallback(0, "开始处理数据..."); } //获取波段提供者 //progessIndex++; prd = GetRasDataProvide(inputFileName); if (prd == null) { MessageBox.Show("错误文件!"); return; } for (int i = 0; i < bandNo.Length; i++) { //获取指定波段号的波段信息 IRasterBand band = prd.GetRasterBand(bandNo[i]); //获取波段的数据 object data = ReadOldBrandData(band, prd.DataType); //读取映射波段对应的数据集名称 Dictionary <string, int> mappingDataSet = GetMappingInfo(bandNo[i]); //int bandIndex = 0; foreach (KeyValuePair <string, int> dataSet in mappingDataSet) { DoRemoveLineOperate(dataSet.Key, prd.DataType, data, dataSet.Value, band.Width, band.Height, progessIndex, percent, progressCallback); progessIndex++; } } if (progressCallback != null) { progressCallback(100, "数据处理完毕!"); } if (writeMode == HDFWriteMode.ReWrite) { File.Copy(fileName, inputFileName, true); File.Delete(fileName); } MessageBox.Show("处理成功!"); } catch (Exception e) { throw new Exception(e.Message); } finally { prd.Dispose(); } }