private void CalcSample(ListBox listbox, TextBox textBox) { try { if (listbox.Items.Count > 0) { textBox.Text = ""; textBox.Enabled = true; if (Path.GetExtension(listbox.Items[0].ToString()) == ".000") { textBox.Text = "1"; textBox.Enabled = false; return; } if (StatRegionSet.UseRegion || StatRegionSet.UseVectorAOIRegion) { double dst = CloudParaFileStatics.CalcSample(listbox.Items[0].ToString(), true); textBox.Text = dst.ToString("f1"); } else { double dst = CloudParaFileStatics.CalcSample(listbox.Items[0].ToString()); textBox.Text = dst.ToString("f1"); } } } catch (System.Exception ex) { toolStripStatusLabel1.Text = ex.Message; } }
private void txtrightRatio_TextChanged(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtrightRatio.Text)) { return; } string[] lfiles = GetFileNames(listBox2); string[] rfiles = GetFileNames(listBox1); if (lfiles == null || lfiles.Length == 0) { return; } if (Path.GetExtension(lfiles[0]) == ".000") { int width = GetMicapsWidth(lfiles[0], rfiles.Length < 1 ? null : rfiles[0]); txtRightSize.Text = "X:" + width + ",Y:1"; return; } int leftBandNum = GetBandNo(comboBox2); double ratio; if (TryGetRatio(txtrightRatio, out ratio)) { Size size; CloudParaFileStatics.RatioSize(lfiles[0], leftBandNum, ratio, out size); txtRightSize.Text = "X:" + size.Width + ",Y:" + size.Height; } }
private void DoWork() { try { CloudParaFileStatics st = new CloudParaFileStatics(); long scL, scR; double correla; bool lisMicaps = false, risMicaps = false; if (Path.GetExtension(_lfiles[0]) == ".000") { lisMicaps = true; } if (Path.GetExtension(_rfiles[0]) == ".000") { risMicaps = true; } correla = st.FilesCorrelateStat(_lfiles, _leftBandNum, _fillvalueL, lisMicaps, _rfiles, _rightBandNum, _fillvalueR, risMicaps, _state, out scL, out scR); txtOutputDir.Text = correla.ToString(); txtSampleCountsL.Text = scL.ToString(); txtSampleCountsR.Text = scR.ToString(); } catch (System.Exception ex) { Action <int, string> process = _state as Action <int, string>; if (process != null) { process(0, ex.Message); } } }
public static void GetMatchedRasterValues(string[] rasterfiles, int bandNum, string[] fillValueStrRst, List <ShapePoint> matchedpos, out double[][] rasterdata) { rasterdata = null; int width = matchedpos.Count; int length = rasterfiles.Length; Double[] fillValuesRst = null; fillValuesRst = CloudParaFileStatics.GetFillValues <Double>(fillValueStrRst, enumDataType.Double); rasterdata = new double[length][]; double[] matchedRasterValues = new double[width]; for (int lr = 0; lr < length; lr++) { matchedRasterValues = GetMatchedRasterValues(rasterfiles[lr], bandNum, matchedpos.ToArray()); double alue; for (int i = 0; i < width; i++) { alue = matchedRasterValues[i]; if (fillValuesRst != null && fillValuesRst.Contains(alue)) { matchedRasterValues[i] = 0; } } rasterdata[lr] = matchedRasterValues; } }
private void DoProcess() { try { CloudParaFileStatics st = new CloudParaFileStatics(); string[] result = st.FilesSVDStat(_lfiles, _leftBandNum, _fillvalueL, _rfiles, _rightBandNum, _fillvalueR, _leftRatio, _rightRatio, _outdir, _state as Action <int, string>, _lisMicaps, _risMicaps); if (result != null) { foreach (string file in result) { if (Path.GetFileName(file).Contains("累计方差贡献")) { Process.Start(file); } } } } catch (System.Exception ex) { _state(0, ex.Message); } }
private void DoProcess() { try { CloudParaFileStatics st = new CloudParaFileStatics(); string[] result; if (_lisMicaps) { result = st.FilesEOFStat(_lfiles, _leftBandNum, _leftBandName, _fillvalueL, true, _outdir, _state as Action <int, string>); } else if (checkBox1.Checked) { result = st.FilesEOFStat(_lfiles, _leftBandNum, _leftBandName, _fillvalueL, false, _outdir, _state as Action <int, string>, _rfiles, _fillvalueR); } else { result = st.FilesEOFStat(_lfiles, _leftBandNum, _leftBandName, _fillvalueL, false, _outdir, _state as Action <int, string>, null, null, double.Parse(txtleftRatio.Text)); } if (result != null) { foreach (string file in result) { if (Path.GetFileName(file).Contains("累计方差贡献")) { Process.Start(file); } } } } catch (System.Exception ex) { Action <int, string> process = _state as Action <int, string>; if (process != null) { process(0, ex.Message); } } }
private void DoWork() { string[] lfiles = GetFileNames(listBox1); string[] rfiles = GetFileNames(listBox2); if (!CheckFiles(lfiles, rfiles)) { return; } int leftBandNum = GetBandNo(comboBox1, Path.GetExtension(lfiles[0]) == ".000"); int rightBandNum = GetBandNo(comboBox2, Path.GetExtension(rfiles[0]) == ".000"); double leftRatio, rightRatio; TryGetRatio(txtleftRatio, out leftRatio); TryGetRatio(txtrightRatio, out rightRatio); string outdir = txtOutputDir.Text; bool lisMicaps = false, risMicaps = false; if (Path.GetExtension(lfiles[0]) == ".000") { lisMicaps = true; } if (Path.GetExtension(rfiles[0]) == ".000") { risMicaps = true; } string[] fillvalueR = null; if (!string.IsNullOrEmpty(txtFillvaluesR.Text)) { string[] parts = txtFillvaluesR.Text.Split(','); double fv; foreach (string part in parts) { if (double.TryParse(part, out fv)) { throw new ArgumentException("填充值设置无效!" + part); } } if (parts.Length > 0) { fillvalueR = parts; } } string[] fillvalueL = null; if (!string.IsNullOrEmpty(txtFillvaluesL.Text)) { string[] parts = txtFillvaluesL.Text.Split(','); double fv; foreach (string part in parts) { if (double.TryParse(part, out fv)) { throw new ArgumentException("填充值设置无效!" + part); } } if (parts.Length > 0) { fillvalueL = parts; } } var context = TaskScheduler.FromCurrentSynchronizationContext(); var token = Task.Factory.CancellationToken; Task task = Task.Factory.StartNew((arg) => { Task.Factory.StartNew(() => { toolStrip1.Enabled = false; }, token, TaskCreationOptions.None, context); try { CloudParaFileStatics st = new CloudParaFileStatics(); string[] result = st.FilesSVDStat(lfiles, leftBandNum, fillvalueL, rfiles, rightBandNum, fillvalueR, leftRatio, rightRatio, outdir, arg as Action <int, string>, lisMicaps, risMicaps); if (result != null) { foreach (string file in result) { if (Path.GetFileName(file).Contains("累计方差贡献")) { Process.Start(file); } } } } catch (Exception ex) { Action <int, string> process = arg as Action <int, string>; if (process != null) { process(0, ex.Message); } } }, _state); task.ContinueWith((t) => { toolStrip1.Enabled = true; }, context); }
/// <summary> /// 获取栅格文件与自定义区域的交集区域 /// </summary> /// <param name="rasterfiles"></param> /// <param name="regionEnv"></param> /// <returns></returns> public static Envelope GetInterectEnv(string[] rasterfiles, PrjEnvelope regionEnv) { return(CloudParaFileStatics.GetIntersectEnvolop(rasterfiles, regionEnv)); }
/// <summary> /// 相关系数计算对应micaps点抽取栅格数据,存在多个数据则该点平均 /// </summary> /// <param name="rasterfiles"></param> /// <param name="bandNum"></param> /// <param name="fillValueStrRst"></param> /// <param name="micapsFiles"></param> /// <param name="mbandNo"></param> /// <param name="fillValuestr"></param> /// <param name="envelope"></param> /// <param name="rasterdata"></param> /// <param name="micapsdata"></param> /// <param name="scL"></param> /// <param name="scR"></param> public static void GetMatchedValues(string[] rasterfiles, int bandNum, string [] fillValueStrRst, string[] micapsFiles, int mbandNo, string [] fillValuestr, PrjEnvelope envelope, out double[] rasterdata, out double[] micapsdata, out long scL, out long scR) { rasterdata = null; micapsdata = null; scL = 0; scR = 0; Envelope dstEnv = GetInterectEnv(rasterfiles, envelope); if (dstEnv == null || dstEnv.Width == 0 || dstEnv.Height == 0) { throw new ArgumentNullException("待分析区域为空,请确认自定义区域范围或数据文件范围!"); } #region 获取micaps数据 Dictionary <string, ShapePoint> unionStationPos; Dictionary <string, List <string> > unionStationValues;//站点编号,数据索引号,数据值 GetUnionStationValues(micapsFiles, mbandNo, fillValuestr, dstEnv, out unionStationPos, out unionStationValues); if (unionStationPos.Count < 1) { throw new ArgumentException("指定的Micaps数据不包含站点数据!"); } double staValue; List <double> micapsdatalist = new List <double>(); foreach (List <string> list in unionStationValues.Values) { double sum = 0; int count = 0; foreach (string str in list)//list为所有站点非填充值的值的集合, { if (double.TryParse(str, out staValue)) { sum += staValue; count++; scR++; } } if (count != 0) { micapsdatalist.Add(sum / count);//有效平均 } else { micapsdatalist.Add(0);//无效填0 } } micapsdata = micapsdatalist.ToArray(); #endregion #region 获取栅格对应点的数据 int matchedcount = micapsdatalist.Count; Double[] fillValuesRst = null; fillValuesRst = CloudParaFileStatics.GetFillValues <Double>(fillValueStrRst, enumDataType.Double); rasterdata = new double[matchedcount]; double[] summatchedRasterValues = new double[matchedcount]; int[] sumRasterCounts = new int[matchedcount]; foreach (string rasterf in rasterfiles) { rasterdata = GetMatchedRasterValues(rasterf, bandNum, unionStationPos.Values.ToArray()); double alue; for (int i = 0; i < matchedcount; i++) { alue = rasterdata[i]; if (fillValuesRst == null || !fillValuesRst.Contains(alue)) { summatchedRasterValues[i] += alue; sumRasterCounts[i]++; scL++; } } } for (int i = 0; i < matchedcount; i++) { if (sumRasterCounts[i] != 0) { rasterdata[i] = summatchedRasterValues[i] / sumRasterCounts[i]; } else { rasterdata[i] = 0; } } #endregion }
private void DoWork() { try { if (!CheckArgsIsOk()) { return; } string[] lfiles = GetFileNames(listBox1); if (lfiles.Length < 1) { throw new ArgumentException("待统计文件为空!"); } //int[] leftBandNum = new int[] { }; //int[] leftBandNum = GetBandNo(lvBands); //if (leftBandNum == null) // throw new ArgumentException("待统计波段为空!"); int bandno = GetBandNo(this.comboBox1); if (bandno <= 0) { throw new ArgumentException("待统计波段无效!"); } string[] fillvalue = null; if (!string.IsNullOrEmpty(txtFillvalues.Text)) { try { string[] parts = txtFillvalues.Text.Split(','); double fv; foreach (string part in parts) { if (!double.TryParse(part, out fv)) { throw new ArgumentException("填充值设置无效!" + part); } } if (parts.Length > 0) { fillvalue = parts; } } catch (System.Exception ex) { throw ex; } } CloudParaFileStatics st = new CloudParaFileStatics(); string[] files = st.FilesSeriesMeanStat(lfiles, bandno, fillvalue, txtOutputDir.Text, _state as Action <int, string>); _state(100, "长时间序列均值统计完成!"); foreach (string file in files) { if (File.Exists(file)) { Process.Start(file); } } } catch (Exception ex) { Action <int, string> process = _state as Action <int, string>; if (process != null) { process(0, ex.Message); } } }
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; } }
private void DoWork() { try { bool reverse;//标识最大是否<最小值 if (!CheckArgsIsOk(out reverse)) { return; } string[] lfiles = GetFileNames(listBox1); if (lfiles.Length < 1) { throw new ArgumentException("待统计文件为空!"); } int[] leftBandNum = GetBandNo(lvBands); if (leftBandNum == null) { throw new ArgumentException("待统计波段为空!"); } if (checkBox1.Checked && leftBandNum.Length > 1) { throw new ArgumentException("分区段统计只适用于单一波段,请重新选择!"); } string[] fillvalue = null; if (!string.IsNullOrEmpty(txtFillvalues.Text)) { string[] parts = txtFillvalues.Text.Split(','); double fv; foreach (string part in parts) { if (double.TryParse(part, out fv)) { throw new ArgumentException("填充值设置无效!" + part); } } if (parts.Length > 0) { fillvalue = parts; } } CloudParaFileStatics st = new CloudParaFileStatics(); Dictionary <int, RasterQuickStatResult> results = null; if (Path.GetExtension(lfiles[0]) == ".000") { if (!checkBox1.Checked)//全部统计 { results = st.MicapsHistoStat(lfiles, leftBandNum, fillvalue, _state as Action <int, string>); } else//分区段 { if (!reverse) { results = st.MicapsHistoStatBetween(lfiles, leftBandNum, fillvalue, txtMin.Text, txtMax.Text, _state as Action <int, string>); } else { results = st.MicapsHistoStatBetween(lfiles, leftBandNum, fillvalue, txtMax.Text, txtMin.Text, _state as Action <int, string>); } } } else { if (!checkBox1.Checked)//全部统计 { results = st.FilesHistoStat(lfiles, leftBandNum, fillvalue, _state as Action <int, string>); } else//分区段 { if (!reverse) { results = st.FilesHistoStatBetween(lfiles, leftBandNum, fillvalue, txtMin.Text, txtMax.Text, _state as Action <int, string>); } else { results = st.FilesHistoStatBetween(lfiles, leftBandNum, fillvalue, txtMax.Text, txtMin.Text, _state as Action <int, string>); } } } if (results != null) { frmRasterQuickStat frm = new frmRasterQuickStat();//) { frm.Owner = _smartSession.SmartWindowManager.MainForm as Form; frm.StartPosition = FormStartPosition.CenterScreen; frm.Apply(lfiles[0], results); frm.Show(); } } } catch (Exception ex) { Action <int, string> process = _state as Action <int, string>; if (process != null) { process(0, ex.Message); } } }
public List <string[]> SeriesStaticAOI(string[] filesL, int bandNumL, string[] fillvalueL, out Dictionary <DateTime, string> filedate, Action <int, string> progressCallback) { int[] aoiIndex; Size fileSize; int aoilength; int count = 0; IRasterDataProvider arrayPrd = null; List <string[]> resultList = new List <string[]>(); filedate = new Dictionary <DateTime, string>(); DateTime t = DateTime.MinValue; try { foreach (string file in filesL) { enumDataType datatype = enumDataType.Unknow; using (IRasterDataProvider dataPrd = GeoDataDriver.Open(file) as IRasterDataProvider) { datatype = dataPrd.DataType; fileSize = new Size(dataPrd.Width, dataPrd.Height); //创建AOI(基于数据的地理范围) aoiIndex = GetAOI(dataPrd.CoordEnvelope, _aoiContainer, fileSize); if (aoiIndex == null || aoiIndex.Length <= 0) { throw new ArgumentException("矢量AOI区域设置无效或范围不合法!"); } } aoilength = aoiIndex.Length; count = 0; arrayPrd = null; switch (datatype) { case enumDataType.Float: float[][] rasterbandsF = new float[1][]; { rasterbandsF[0] = GetHistArrayAOI <float>(new string[] { file }, bandNumL, fileSize.Width, fileSize.Height, datatype, aoiIndex, fillvalueL, out count); arrayPrd = new ArrayRasterDataProvider <float>("Array", rasterbandsF, aoilength, 1); } break; case enumDataType.Int16: short[][] rasterbandsS = new short[1][]; { rasterbandsS[0] = GetHistArrayAOI <short>(new string[] { file }, bandNumL, fileSize.Width, fileSize.Height, datatype, aoiIndex, fillvalueL, out count); arrayPrd = new ArrayRasterDataProvider <short>("Array", rasterbandsS, aoilength, 1); } break; case enumDataType.Byte: Byte[][] rasterbandsB = new Byte[1][]; { rasterbandsB[0] = GetHistArrayAOI <Byte>(new string[] { file }, bandNumL, fileSize.Width, fileSize.Height, datatype, aoiIndex, fillvalueL, out count); arrayPrd = new ArrayRasterDataProvider <Byte>("Array", rasterbandsB, aoilength, 1); } break; default: throw new ArgumentException("暂不支持" + datatype.ToString() + "类型的统计!"); } if (arrayPrd.Width == 0 || arrayPrd.Height == 0) { throw new ArgumentException("创建待统计数据失败!" + file); } double[] values; if (CloudParaFileStatics.ComputeMinMaxAvg(arrayPrd, datatype, new int[] { bandNumL }, null, out values, progressCallback)) { string date; GetFileTime(file, out date, out t); if (!filedate.ContainsKey(t)) { filedate.Add(t, date); } resultList.Add(new string[] { date, values[1].ToString("f2") }); if (progressCallback != null) { progressCallback(-1, Path.GetFileName(file) + "统计完成!"); } } } return(resultList); } finally { if (arrayPrd != null) { arrayPrd.Dispose(); } } }