private void CalcMinMax() { double pdfMin = 0; double pdfMax = 0; try { _progress.Reset("正在统计端值...", 100); _progress.Start(false); IRasterBand band = _drawing.DataProviderCopy.GetRasterBand(_selectBand); band.ComputeMinMax(out pdfMin, out pdfMax, false, (idx, tip) => { _progress.Boost(idx); }); } finally { _progress.Finish(); } this.txtMin.Text = Math.Round(pdfMin, 2).ToString(); this.txtMax.Text = Math.Round(pdfMax, 2).ToString(); if (StringToNumberHelper.isFloatPointNumber(txtMin.Text) || StringToNumberHelper.isFloatPointNumber(txtMax.Text)) { _intervalType = IntervalType.FloatType; } else { _intervalType = IntervalType.IntType; } _min_value = (int)pdfMin; _max_value = (int)pdfMax; _minValue = (float)Math.Round(pdfMin, 2); _maxValue = (float)Math.Round(pdfMax, 2); }
private void DoBandMath(IRasterDrawing drawing, string outFilename, string expression) { string extName = Path.GetExtension(outFilename).Replace(",", "").ToUpper(); if (extName == ".DAT") { extName = "MEM"; } else { extName = "LDF"; } IBandMathTool bandMathTool = new BandMathTool(); IProgressMonitor progress = _smartSession.ProgressMonitorManager.DefaultProgressMonitor; try { progress.Reset("正在执行波段运算...", 100); progress.Start(false); bandMathTool.Compute(drawing.DataProviderCopy, expression, extName, outFilename, (idx, tip) => { progress.Boost(idx, "正在执行波段运算..."); }); } finally { progress.Finish(); //if (MsgBox.ShowQuestionYesNo("波段运算已输出文件\"" + outFilename + "\",要打开文件吗?") == System.Windows.Forms.DialogResult.Yes) { OpenFileFactory.Open(outFilename); } } }
private void DoStat(IRasterDataProvider dataProvider, int[] bandNos, int[] aoi) { Dictionary <int, RasterQuickStatResult> results; IProgressMonitor progress = _smartSession.ProgressMonitorManager.DefaultProgressMonitor; try { progress.Reset("正在执行直方图统计...", 100); progress.Start(false); IRasterQuickStatTool stat = new RasterQuickStatTool(); results = stat.Compute(dataProvider, aoi, bandNos, (idx, tip) => { progress.Boost(idx, "正在执行直方图统计..."); }); } finally { progress.Finish(); } /*using (*/ frmRasterQuickStat frm = new frmRasterQuickStat();//) { frm.Owner = _smartSession.SmartWindowManager.MainForm as Form; frm.StartPosition = FormStartPosition.CenterScreen; frm.Apply(dataProvider.fileName, results); frm.Show(); } }
private void OnProgress(int progerss, string text) { if (_progressMonitor != null) { _progressMonitor.Boost(progerss, text); } }
public object[] GetStretcher(IRasterDataProvider dataProvider, int[] bandNos, float percent) { int[] bNos = bandNos.Distinct().ToArray(); Dictionary <int, RasterQuickStatResult> results; IProgressMonitor progress = _smartSession.ProgressMonitorManager.DefaultProgressMonitor; try { progress.Reset("正在执行直方图统计...", 100); progress.Start(false); IRasterQuickStatTool stat = new RasterQuickStatTool(); results = stat.Compute(dataProvider, null, bNos, (idx, tip) => { progress.Boost(idx, "正在执行直方图统计..."); }); } finally { progress.Finish(); } RasterQuickStatResult[] rts = new RasterQuickStatResult[bandNos.Length]; for (int i = 0; i < bandNos.Length; i++) { rts[i] = results[bandNos[i]]; } // object[] stretchers = GetStretcher(dataProvider.DataType, rts, percent); return(stretchers); }
private unsafe void TryExport2ShapeFile(IRasterDataProvider dataProvider, ContourLine[] cntLines, string shpFileName, IProgressMonitor progress, bool isNeedDisplay) { int cntCount = cntLines.Length; string tip = "正在将等值线导出为矢量文件({0}/{1})..."; progress.Reset("正在将等值线导出为矢量文件...", cntLines.Length); IEsriShapeFilesWriter writer = new EsriShapeFilesWriterII(shpFileName, enumShapeType.Polyline); writer.BeginWrite(); try { double resX = dataProvider.CoordEnvelope.Width / dataProvider.Width; double resY = dataProvider.CoordEnvelope.Height / dataProvider.Height; double minX = dataProvider.CoordEnvelope.MinX; double maxY = dataProvider.CoordEnvelope.MaxY; Feature[] buffer = new Feature[1]; for (int i = 0; i < cntCount; i++) { if (cntLines[i] == null) { continue; } Feature fet = GetFeature(cntLines[i], resX, resY, minX, maxY, i); if (fet != null) { buffer[0] = fet; writer.Write(buffer); } progress.Boost(i, string.Format(tip, i + 1, cntCount)); } } finally { writer.EndWriter(); progress.Boost(cntCount); //没有直接显示则打开矢量文件 if (!isNeedDisplay) { if (MsgBox.ShowQuestionYesNo("是否打开矢量文件\"" + shpFileName + "\"?") == DialogResult.Yes) { OpenFileFactory.Open(shpFileName); } } } }
public override void Execute() { //Test(); //return; IRasterDataProvider dataProvider = null; bool isNew = false; int[] bandNos = null; int[] aoi = GetAOI(); using (frmScatterVarSelector frm = new frmScatterVarSelector()) { frm.StartPosition = FormStartPosition.CenterScreen; frm.Apply(GetCurrentDataProvider(), aoi); if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { dataProvider = frm.DataProvider; bandNos = new int[] { frm.XBandNo, frm.YBandNo }; isNew = frm.IsNewDataProvider; aoi = frm.AOI; } } if (bandNos == null || dataProvider == null) { return; } // IProgressMonitor progress = _smartSession.ProgressMonitorManager.DefaultProgressMonitor; try { progress.Reset("正在准备生成散点图...", 100); progress.Start(false); frmScatterGraph frm1 = new frmScatterGraph(); frm1.Owner = _smartSession.SmartWindowManager.MainForm as Form; frm1.StartPosition = FormStartPosition.CenterScreen; LinearFitObject fitObj = new LinearFitObject(); frm1.Reset(dataProvider, bandNos[0], bandNos[1], aoi, fitObj, (idx, tip) => { progress.Boost(idx, "正在准备生成散点图..."); } ); progress.Finish(); frm1.Show(); frm1.Rerender(); frm1.FormClosed += new FormClosedEventHandler((obj, e) => { if (isNew) { dataProvider.Dispose(); } }); } finally { progress.Finish(); } }
public override void Execute(string argument) { ICanvasViewer viewer = _smartSession.SmartWindowManager.ActiveCanvasViewer; if (viewer == null) { return; } IRasterDrawing drawing = viewer.ActiveObject as IRasterDrawing; if (drawing.TileBitmapProvider.TileCountOfLoading > 0) { return; } if (drawing.SelectedBandNos.Length > 1) { MsgBox.ShowInfo("当前影像显示为RGB合成模式,系统将自动调整为灰度显示模式!"); drawing.SelectedBandNos = new int[] { drawing.SelectedBandNos[0] }; } IProgressMonitor progress = _smartSession.ProgressMonitorManager.DefaultProgressMonitor; try { progress.Reset("正在统计端值...", 100); progress.Start(false); if (drawing.TileBitmapProvider.TileCountOfLoading > 0) { return; } IRasterBand band = drawing.DataProviderCopy.GetRasterBand(drawing.SelectedBandNos[0]); band.ComputeMinMax(out _bandMinValue, out _bandMaxValue, false, (idx, tip) => { progress.Boost(idx); }); } finally { progress.Finish(); } using (frmColorRampEditor frm = new frmColorRampEditor()) { frm.MinLimitValue = int.MinValue; frm.MaxLimitValue = int.MaxValue; //frm.OnStatMinValueAndMaxValue += new frmColorRampEditor.StatMinValueAndMaxValueHandler(frm_OnStatMinValueAndMaxValue); frm.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Color[] Colors = frm.ComputeColors(200); ApplyColorItems(Colors); } } }
private void btnExtract_Click(object sender, EventArgs e) { IMonitoringSubProduct subProduct = GetCurrentSubProduct(); if (subProduct == null) { return; } IContextMessage msg = _session.SmartWindowManager.SmartToolWindowFactory.GetSmartToolWindow(9006) as IContextMessage; SetAOIArgument(subProduct); IProgressMonitor tracker = _session.ProgressMonitorManager.DefaultProgressMonitor; IExtractResult result = null; try { subProduct.ArgumentProvider.SetArg("SmartSession", _session); //不能在这里设置SelectedPrimaryFiles参数,会将界面上设置好参数值的覆盖掉。 //TrySetSelectedPrimaryFilesArgs(_session, subProduct); tracker.Start(false); tracker.Reset("正在生成...", 100); result = subProduct.Make((pro, tip) => { if (tracker != null) { tracker.Boost(pro, tip); } }, msg); if (result == null) { _isNullResult = true; return; } } finally { tracker.Finish(); } if (!(result is IPixelIndexMapper) && !(result is IExtractResultArray)) { _isAutoSave = false; } if (result is IExtractResultArray) { SetIsAutoSave(result as IExtractResultArray); } DisplayResultClass.DisplayResult(_session, subProduct, result, true); }
private void btnOk_Click(object sender, EventArgs e) { string inputFileName = txtFileDir.Text; string outputFileName = txtOutDir.Text; if (string.IsNullOrWhiteSpace(inputFileName) || string.IsNullOrWhiteSpace(outputFileName)) { MessageBox.Show("输入文件、输出文件不能为空", "提示"); return; } int[] bandNos = GetInputBandNos(); if (bandNos == null) { MessageBox.Show("波段信息输入有误,请输入待处理的波段,如 5或5,6", "提示"); return; } string errBandNo = string.Empty; if (!CheckBand(inputFileName, bandNos, out errBandNo)) { MessageBox.Show("文件中不包含第" + errBandNo + "波段"); return; } IHDF5RemoveLines opt = new HDF5RemoveLines(); IProgressMonitor progress = _smartSession.ProgressMonitorManager.DefaultProgressMonitor; try { progress.Reset("获取文件信息...", 100); progress.Start(false); opt.RemoveLines(bandNos, inputFileName, HDFWriteMode.SaveAS, outputFileName, (idx, tip) => { progress.Boost(idx, tip); }); } catch (Exception ex) { MessageBox.Show("处理失败!" + ex.Message); } finally { progress.Finish(); Close(); } }
private string MoasicFiles(string[] srcFiles, bool processInvaild, string[] invaildValues, string outDir, CoordEnvelope outCoordEnvelope, int[] selectedBands, IProgressMonitor progress) { try { if (File.Exists(outDir)) { GetFilename(outDir); } int count = srcFiles.Length; IRasterDataProvider[] srcRaster = new IRasterDataProvider[count]; for (int i = 0; i < count; i++) { IRasterDataProvider src = GeoDataDriver.Open(srcFiles[i]) as IRasterDataProvider; srcRaster[i] = src; } if (progress != null) { progress.Reset("", 100); progress.Start(false); } RasterMoasicProcesser processer = new RasterMoasicProcesser(); IRasterDataProvider dstRaster = processer.Moasic(srcRaster, selectedBands, "LDF", outDir, outCoordEnvelope, srcRaster[0].ResolutionX, srcRaster[0].ResolutionY, processInvaild, invaildValues, new Action <int, string>((int progerss, string text) => { if (progress != null) { progress.Boost(progerss, text); } })); string dstFileName = dstRaster.fileName; for (int i = 0; i < count; i++) { if (srcRaster[i] != null) { srcRaster[i].Dispose(); } } dstRaster.Dispose(); return(dstFileName); } finally { if (progress != null) { progress.Finish(); } } }
private void Project(string fileName, ISpatialReference proj) { string errorMsg; string[] outFiles = null; Action <int, string> progress = new Action <int, string>(OnProgress); ProjectionFactory quick = new ProjectionFactory(); try { _progressMonitor = _smartSession.ProgressMonitorManager.DefaultProgressMonitor; if (_progressMonitor != null) { _progressMonitor.Reset("", 100); _progressMonitor.Start(false); _progressMonitor.Boost(0, "准备文件"); } PrjOutArg prjOutArg = new PrjOutArg(proj, null, 0, 0, Path.GetDirectoryName(fileName)); outFiles = quick.Project(fileName, prjOutArg, progress, out errorMsg); } finally { if (_progressMonitor != null) { _progressMonitor.Finish(); } progress = null; } if (outFiles != null && outFiles.Length != 0) { for (int i = 0; i < outFiles.Length; i++) { if (!string.IsNullOrWhiteSpace(outFiles[i])) { OpenFileToWindows(outFiles[i]); } } } if (errorMsg != null && errorMsg.Length != 0) { MsgBox.ShowInfo(errorMsg); } }
private void DoGenerateContourLines(IRasterDataProvider dataProvider, bool isNew, int bandNo, int[] aoi, frmContourSettings.ContourItem[] contourItems, bool isNeedDisplay, bool isNeedLabel, bool isNeedFillColor, int sample, string shpFileName) { try { IProgressMonitor progress = _smartSession.ProgressMonitorManager.DefaultProgressMonitor; try { progress.Reset("正在生成等值线...", 100); progress.Start(false); IContourGenerateTool tool = new ContourGenerateTool(); tool.Sample = sample; double[] cvs = ToContourValues(contourItems); ContourLine[] cntLines = tool.Generate(dataProvider.GetRasterBand(bandNo), cvs, aoi, (idx, tip) => { progress.Boost(idx, tip); }); if (cntLines == null || cntLines.Length == 0) { MsgBox.ShowInfo("不存在符合指定条件的等值线!"); return; } if (shpFileName != null) { TryExport2ShapeFile(dataProvider, cntLines, shpFileName, progress, isNeedDisplay); } if (isNeedDisplay) { TryDisplay(cntLines, contourItems, isNeedLabel, isNeedFillColor, isNew, dataProvider); } } finally { progress.Finish(); } } finally { if (isNew && !isNeedDisplay) { dataProvider.Dispose(); } } }
private string MoasicFiles(List <string> srcFiles, bool processInvaild, string[] invaildValues, string outDir, IProgressMonitor progress) { try { int count = srcFiles.Count; IRasterDataProvider[] srcRaster = new IRasterDataProvider[count]; for (int i = 0; i < count; i++) { IRasterDataProvider src = GeoDataDriver.Open(srcFiles[i]) as IRasterDataProvider; srcRaster[i] = src; } if (progress != null) { progress.Reset("", 100); progress.Start(false); } RasterMoasicProcesser processer = new RasterMoasicProcesser(); IRasterDataProvider dstRaster = processer.Moasic(srcRaster, "LDF", outDir, processInvaild, invaildValues, new Action <int, string>((int progerss, string text) => { if (progress != null) { progress.Boost(progerss, text); } })); string dstFileName = dstRaster.fileName; for (int i = 0; i < count; i++) { srcRaster[i].Dispose(); } dstRaster.Dispose(); return(dstFileName); } finally { if (progress != null) { progress.Finish(); } } }
public override void Execute(string argument) { if (argument == null) { return; } IRasterDataProvider prd = null; try { prd = GeoDataDriver.Open(argument) as IRasterDataProvider; } catch (Exception ex) { ExceptionHandler.ShowExceptionWnd(ex, "为文件\"" + Path.GetFileName(argument) + "\"创建金字塔失败!"); return; } if (prd == null) { return; } if (prd.IsSupprtOverviews) { IProgressMonitor progress = _smartSession.ProgressMonitorManager.DefaultProgressMonitor; try { string tip = "正在建立金字塔\"" + Path.GetFileName(argument) + "\"..."; progress.Reset(tip, 100); progress.Start(false); prd.BuildOverviews((idx, tipo) => { progress.Boost(idx, tip); }); } finally { progress.Finish(); } } }
private void GeoCorrect_Click(object sender, EventArgs e) { if (_listGCP.Count < 3) { MessageBox.Show("请至少选择3个控制点!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (_baseDataControl.GetSpatialRef() == null) { MessageBox.Show("基准数据没有地理坐标!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (File.Exists(OutPath.Text)) { DialogResult dlgResult = MessageBox.Show("输出文件已存在,是否替换?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlgResult == DialogResult.No) { return; } } CalGeoCoef calCoef = new CalGeoCoef(); double[] imgX = new double[_listGCP.Count]; double[] imgY = new double[_listGCP.Count]; double[] baseX = new double[_listGCP.Count]; double[] baseY = new double[_listGCP.Count]; for (int i = 0; i < _listGCP.Count; i++) { imgX[i] = _listGCP[i].ImagePoint.X; imgY[i] = _listGCP[i].ImagePoint.Y; baseX[i] = _listGCP[i].BasePoint.X; baseY[i] = _listGCP[i].BasePoint.Y; } IProgressMonitor progress = _smartSession.ProgressMonitorManager.DefaultProgressMonitor; try { if (progress != null) { progress.Reset("", 100); progress.Start(false); } int coordType = 0; int imgType = _imageControl.GetCoordType(); int baseType = _baseDataControl.GetCoordType(); if ((imgType == 0) && (baseType == 0)) { coordType = 0; } else if ((imgType == 0) && (baseType == 1)) { coordType = 1; } else if ((imgType == 0) && (baseType == 2)) { coordType = 2; } else if ((imgType == 1) && (baseType == 0)) { coordType = 3; } else if ((imgType == 1) && (baseType == 1)) { coordType = 4; } else if ((imgType == 1) && (baseType == 2)) { coordType = 5; } else if ((imgType == 2) && (baseType == 0)) { coordType = 6; } else if ((imgType == 2) && (baseType == 1)) { coordType = 7; } else if ((imgType == 2) && (baseType == 2)) { coordType = 8; } string spatialRef = _baseDataControl.GetSpatialRef().ToProj4String(); if (_listGCP.Count >= 6) { double[] coefX = new double[6]; double[] coefY = new double[6]; double[] RcoefX = new double[6]; double[] RcoefY = new double[6]; calCoef.PolyCoef2(baseX, baseY, imgX, imgY, _listGCP.Count, out coefX, out coefY); calCoef.PolyCoef2(imgX, imgY, baseX, baseY, _listGCP.Count, out RcoefX, out RcoefY); PolyCorrection polyCorrect = new PolyCorrection(); polyCorrect.PolyOrder = 2; polyCorrect.DoPolyCorrection(_imageControl.RasterName, OutPath.Text, coordType, coefX, coefY, RcoefX, RcoefY, spatialRef, "LDF", new Action <int, string>((int progerss, string text) => { if (progress != null) { progress.Boost(progerss, text); } })); } else { double[] coefX = new double[3]; double[] coefY = new double[3]; double[] RcoefX = new double[3]; double[] RcoefY = new double[3]; //imgX[0] = 13.0; //imgX[1] = 116.0; //imgX[2] = 228.0; //imgY[0] = 13.0; //imgY[1] = 132.0; //imgY[2] = 241.0; //baseX[0] = 119.515789; //baseX[1] = 120.036845; //baseX[2] = 120.612091; //baseY[0] = 39.099891; //baseY[1] = 38.556071; //baseY[2] = 38.085306; calCoef.PolyCoef1(baseX, baseY, imgX, imgY, _listGCP.Count, out coefX, out coefY); calCoef.PolyCoef1(imgX, imgY, baseX, baseY, _listGCP.Count, out RcoefX, out RcoefY); PolyCorrection polyCorrect = new PolyCorrection(); polyCorrect.PolyOrder = 1; polyCorrect.DoPolyCorrection(_imageControl.RasterName, OutPath.Text, coordType, coefX, coefY, RcoefX, RcoefY, spatialRef, "LDF", new Action <int, string>((int progerss, string text) => { if (progress != null) { progress.Boost(progerss, text); } })); } } finally { if (progress != null) { progress.Finish(); } } string strText = "几何精校正处理完成,是否打开输出影像" + Path.GetFileName(OutPath.Text) + "?"; DialogResult result = MessageBox.Show(strText, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == System.Windows.Forms.DialogResult.Yes) { OpenFileFactory.Open(OutPath.Text); } }
//根据文件名提取区域标识,限定专题图输出数据范围。一般用于制作网络图。 public static IExtractResult CreateThemeGraphyBase(ISmartSession session, string algorithmName, string outFileIdentify, string colorTableName, string dataIdentify, string templateName, bool isCustom, bool multiSelect, bool isUseRegion, int genralAndTheme) { IMonitoringSubProduct msp = (session.MonitoringSession as IMonitoringSession).ActiveMonitoringSubProduct; if (msp == null) { return(null); } string[] files = null; CoordEnvelope customEnv = null; if (genralAndTheme == 0) { object obj = msp.ArgumentProvider.GetArg("SelectedPrimaryFiles"); if (!SetSelectedPrimaryFiles(session, ref obj, msp.ArgumentProvider, algorithmName)) { return(null); } files = obj as string[]; if (files == null || files.Length == 0) { if (File.Exists(obj.ToString())) { files = new string[] { obj.ToString() } } ; else { return(null); } } //by chennan 20130319 根据需要查找相应文件 UpdateFilesByDataIdentify(ref files, dataIdentify); //添加对生成专题图文件类型的判断,排除生成的专题图和统计结果文件,add by wangyu,20120923 foreach (string fname in files) { CanCreatThemegraph(fname); } msp.ArgumentProvider.SetArg("SelectedPrimaryFiles", files); if (isCustom && !SetAOIArugment(files, msp, multiSelect, out customEnv))//用户自定义区域 { return(null); } else if (!isCustom) { msp.ArgumentProvider.SetArg("AOI", null); } } IThemeGraphGenerator tgg = new GeoDo.RSS.MIF.Prds.Comm.CmaThemeGraphGenerator(session); msp.ArgumentProvider.SetArg("ThemeGraphyGenerator", tgg); msp.ArgumentProvider.SetArg("OutFileIdentify", outFileIdentify); msp.ArgumentProvider.SetArg("ThemeGraphTemplateName", templateName); if (customEnv != null) { RasterProject.PrjEnvelope prjEnvelope = new RasterProject.PrjEnvelope(customEnv.MinX, customEnv.MaxX, customEnv.MinY, customEnv.MaxY); msp.ArgumentProvider.SetArg("UseRegion", prjEnvelope); } else if (isUseRegion)// 换为字符串,为区域定义分组名称regionGroupName,为空代表不指定区域。 { RasterIdentify rstId = new RasterIdentify(files[0]); if (!string.IsNullOrWhiteSpace(rstId.RegionIdentify)) { DefinedRegionParse reg = new DefinedRegionParse(); BlockItemGroup blockGroup = reg.BlockDefined.FindGroup("积雪"); PrjEnvelopeItem envItem = blockGroup.GetPrjEnvelopeItem(rstId.RegionIdentify); if (envItem != null) { RasterProject.PrjEnvelope prjEnvelope = RasterProject.PrjEnvelope.CreateByCenter(envItem.PrjEnvelope.CenterX, envItem.PrjEnvelope.CenterY, 10, 10); msp.ArgumentProvider.SetArg("UseRegion", prjEnvelope); } } } if (!string.IsNullOrEmpty(colorTableName)) { msp.ArgumentProvider.SetArg("colortablename", "colortablename=" + colorTableName); } IProgressMonitor tracker = null; Action <int, string> progress = null; try { tracker = session.ProgressMonitorManager.DefaultProgressMonitor; if (tracker != null) { tracker.Start(false); tracker.Reset("正在生成...", 100); progress = (p, txt) => { tracker.Boost(p, txt); }; } IExtractResult result = msp.Make(progress); DisplayResultClass.DisplayResult(session, msp, result, false); return(result); } finally { if (tracker != null) { tracker.Finish(); } } }
/// <summary> /// /// </summary> /// <param name="argument"> /// 格式"*#*"冒号前面部分表示文件名称,冒号后面部分表示所选投影坐标的Wkt格式字符串 /// </param> public override void Execute(string argument) { try { string fileName = ""; string prjString = ""; ISpatialReference proj = null; if (string.IsNullOrWhiteSpace(argument)) { fileName = TryGetFileFromActiveView(); proj = SpatialReference.GetDefault(); } else { MatchCollection matches = Regex.Matches(argument, @"(?<file>[^#]*)#(?<proj>.*)"); fileName = matches[0].Groups["file"].Value; prjString = matches[0].Groups["proj"].Value; if (string.IsNullOrWhiteSpace(fileName) || fileName.ToLower() == "null") { fileName = TryGetFileFromActiveView(); } if (string.IsNullOrWhiteSpace(prjString) || prjString.ToLower() == "null") { proj = SpatialReference.GetDefault(); } else { proj = SpatialReference.FromWkt(prjString, enumWKTSource.EsriPrjFile); } } if (string.IsNullOrWhiteSpace(fileName)) { throw new Exception("无法从参数中解析出文件名:" + argument); } IProgressMonitor progress = _smartSession.ProgressMonitorManager.DefaultProgressMonitor; ProjectionFactory quick = new ProjectionFactory(); string errorMsg; string[] outFiles = null; try { _progressMonitor = _smartSession.ProgressMonitorManager.DefaultProgressMonitor; if (_progressMonitor != null) { _progressMonitor.Reset("", 100); _progressMonitor.Start(false); _progressMonitor.Boost(0, "准备文件"); } PrjOutArg prjOutArg = new PrjOutArg(proj, null, 0, 0, Path.GetDirectoryName(fileName)); outFiles = quick.Project(fileName, prjOutArg, new Action <int, string>(OnProgress), out errorMsg); } finally { if (_progressMonitor != null) { _progressMonitor.Finish(); } } if (outFiles != null && outFiles.Length != 0) { for (int i = 0; i < outFiles.Length; i++) { if (!string.IsNullOrWhiteSpace(outFiles[i])) { OpenFileToWindows(outFiles[i]); } } } if (errorMsg != null && errorMsg.Length != 0) { MsgBox.ShowInfo(errorMsg); } } catch (Exception ex) { MessageBox.Show(ex.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public string[] RasterClipT(string infName, BlockDef[] blocks, string outDir, IProgressMonitor progress, string type) { IRasterDataProvider prd = GeoDataDriver.Open(infName) as IRasterDataProvider; try { if (progress != null) { progress.Reset("", 100); progress.Start(false); } if (type.Equals("Clip")) { RasterClipProcesser clip = new RasterClipProcesser(); IRasterDataProvider[] outs = null; if (prd is IMemoryRasterDataProvider) { outs = clip.Clip(prd, blocks, 100, "MEM", outDir, new Action <int, string>((int progerss, string text) => { if (progress != null) { progress.Boost(progerss, text); } })); } else { outs = clip.Clip(prd, blocks, 100, "LDF", outDir, new Action <int, string>((int progerss, string text) => { if (progress != null) { progress.Boost(progerss, text); } })); } List <string> files = new List <string>(); for (int i = 0; i < outs.Length; i++) { if (outs[i] != null) { files.Add(outs[i].fileName); outs[i].Dispose(); } } return(files.ToArray()); } else if (type.Equals("Cut")) { RasterCutProcesser cut = new RasterCutProcesser(); IRasterDataProvider result = null; if (prd is IMemoryRasterDataProvider) { result = cut.Cut(prd, blocks[0] as BlockDefWithAOI, 100, "MEM", outDir, new Action <int, string>((int progerss, string text) => { if (progress != null) { progress.Boost(progerss, text); } })); } else { result = cut.Cut(prd, blocks[0] as BlockDefWithAOI, 100, "LDF", outDir, new Action <int, string>((int progerss, string text) => { if (progress != null) { progress.Boost(progerss, text); } })); } List <string> files = new List <string>(); if (result != null) { files.Add(result.fileName); } return(files.ToArray()); } else { return(null); } } finally { if (progress != null) { progress.Finish(); } } }
public override void Execute(string argument) { //判断当前视图中显示的数据,如果没有点状矢量数据,则返回 ICanvasViewer viewer = _smartSession.SmartWindowManager.ActiveCanvasViewer; if (viewer == null) { return; } ICanvas canvas = viewer.Canvas; if (canvas == null) { return; } IVectorHostLayer vectorHost = canvas.LayerContainer.VectorHost; if (vectorHost == null) { return; } Map map = vectorHost.Map as Map; if (map == null) { return; } CodeCell.AgileMap.Core.ILayer[] layers = map.LayerContainer.Layers; if (layers == null || layers.Length == 0) { return; } CodeCell.AgileMap.Core.FeatureLayer fetL = null; CodeCell.AgileMap.Core.FeatureClass fetc = null; int nCount = 0; for (nCount = 0; nCount < layers.Length; nCount++) { fetL = map.LayerContainer.Layers[nCount] as CodeCell.AgileMap.Core.FeatureLayer; fetc = fetL.Class as CodeCell.AgileMap.Core.FeatureClass; if (fetc.ShapeType == enumShapeType.Point) { break; } } if (nCount == layers.Length) { MessageBox.Show("视图中未显示点状矢量数据!", "系统消息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Feature[] features = fetc.GetVectorFeatures(); if (features == null || features.Length == 0) { return; } string fileName = null; IDataSource ds = fetc.DataSource as FileDataSource; if (ds != null) { fileName = (ds as FileDataSource).FileUrl; } if (ds == null) { ds = fetc.DataSource as MemoryDataSource; if (ds != null) { fileName = (ds as MemoryDataSource).Name; } } int featureCount = features.Count(); int fieldCount = fetc.FieldNames.Count(); //取出矢量数据中的字段值 Dictionary <string, ArrayList> dicFieldValues = new Dictionary <string, ArrayList>(); for (int i = 0; i < fieldCount; i++) { ArrayList fieldValues = new ArrayList(); for (int j = 0; j < featureCount; j++) { fieldValues.Add(features[j].FieldValues[i]); } dicFieldValues.Add(fetc.FieldNames[i], fieldValues); } for (int i = 0; i < fieldCount; i++) { double temp; if (double.TryParse(features[0].FieldValues[i], out temp)) { } else { dicFieldValues.Remove(features[0].FieldNames[i]); } } //计算矢量数据坐标范围和插值后默认的分辨率大小 double coordXmin, coordXmax, coordYmin, coordYmax; canvas.CoordTransform.Prj2Geo(fetc.FullEnvelope.MinX, fetc.FullEnvelope.MinY, out coordXmin, out coordYmin); canvas.CoordTransform.Prj2Geo(fetc.FullEnvelope.MaxX, fetc.FullEnvelope.MaxY, out coordXmax, out coordYmax); coordXmin = Math.Min(coordXmin, coordXmax); coordXmax = Math.Max(coordXmin, coordXmax); coordYmin = Math.Min(coordYmin, coordYmax); coordYmax = Math.Max(coordYmin, coordYmax); double defResX = (coordXmax - coordXmin) / 1000; ////////////////////////////////////////////////////////////////////////// //插入对话框,获取selFieldName值 ////////////////////////////////////////////////////////////////////////// using (frmPointInterpolation frm = new frmPointInterpolation()) { frm.StartPosition = FormStartPosition.CenterScreen; frm.FieldNames = dicFieldValues.Keys.ToArray(); frm.ResX = defResX; frm.ResY = defResX; frm.ResXmin = (coordXmax - coordXmin) / 10000; frm.ResXmax = (coordXmax - coordXmin) / 50; frm.ResYmin = (coordYmax - coordYmin) / 10000; frm.ResYmax = (coordYmax - coordYmin) / 50; frm.OutputImg = GetOutImgName(fileName); if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { //获取坐标值和字段值 string selFieldName = frm.GetSelFieldName(); double resolutionX = frm.ResX; double resolutionY = frm.ResY; string outImg = frm.OutputImg; List <double> coordListX = new List <double>(); List <double> coordListY = new List <double>(); List <double> valueList = new List <double>(); double coordX, coordY; for (int i = 0; i < featureCount; i++) { ShapePoint point = features[i].Geometry as ShapePoint; if (point == null) { continue; } canvas.CoordTransform.Prj2Geo(point.X, point.Y, out coordX, out coordY); coordListX.Add(coordX); coordListY.Add(coordY); valueList.Add(Convert.ToDouble(dicFieldValues[selFieldName][i])); } IProgressMonitor progress = _smartSession.ProgressMonitorManager.DefaultProgressMonitor; if (progress != null) { progress.Reset("", 100); progress.Start(false); } //执行插值操作 IDW_Interpolation interpolation = new IDW_Interpolation(); interpolation.CoordPointXArr = coordListX.ToArray(); interpolation.CoordPointYArr = coordListY.ToArray(); interpolation.PointValueArr = valueList.ToArray(); if (fetc.SpatialReference != null) { interpolation.DoIDWinterpolation(resolutionX, resolutionY, outImg, "LDF", enumDataType.Double, new Action <int, string>((int progerss, string text) => { if (progress != null) { progress.Boost(progerss, text); } }), fetc.SpatialReference.ToProj4String()); } else { interpolation.DoIDWinterpolation(resolutionX, resolutionY, outImg, "LDF", enumDataType.Double, new Action <int, string>((int progerss, string text) => { if (progress != null) { progress.Boost(progerss, text); } }), null); } if (progress != null) { progress.Finish(); } //对插值后影像进行渲染,并显示到当前视图中 AddRasterLayer(outImg, canvas, valueList.Min(), valueList.Max()); canvas.Refresh(enumRefreshType.All); } } }
public override void Execute() { IRasterDataProvider XdataProvider = null, YdataProvider = null; try { bool isNewX = false, isNewY = false; int[] bandNos = null; int[] viewerAoi = null, rightAoi = null; string aoiType = null; using (frmScatterTwoVarSelector frm = new frmScatterTwoVarSelector()) { frm.StartPosition = FormStartPosition.CenterScreen; //XdataProvider =GetCurrentDataProvider(); //if (XdataProvider!=null) //{ // frm.AOIName = "视图AOI"; // aoiType = "viewer"; // viewerAoi = GetAOI(); // frm.Apply(XdataProvider, viewerAoi, true); //} //else { if (StatRegionSet.UseRecgRegion || StatRegionSet.UseRegion) { frm.AOIName = StatRegionSet.SelectedRegionEnvelope.Name; aoiType = "recg"; } else if (StatRegionSet.UseVectorAOIRegion) { frm.AOIName = StatRegionSet.AOIName; aoiType = "vector"; } } if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { XdataProvider = frm.XDataProvider; isNewX = frm.IsNewXDataProvider; YdataProvider = frm.YDataProvider; isNewY = frm.IsNewYDataProvider; bandNos = new int[] { frm.XBandNo, frm.YBandNo }; //判断两个文件的大小一致、空间范围一致 if (XdataProvider.Width != YdataProvider.Width) //|| XdataProvider.Height != YdataProvider.Height { throw new ArgumentException("两个文件大小不一致!目前仅支持相同大小文件!"); } CoordEnvelope lenv = XdataProvider.CoordEnvelope, renv = YdataProvider.CoordEnvelope; if (lenv == null || lenv.Width <= 0 || lenv.Height <= 0) { throw new ArgumentException("X轴文件的空间范围信息不可用!"); } if (renv == null || renv.Width <= 0 || renv.Height <= 0) { throw new ArgumentException("Y轴文件的空间范围信息不可用!"); } if (lenv.MinX != renv.MinX || lenv.MaxY != renv.MaxY) { throw new ArgumentException("两个文件空间区域不一致!目前仅支持相同范围!!"); } if (frm.AOIName != null)//利用AOI { // 两个文件存在相交 PrjEnvelope lfilePrj, rfilePrj; //PrjEnvelope lfilePrj = new PrjEnvelope(lenv.MinX, lenv.MaxX, lenv.MinY, lenv.MaxY), rfilePrj = new PrjEnvelope(renv.MinX, renv.MaxX, renv.MinY, renv.MaxY); //PrjEnvelope env = PrjEnvelope.Intersect(lfilePrj, rfilePrj); //if (env == null || env.Width <= 0 || env.Height <= 0) // throw new ArgumentException("两个文件不存在空间相交区域!"); //分别计算两个文件的AOI index if (aoiType.ToLower() == "recg") { if (CloudParaFileStatics.CheckAOIIntersect(XdataProvider, StatRegionSet.SelectedRegionEnvelope.PrjEnvelope, out lfilePrj, out viewerAoi) && CloudParaFileStatics.CheckAOIIntersect(YdataProvider, StatRegionSet.SelectedRegionEnvelope.PrjEnvelope, out rfilePrj, out rightAoi)) { } } else if (aoiType.ToLower() == "vector") { AOIContainerLayer aoiContainer = StatRegionSet.AoiContainer; PrjEnvelope RegionEnv = StatRegionSet.AOIPrjEnvelope; if (RegionEnv == null || RegionEnv.Height <= 0 || RegionEnv.Width <= 0) { throw new ArgumentException("矢量AOI区域设置无效或范围不合法!"); } if (aoiContainer != null) { Size xSize = new Size(XdataProvider.Width, XdataProvider.Height); viewerAoi = CloudParaFileStaticsAOI.GetAOI(lenv, aoiContainer, xSize); if (viewerAoi == null || viewerAoi.Length <= 0) { throw new ArgumentException(Path.GetFileName(XdataProvider.fileName) + "与矢量AOI区域" + frm.AOIName + "无相交区域!"); } Size ySize = new Size(YdataProvider.Width, YdataProvider.Height); rightAoi = CloudParaFileStaticsAOI.GetAOI(renv, aoiContainer, ySize); if (rightAoi == null || rightAoi.Length <= 0) { throw new ArgumentException(Path.GetFileName(YdataProvider.fileName) + "与矢量AOI区域" + frm.AOIName + "无相交区域!"); } } } //判断两个Index大小相等 if (viewerAoi == null || rightAoi == null || viewerAoi.Length != rightAoi.Length) { throw new ArgumentException("两个文件AOI区域大小不一致!"); } } //构建虚拟的dataProvider IRasterBand xband = XdataProvider.GetRasterBand(bandNos[0]); IRasterBand yband = YdataProvider.GetRasterBand(bandNos[1]); IRasterDataProvider localprd = new LogicalRasterDataProvider(frm.AOIName + "区域", new IRasterBand[2] { xband, yband }, null); //if (localprd.BandCount!=2) //{ // throw new ArgumentException("两个波段信息不一致,无法进行散点图运算!"); //} IProgressMonitor progress = _smartSession.ProgressMonitorManager.DefaultProgressMonitor; try { progress.Reset("正在准备生成散点图...", 100); progress.Start(false); frmScatterGraph frm1 = new frmScatterGraph(); frm1.Owner = _smartSession.SmartWindowManager.MainForm as Form; frm1.StartPosition = FormStartPosition.CenterScreen; LinearFitObject fitObj = frm.FitObj; frm1.Reset(localprd, 1, 2, viewerAoi, fitObj, (idx, tip) => { progress.Boost(idx, "正在准备生成散点图..."); } ); progress.Finish(); frm1.Show(); frm1.Rerender(); frm1.FormClosed += new FormClosedEventHandler((obj, e) => { if (isNewX && XdataProvider != null) { XdataProvider.Dispose(); XdataProvider = null; } if (isNewY && YdataProvider != null) { YdataProvider.Dispose(); YdataProvider = null; } }); } finally { progress.Finish(); } } } } catch (System.Exception ex) { MessageBox.Show(ex.Message); return; } }
/// <summary> /// /// </summary> /// <param name="argument">格式"*#*"冒号前面部分表示文件名称,冒号后面部分表示所选投影坐标的Wkt格式字符串</param> public override void Execute(string argument) { try { string fileName = ""; ISpatialReference proj = null; GeoDo.RSS.Core.DrawEngine.CoordEnvelope[] envelopes; fileName = TryCheckArgsEnvironment(out envelopes); proj = SpatialReference.GetDefault(); List <PrjEnvelopeItem> lstEnvelope = new List <PrjEnvelopeItem>(); for (int i = 0; i < envelopes.Length; i++) { GeoDo.RSS.Core.DrawEngine.CoordEnvelope env = envelopes[i]; if (env.IsEmpty()) { throw new Exception("获得的感兴趣区域是空值:" + env.ToString()); } PrjEnvelope prjEnv = new PrjEnvelope(env.MinX, env.MaxX, env.MinY, env.MaxY); lstEnvelope.Add(new PrjEnvelopeItem("AOI", prjEnv)); } if (string.IsNullOrWhiteSpace(fileName)) { throw new Exception("无法从参数中解析出文件名:" + argument); } string errorMsg; string[] outFiles = null; IProgressMonitor progressMonitor = null; Action <int, string> progress = null; try { progressMonitor = _smartSession.ProgressMonitorManager.DefaultProgressMonitor; progress = new Action <int, string>( (int progerss, string text) => { if (progressMonitor != null) { progressMonitor.Boost(progerss, text); } }); if (progressMonitor != null) { progressMonitor.Reset("", 100); progressMonitor.Start(false); progressMonitor.Boost(0, "准备文件"); } string outdir = GetOutDirFromConfig(fileName); PrjOutArg prjOutArg = new PrjOutArg(proj, lstEnvelope.ToArray(), 0, 0, outdir); //添加对自定义感兴趣区的支持。 ProjectionFactory quick = new ProjectionFactory(); outFiles = quick.Project(fileName, prjOutArg, progress, out errorMsg); } finally { if (progressMonitor != null) { progressMonitor.Finish(); } progress = null; } if (outFiles != null && outFiles.Length != 0) { for (int i = 0; i < outFiles.Length; i++) { if (!string.IsNullOrWhiteSpace(outFiles[i])) { OpenFileToWindows(outFiles[i]); } } } if (errorMsg != null && errorMsg.Length != 0) { MsgBox.ShowInfo(errorMsg); } } catch (Exception ex) { MsgBox.ShowInfo(ex.Message); } }
private void DoGenerateContourLines(ICanvas canvas, double resX, double resY, frmPointContour.ContourItem[] contourItems, bool isNeedDisplay, bool isNeedLabel, IDW_Interpolation interpolate, string shpFileName) { IProgressMonitor progress = _smartSession.ProgressMonitorManager.DefaultProgressMonitor; try { progress.Reset("正在生成等值线...", 100); progress.Start(false); ContourGenerateTool tool = new ContourGenerateTool(); double[] cvs = ToContourValues(contourItems); ContourLine[] cntLines = tool.Generate(resX, resY, enumDataType.Float, cvs, interpolate, (idx, tip) => { progress.Boost(idx, tip); }); if (cntLines == null || cntLines.Length == 0) { MsgBox.ShowInfo("不存在符合指定条件的等值线!"); return; } double dMinX = interpolate.CoordPointXArr.Min(); double dMaxY = interpolate.CoordPointYArr.Max(); for (int i = 0; i < cntLines.Count(); i++) { ContourLine cntLine = cntLines[i]; ContourLine newCntLine = new ContourLine(cntLine.ContourValue); PointF[] pts = cntLine.Points; for (int j = 0; j < pts.Count(); j++) { pts[j].X = Convert.ToSingle(dMinX + resX * pts[j].X); pts[j].Y = Convert.ToSingle(dMaxY - resY * pts[j].Y); } newCntLine.AddPoints(pts); newCntLine.UpdateEnvelope(); cntLines[i] = newCntLine; } if (shpFileName != null) { TryExport2ShapeFile(canvas, cntLines, shpFileName, progress, isNeedDisplay); } if (isNeedDisplay) { TryDisplay(cntLines, contourItems, isNeedLabel); } } finally { progress.Finish(); } }