private void AddLineSeries(frmBoxPlotResults pfrmBoxplotResults, string strSeriesName, System.Drawing.Color FillColor, int intWidth, ChartDashStyle BorderDash, double dblXMin, double dblXMax, double dblYMin, double dblYMax) { //try //{ var pSeries = new System.Windows.Forms.DataVisualization.Charting.Series { Name = strSeriesName, Color = FillColor, //BorderColor = Color.Black, BorderWidth = intWidth, IsVisibleInLegend = false, IsXValueIndexed = false, BorderDashStyle = BorderDash, ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line, }; pfrmBoxplotResults.pChart.Series.Add(pSeries); pSeries.Points.AddXY(dblXMin, dblYMin); pSeries.Points.AddXY(dblXMax, dblYMax); //} //catch (Exception ex) //{ // frmErrorLog pfrmErrorLog = new frmErrorLog();pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); // return; //} }
private void btnBoxplot_Click(object sender, EventArgs e) { try { #region Combined Chart string strTargetLayerName = cboTargetLayer.Text; string strFieldName = cboFieldName.Text; string strGroupFieldName = cboGroupField.Text; int intTargetIndex = m_pSnippet.GetIndexNumberFromLayerName(m_pActiveView, strTargetLayerName); int intNFeatureCount = 0; ILayer pTargetLayer = m_pForm.axMapControl1.get_Layer(intTargetIndex); IFeatureLayer pTargetFLayer = (IFeatureLayer)pTargetLayer; //Extract geometry from selected feature IFeatureCursor pFCursor = null; pFCursor = pTargetFLayer.Search(null, true); intNFeatureCount = pTargetFLayer.FeatureClass.FeatureCount(null); int intFieldIdx = pTargetFLayer.FeatureClass.Fields.FindField(strFieldName); int intGroupIdx = pTargetFLayer.FeatureClass.Fields.FindField(strGroupFieldName); System.Collections.Generic.List <object> uvList = new System.Collections.Generic.List <object>(); ICursor ipCursor = pFCursor as ICursor; IRow ipRow = ipCursor.NextRow(); while (ipRow != null) { object curValue = ipRow.get_Value(intGroupIdx); if (!uvList.Contains(curValue)) { uvList.Add(curValue); } ipRow = ipCursor.NextRow(); } uvList.Sort(); //Add exeption for sorting //0421 HK //1. H L M if (uvList.Count == 3) { if (uvList[0].ToString() == "H" && uvList[1].ToString() == "L" && uvList[2].ToString() == "M") { uvList.Clear(); uvList.Add("L"); uvList.Add("M"); uvList.Add("H"); } if (uvList[0].ToString() == "High" && uvList[1].ToString() == "Low" && uvList[2].ToString() == "Medium") { uvList.Clear(); uvList.Add("Low"); uvList.Add("Medium"); uvList.Add("High"); } } ipCursor.Flush(); int intNGroups = uvList.Count; double[,] adbBPStats = new double[5, uvList.Count]; double[,] adbQuantiles = new double[5, uvList.Count]; IQueryFilter pQfilter = new QueryFilterClass(); double[][] adblTarget = new double[intNGroups][]; double[][] adblDiff = new double[intNGroups][]; int[] aintNCounts = new int[intNGroups]; int i = 0; foreach (string uvValue in uvList) { pQfilter.WhereClause = strGroupFieldName + " = '" + uvValue + "'"; pFCursor = pTargetFLayer.Search(pQfilter, true); IFeature pFeature = pFCursor.NextFeature(); intNFeatureCount = pTargetFLayer.FeatureClass.FeatureCount(pQfilter); aintNCounts[i] = intNFeatureCount; adblTarget[i] = new double[intNFeatureCount]; adblDiff[i] = new double[intNFeatureCount]; int j = 0; while (pFeature != null) { adblTarget[i][j] = Convert.ToDouble(pFeature.get_Value(intFieldIdx)); j++; pFeature = pFCursor.NextFeature(); } pFCursor.Flush(); double[] dblQuantiles = new double[5]; dblQuantiles = BoxPlotStats(adblTarget[i]); adblDiff[i] = GetStatsForStackedBarChart(adblTarget[i]); for (int k = 0; k < 5; k++) // Needs to be modified 010716 HK { adbQuantiles[k, i] = dblQuantiles[k]; } i++; } frmBoxPlotResults pfrmBoxplotResults = new frmBoxPlotResults(); pfrmBoxplotResults.Text = "BoxPlot of " + pTargetFLayer.Name; pfrmBoxplotResults.pChart.Series.Clear(); ChartArea area = pfrmBoxplotResults.pChart.ChartAreas[0]; int intMaxFeatureNCount = aintNCounts.Max(); //Draw Lines for (int k = 0; k < intNGroups; k++) { int intXvalue = k * 2 + 1; double dblXmin = Convert.ToDouble(intXvalue) - 0.6; double dblXmax = Convert.ToDouble(intXvalue) + 0.6; double dblXBoxMin = Convert.ToDouble(intXvalue) - 0.8; double dblXBoxMax = Convert.ToDouble(intXvalue) + 0.8; AddLineSeries(pfrmBoxplotResults, "min_" + k.ToString(), Color.Black, 1, ChartDashStyle.Solid, dblXmin, dblXmax, adbQuantiles[0, k], adbQuantiles[0, k]); AddLineSeries(pfrmBoxplotResults, "BoxBottom_" + k.ToString(), Color.Black, 1, ChartDashStyle.Solid, dblXBoxMin, dblXBoxMax, adbQuantiles[1, k], adbQuantiles[1, k]); AddLineSeries(pfrmBoxplotResults, "BoxLeft_" + k.ToString(), Color.Black, 1, ChartDashStyle.Solid, dblXBoxMin, dblXBoxMin, adbQuantiles[1, k], adbQuantiles[3, k]); AddLineSeries(pfrmBoxplotResults, "BoxRight_" + k.ToString(), Color.Black, 1, ChartDashStyle.Solid, dblXBoxMax, dblXBoxMax, adbQuantiles[1, k], adbQuantiles[3, k]); AddLineSeries(pfrmBoxplotResults, "Boxup_" + k.ToString(), Color.Black, 1, ChartDashStyle.Solid, dblXBoxMin, dblXBoxMax, adbQuantiles[3, k], adbQuantiles[3, k]); AddLineSeries(pfrmBoxplotResults, "median_" + k.ToString(), Color.Black, 2, ChartDashStyle.Solid, dblXBoxMin, dblXBoxMax, adbQuantiles[2, k], adbQuantiles[2, k]); AddLineSeries(pfrmBoxplotResults, "max_" + k.ToString(), Color.Black, 1, ChartDashStyle.Solid, dblXmin, dblXmax, adbQuantiles[4, k], adbQuantiles[4, k]); AddLineSeries(pfrmBoxplotResults, "verDown_" + k.ToString(), Color.Black, 1, ChartDashStyle.Dash, intXvalue, intXvalue, adbQuantiles[0, k], adbQuantiles[1, k]); AddLineSeries(pfrmBoxplotResults, "verUp_" + k.ToString(), Color.Black, 1, ChartDashStyle.Dash, intXvalue, intXvalue, adbQuantiles[3, k], adbQuantiles[4, k]); } //Add Points System.Drawing.Color pMarkerColor = System.Drawing.Color.Blue; var seriesOutPts = new System.Windows.Forms.DataVisualization.Charting.Series { Name = "Points", Color = pMarkerColor, BorderColor = pMarkerColor, IsVisibleInLegend = false, IsXValueIndexed = false, ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point, MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle }; pfrmBoxplotResults.pChart.Series.Add(seriesOutPts); for (int k = 0; k < intNGroups; k++) { int intXvalue = k * 2 + 1; foreach (double dblValue in adblTarget[k]) { //if (dblValue < adbQuantiles[1, k] || dblValue > adbQuantiles[3, k]) seriesOutPts.Points.AddXY(intXvalue, dblValue); } } pMarkerColor = System.Drawing.Color.Black; var seriesInPts = new System.Windows.Forms.DataVisualization.Charting.Series { Name = "InPoints", Color = pMarkerColor, BorderColor = pMarkerColor, IsVisibleInLegend = false, IsXValueIndexed = false, ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point, MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle }; pfrmBoxplotResults.pChart.Series.Add(seriesInPts); for (int k = 0; k < intNGroups; k++) { int intXvalue = k * 2 + 1; foreach (double dblValue in adblTarget[k]) { if (dblValue >= adbQuantiles[1, k] && dblValue <= adbQuantiles[3, k]) { seriesInPts.Points.AddXY(intXvalue, dblValue); } } } //Store variables in frmBoxPlotResults pfrmBoxplotResults.mForm = m_pForm; pfrmBoxplotResults.pActiveView = m_pActiveView; pfrmBoxplotResults.pFLayer = pTargetFLayer; pfrmBoxplotResults.Text = "Boxplot of " + pTargetFLayer.Name; pfrmBoxplotResults.strFieldName = strFieldName; pfrmBoxplotResults.strGroupFieldName = strGroupFieldName; pfrmBoxplotResults.uvList = uvList; //pfrmBoxplotResults.pFillColor = pFillColor; pfrmBoxplotResults.adbQuantiles = adbQuantiles; pfrmBoxplotResults.pChart.ChartAreas[0].AxisX.Title = strGroupFieldName; pfrmBoxplotResults.pChart.ChartAreas[0].AxisY.Title = strFieldName; pfrmBoxplotResults.pChart.ChartAreas[0].AxisY.IsStartedFromZero = false; pfrmBoxplotResults.pChart.ChartAreas[0].AxisX.Maximum = intNGroups * 2; pfrmBoxplotResults.pChart.ChartAreas[0].AxisX.Interval = 2; pfrmBoxplotResults.pChart.ChartAreas[0].AxisX.Minimum = 0; pfrmBoxplotResults.pChart.ChartAreas[0].AxisX.IntervalOffset = -1; pfrmBoxplotResults.pChart.ChartAreas[0].AxisX.IsLabelAutoFit = false; for (int n = 0; n < uvList.Count; n++) { int intXvalue = n * 2 + 1; double dblXmin = Convert.ToDouble(intXvalue) - 0.6; double dblXmax = Convert.ToDouble(intXvalue) + 0.6; CustomLabel pcutsomLabel = new CustomLabel(); pcutsomLabel.FromPosition = dblXmin; pcutsomLabel.ToPosition = dblXmax; pcutsomLabel.Text = uvList[n].ToString(); pfrmBoxplotResults.pChart.ChartAreas[0].AxisX.CustomLabels.Add(pcutsomLabel); } #endregion pfrmBoxplotResults.Show(); #region Previous Method (ChartType = SeriesChartType.BoxPlot) //Previous Method using Boxplot Chart Type (01/07/16) //string strTargetLayerName = cboTargetLayer.Text; //string strFieldName = cboFieldName.Text; //string strGroupFieldName = cboGroupField.Text; //int intTargetIndex = pSnippet.GetIndexNumberFromLayerName(pActiveView, strTargetLayerName); //int intNFeatureCount = 0; //ILayer pTargetLayer = mForm.axMapControl1.get_Layer(intTargetIndex); //IFeatureLayer pTargetFLayer = (IFeatureLayer)pTargetLayer; ////Extract geometry from selected feature //IFeatureCursor pFCursor = null; //pFCursor = pTargetFLayer.Search(null, true); //intNFeatureCount = pTargetFLayer.FeatureClass.FeatureCount(null); //int intFieldIdx = pTargetFLayer.FeatureClass.Fields.FindField(strFieldName); //int intGroupIdx = pTargetFLayer.FeatureClass.Fields.FindField(strGroupFieldName); //System.Collections.Generic.List<object> uvList = new System.Collections.Generic.List<object>(); //ICursor ipCursor = pFCursor as ICursor; //IRow ipRow = ipCursor.NextRow(); //while (ipRow != null) //{ // object curValue = ipRow.get_Value(intGroupIdx); // if (!uvList.Contains(curValue)) // { // uvList.Add(curValue); // } // ipRow = ipCursor.NextRow(); //} //uvList.Sort(); //double[] adblTarget = new double[intNFeatureCount]; //string[] astrGroup = new string[intNFeatureCount]; //IQueryFilter pQfilter = new QueryFilterClass(); //frmBoxPlotResults pfrmBoxplotResults = new frmBoxPlotResults(); //pfrmBoxplotResults.pChart.Series.Clear(); //ChartArea area = pfrmBoxplotResults.pChart.ChartAreas[0]; //Series DataSeries = new Series(); //foreach (string uvValue in uvList) //{ // pQfilter.WhereClause = strGroupFieldName + " = '" + uvValue + "'"; // pFCursor = pTargetFLayer.Search(pQfilter, true); // IFeature pFeature = pFCursor.NextFeature(); // intNFeatureCount = pTargetFLayer.FeatureClass.FeatureCount(pQfilter); // adblTarget = new double[intNFeatureCount]; // int j = 0; // while (pFeature != null) // { // adblTarget[j] = Convert.ToDouble(pFeature.get_Value(intFieldIdx)); // j++; // pFeature = pFCursor.NextFeature(); // } // DataSeries = new Series(uvValue); // DataSeries.ChartArea = area.Name; // DataSeries.Color = Color.Transparent; // DataSeries.Points.DataBindY(adblTarget); // DataSeries.XValueType = ChartValueType.String; // //DataSeries.IsXValueIndexed = true; // pfrmBoxplotResults.pChart.Series.Add(DataSeries); //} //Series BoxPlotSeries = new Series() //{ // Name = "BoxPlotSeries", // ChartArea = area.Name, // ChartType = SeriesChartType.BoxPlot, // Color = Color.White, // BorderColor = Color.Black, // // IsXValueIndexed = true, //XValueType = ChartValueType.String, //}; //pfrmBoxplotResults.pChart.Series.Add(BoxPlotSeries); //pfrmBoxplotResults.pChart.Series["BoxPlotSeries"]["BoxPlotSeries"] = string.Join(";", uvList); //pfrmBoxplotResults.pChart.ChartAreas[0].AxisX.IsMarksNextToAxis = false; ////Manually Change the labels for Boxplot -- Needs to be modified 011117 HK //for (int n = 0; n <= uvList.Count; n++) //{ // //pfrmBoxplotResults.pChart.Series["BoxPlotSeries"].Points[n].AxisLabel = uvList[n].ToString(); // if (n == uvList.Count) // pfrmBoxplotResults.pChart.Series[0].Points[n].AxisLabel = " "; // else // pfrmBoxplotResults.pChart.Series[0].Points[n].AxisLabel = uvList[n].ToString(); // //area.AxisX.CustomLabels[n].Text = uvList[n].ToString(); //} //area.AxisX.Maximum = uvList.Count + 1; //area.AxisX.Minimum = 0; //pfrmBoxplotResults.Show(); #endregion } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }
public string RemoveWarningByBrushingTechnique(IFeatureLayer pFLayer) { //try //{ FormCollection pFormCollection = System.Windows.Forms.Application.OpenForms; //IActiveView pActiveView = mForm.axMapControl1.ActiveView; string strRelatedPlotName = string.Empty; for (int j = 0; j < pFormCollection.Count; j++) { if (pFormCollection[j].Name == "frmHistResults")//Brushing to Histogram { frmHistResults pfrmHistResults = pFormCollection[j] as frmHistResults; if (pfrmHistResults.pFLayer == pFLayer) { strRelatedPlotName += "Histogram, "; } } if (pFormCollection[j].Name == "frmScatterPlotResults") //Brushing to Scatterplot { frmScatterPlotResults pfrmPointsPlot = pFormCollection[j] as frmScatterPlotResults; if (pfrmPointsPlot.m_pFLayer == pFLayer) { strRelatedPlotName += "Scatter plot, "; } } if (pFormCollection[j].Name == "frmQQPlotResults") //Brushing to QQPlot { frmQQPlotResults pfrmQQPlotResult = pFormCollection[j] as frmQQPlotResults; if (pfrmQQPlotResult.m_pFLayer == pFLayer) { strRelatedPlotName += "QQ-plot, "; } } //if (pFormCollection[j].Name == "frmAttributeTable")//Brushing to AttributeTable //{ // frmAttributeTable pfrmAttTable = pFormCollection[j] as frmAttributeTable; // BrushingToAttTable(pfrmAttTable, pFLayer, featureSelection); //} if (pFormCollection[j].Name == "frmBoxPlotResults")//Brushing to AttributeTable { frmBoxPlotResults pfrmBoxPlotResult = pFormCollection[j] as frmBoxPlotResults; if (pfrmBoxPlotResult.pFLayer == pFLayer) { strRelatedPlotName += "Boxplot, "; } } //if (pFormCollection[j].Name == "frmClassificationGraph")//Brushing to Optiize Graph //{ // frmClassificationGraph pfrmClassGraph = pFormCollection[j] as frmClassificationGraph; // BrushingToOptimizeGraph(pfrmClassGraph, pFLayer, featureSelection); //} //if (pFormCollection[j].Name == "frmCSDesign")//Brushing to CS Graph //{ // frmCSDesign pfrmCSDesign = pFormCollection[j] as frmCSDesign; // if (pfrmCSDesign.pFLayer == pFLayer) // strRelatedPlotName += "Uncertainty Classification, "; //} if (pFormCollection[j].Name == "frmMScatterResults")//Brushing to Moran ScatterPlot { frmMScatterResults pfrmMScatterPlot = pFormCollection[j] as frmMScatterResults; if (pfrmMScatterPlot.m_pFLayer == pFLayer) { strRelatedPlotName += "Moran Scatter Plot, "; } } } if (strRelatedPlotName != string.Empty) { strRelatedPlotName = strRelatedPlotName.Remove(strRelatedPlotName.Length - 2); } return(strRelatedPlotName); //} //catch (Exception ex) //{ // MessageBox.Show("Exception:" + ex.Message); // return; //} }
private void BrushingToBoxPlot(frmBoxPlotResults pfrmBoxPlotResults, IFeatureLayer pFLayer, IFeatureSelection featureSelection) { //try //{ if (pfrmBoxPlotResults.pFLayer == pFLayer) { //Remove Previous Selection int intLastSeriesIdx = pfrmBoxPlotResults.pChart.Series.Count - 1; if (pfrmBoxPlotResults.pChart.Series[intLastSeriesIdx].Name == "SelPoints") { pfrmBoxPlotResults.pChart.Series.RemoveAt(intLastSeriesIdx); } IFeatureClass pFeatureClass = pFLayer.FeatureClass; int intVarIdx = pFeatureClass.Fields.FindField(pfrmBoxPlotResults.strFieldName); int intGrpIdx = pFeatureClass.Fields.FindField(pfrmBoxPlotResults.strGroupFieldName); ICursor pCursor = null; featureSelection.SelectionSet.Search(null, false, out pCursor); IRow pRow = pCursor.NextRow(); intLastSeriesIdx = pfrmBoxPlotResults.pChart.Series.Count - 1; int dblOriPtsSize = pfrmBoxPlotResults.pChart.Series[intLastSeriesIdx].MarkerSize; System.Drawing.Color pMarkerColor = System.Drawing.Color.Red; var seriesPts = new System.Windows.Forms.DataVisualization.Charting.Series { Name = "SelPoints", Color = pMarkerColor, BorderColor = pMarkerColor, IsVisibleInLegend = false, IsXValueIndexed = false, ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point, MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle, MarkerSize = dblOriPtsSize * 2 }; pfrmBoxPlotResults.pChart.Series.Add(seriesPts); int intNGroups = pfrmBoxPlotResults.uvList.Count; while (pRow != null) { string strGrp = pRow.get_Value(intGrpIdx).ToString(); for (int k = 0; k < intNGroups; k++) { if (strGrp == pfrmBoxPlotResults.uvList[k].ToString()) { int intXvalue = k * 2 + 1; seriesPts.Points.AddXY(intXvalue, Convert.ToDouble(pRow.get_Value(intVarIdx))); } } pRow = pCursor.NextRow(); } } //} //catch (Exception ex) //{ // MessageBox.Show("Exception:" + ex.Message); // return; //} }
public void BrushingToOthers(IFeatureLayer pFLayer, IntPtr intPtrParent) { try { FormCollection pFormCollection = System.Windows.Forms.Application.OpenForms; //IActiveView pActiveView = mForm.axMapControl1.ActiveView; if (pFLayer.Visible) { //Brushing to Mapcontrol string ShapeFieldName = pFLayer.FeatureClass.ShapeFieldName; IFeatureSelection featureSelection = (IFeatureSelection)pFLayer; for (int j = 0; j < pFormCollection.Count; j++) { if (pFormCollection[j].Handle != intPtrParent) // Brushing to Others { if (pFormCollection[j].Name == "frmHistResults") //Brushing to Histogram { frmHistResults pfrmHistResults = pFormCollection[j] as frmHistResults; BrushingToHistogram(pfrmHistResults, pFLayer, featureSelection); } if (pFormCollection[j].Name == "frmScatterPlotResults") //Brushing to Scatterplot { frmScatterPlotResults pfrmPointsPlot = pFormCollection[j] as frmScatterPlotResults; BrushingToScatterPlot(pfrmPointsPlot, pFLayer, featureSelection); } if (pFormCollection[j].Name == "frmQQPlotResults") //Brushing to QQPlot { frmQQPlotResults pfrmQQPlotResult = pFormCollection[j] as frmQQPlotResults; BrushingToQQPlot(pfrmQQPlotResult, pFLayer, featureSelection); } if (pFormCollection[j].Name == "frmAttributeTable")//Brushing to AttributeTable { frmAttributeTable pfrmAttTable = pFormCollection[j] as frmAttributeTable; BrushingToAttTable(pfrmAttTable, pFLayer, featureSelection); } if (pFormCollection[j].Name == "frmBoxPlotResults")//Brushing to AttributeTable { frmBoxPlotResults pfrmBoxPlotResult = pFormCollection[j] as frmBoxPlotResults; BrushingToBoxPlot(pfrmBoxPlotResult, pFLayer, featureSelection); } //if (pFormCollection[j].Name == "frmClassificationGraph")//Brushing to Optiize Graph //{ // frmClassificationGraph pfrmClassGraph = pFormCollection[j] as frmClassificationGraph; // BrushingToOptimizeGraph(pfrmClassGraph, pFLayer, featureSelection); //} //if (pFormCollection[j].Name == "frmCSDesign")//Brushing to CS Graph //{ // frmCSDesign pfrmCSDesign = pFormCollection[j] as frmCSDesign; // BrushingToClassSepGraph(pfrmCSDesign, pFLayer, featureSelection); //} if (pFormCollection[j].Name == "frmMScatterResults")//Brushing to Moran ScatterPlot { frmMScatterResults pfrmMScatterPlot = pFormCollection[j] as frmMScatterResults; BrushingToMScatterPlot(pfrmMScatterPlot, pFLayer, featureSelection); } if (pFormCollection[j].Name == "frmCCMapsResults")//Brushing to Moran ScatterPlot { frmCCMapsResults pfrmCCMApsResults = pFormCollection[j] as frmCCMapsResults; BrushingToCCMaps(pfrmCCMApsResults, pFLayer, featureSelection); } if (pFormCollection[j].Name == "frmBoxCox")//Brushing to Box-Cox transformation tool { frmBoxCox pfrmBoxCox = pFormCollection[j] as frmBoxCox; BrushingToBoxCox(pfrmBoxCox, pFLayer, featureSelection); } if (pFormCollection[j].Name == "frmCorrelogram_local")//Brushing to Correlogram { frmCorrelogram_local pfrmCorrelogram = pFormCollection[j] as frmCorrelogram_local; BrushingToCorrelogram(pfrmCorrelogram, pFLayer, featureSelection); } } } } } catch (Exception ex) { MessageBox.Show("Exception:" + ex.Message); return; } }
public void CloseAllRelatedPlots(IFeatureLayer pFLayer) { //try //{ FormCollection pFormCollection = System.Windows.Forms.Application.OpenForms; List <int> lstPlotIdx = new List <int>(); for (int j = 0; j < pFormCollection.Count; j++) { if (pFormCollection[j].Name == "frmHistResults")//Brushing to Histogram { frmHistResults pfrmHistResults = pFormCollection[j] as frmHistResults; if (pfrmHistResults.pFLayer == pFLayer) { lstPlotIdx.Add(j); } } if (pFormCollection[j].Name == "frmScatterPlotResults") //Brushing to Scatterplot { frmScatterPlotResults pfrmPointsPlot = pFormCollection[j] as frmScatterPlotResults; if (pfrmPointsPlot.m_pFLayer == pFLayer) { lstPlotIdx.Add(j); } } if (pFormCollection[j].Name == "frmQQPlotResults") //Brushing to QQPlot { frmQQPlotResults pfrmQQPlotResult = pFormCollection[j] as frmQQPlotResults; if (pfrmQQPlotResult.m_pFLayer == pFLayer) { lstPlotIdx.Add(j); } } if (pFormCollection[j].Name == "frmAttributeTable")//Brushing to AttributeTable { frmAttributeTable pfrmAttTable = pFormCollection[j] as frmAttributeTable; if (pfrmAttTable.m_pLayer == (ILayer)pFLayer) { lstPlotIdx.Add(j); } } if (pFormCollection[j].Name == "frmBoxPlotResults")//Brushing to AttributeTable { frmBoxPlotResults pfrmBoxPlotResult = pFormCollection[j] as frmBoxPlotResults; if (pfrmBoxPlotResult.pFLayer == pFLayer) { lstPlotIdx.Add(j); } } //if (pFormCollection[j].Name == "frmClassificationGraph")//Brushing to Optiize Graph //{ // frmClassificationGraph pfrmClassGraph = pFormCollection[j] as frmClassificationGraph; // BrushingToOptimizeGraph(pfrmClassGraph, pFLayer, featureSelection); //} //if (pFormCollection[j].Name == "frmCSDesign")//Brushing to CS Graph //{ // frmCSDesign pfrmCSDesign = pFormCollection[j] as frmCSDesign; // if (pfrmCSDesign.pFLayer == pFLayer) // lstPlotIdx.Add(j); //} if (pFormCollection[j].Name == "frmMScatterResults")//Brushing to Moran ScatterPlot { frmMScatterResults pfrmMScatterPlot = pFormCollection[j] as frmMScatterResults; if (pfrmMScatterPlot.m_pFLayer == pFLayer) { lstPlotIdx.Add(j); } } if (pFormCollection[j].Name == "frmCorrelogram_local")//Brushing to Correlogram { frmCorrelogram_local pfrmCorrelogram = pFormCollection[j] as frmCorrelogram_local; if (pfrmCorrelogram.m_pFLayer == pFLayer) { lstPlotIdx.Add(j); } } } lstPlotIdx.Sort(); for (int j = lstPlotIdx.Count - 1; j >= 0; j--) { pFormCollection[lstPlotIdx[j]].Close(); } //} //catch (Exception ex) //{ // MessageBox.Show("Exception:" + ex.Message); // return; //} }
public int RemoveBrushing(MainForm mForm, IFeatureLayer pFLayer) { try { FormCollection pFormCollection = System.Windows.Forms.Application.OpenForms; IActiveView pActiveView = mForm.axMapControl1.ActiveView; int intFormCnt = 0; if (pFLayer.Visible) { //Brushing to Mapcontrol string ShapeFieldName = pFLayer.FeatureClass.ShapeFieldName; //IFeatureSelection featureSelection = (IFeatureSelection)pFLayer; for (int j = 0; j < pFormCollection.Count; j++) { if (pFormCollection[j].Name == "frmHistResults")//Brushing to Histogram { frmHistResults pfrmHistResults = pFormCollection[j] as frmHistResults; if (pfrmHistResults.pFLayer == pFLayer) { intFormCnt++; } } if (pFormCollection[j].Name == "frmScatterPlotResults") //Brushing to Scatterplot { frmScatterPlotResults pfrmPointsPlot = pFormCollection[j] as frmScatterPlotResults; if (pfrmPointsPlot.m_pFLayer == pFLayer) { intFormCnt++; } } if (pFormCollection[j].Name == "frmQQPlotResults") //Brushing to QQPlot { frmQQPlotResults pfrmQQPlotResult = pFormCollection[j] as frmQQPlotResults; if (pfrmQQPlotResult.m_pFLayer == pFLayer) { intFormCnt++; } } if (pFormCollection[j].Name == "frmAttributeTable")//Brushing to AttributeTable { frmAttributeTable pfrmAttTable = pFormCollection[j] as frmAttributeTable; if ((IFeatureLayer)pfrmAttTable.m_pLayer == pFLayer) { intFormCnt++; } } if (pFormCollection[j].Name == "frmBoxPlotResults")//Brushing to AttributeTable { frmBoxPlotResults pfrmBoxPlotResult = pFormCollection[j] as frmBoxPlotResults; if (pfrmBoxPlotResult.pFLayer == pFLayer) { intFormCnt++; } } //if (pFormCollection[j].Name == "frmClassificationGraph")//Brushing to Optiize Graph //{ // frmClassificationGraph pfrmClassGraph = pFormCollection[j] as frmClassificationGraph; // if (pfrmClassGraph.m_pFLayer == pFLayer) // intFormCnt++; //} if (pFormCollection[j].Name == "frmMScatterResults")//Brushing to Moran ScatterPlot { frmMScatterResults pfrmMScatterPlot = pFormCollection[j] as frmMScatterResults; if (pfrmMScatterPlot.m_pFLayer == pFLayer) { intFormCnt++; } } } return(intFormCnt); } else { return(-1); } } catch (Exception ex) { MessageBox.Show("Exception:" + ex.Message); return(-1); } }
private void btnBoxplot_Click(object sender, EventArgs e) { try { string strTargetLayerName = cboTargetLayer.Text; string strFieldName = cboFieldName.Text; string strGroupFieldName = cboGroupField.Text; int intTargetIndex = m_pSnippet.GetIndexNumberFromLayerName(m_pActiveView, strTargetLayerName); int intNFeatureCount = 0; ILayer pTargetLayer = m_pForm.axMapControl1.get_Layer(intTargetIndex); IFeatureLayer pTargetFLayer = (IFeatureLayer)pTargetLayer; //Extract geometry from selected feature IFeatureCursor pFCursor = null; pFCursor = pTargetFLayer.Search(null, true); intNFeatureCount = pTargetFLayer.FeatureClass.FeatureCount(null); int intFieldIdx = pTargetFLayer.FeatureClass.Fields.FindField(strFieldName); int intGroupIdx = pTargetFLayer.FeatureClass.Fields.FindField(strGroupFieldName); System.Collections.Generic.List <object> uvList = new System.Collections.Generic.List <object>(); ICursor ipCursor = pFCursor as ICursor; IRow ipRow = ipCursor.NextRow(); while (ipRow != null) { object curValue = ipRow.get_Value(intGroupIdx); if (!uvList.Contains(curValue)) { uvList.Add(curValue); } ipRow = ipCursor.NextRow(); } uvList.Sort(); //Add exeption for sorting //0421 HK //1. H L M if (uvList.Count == 3) { if (uvList[0].ToString() == "H" && uvList[1].ToString() == "L" && uvList[2].ToString() == "M") { uvList.Clear(); uvList.Add("L"); uvList.Add("M"); uvList.Add("H"); } if (uvList[0].ToString() == "High" && uvList[1].ToString() == "Low" && uvList[2].ToString() == "Medium") { uvList.Clear(); uvList.Add("Low"); uvList.Add("Medium"); uvList.Add("High"); } } ipCursor.Flush(); int intNGroups = uvList.Count; double[,] adbBPStats = new double[5, uvList.Count]; double[,] adbQuantiles = new double[5, uvList.Count]; IQueryFilter pQfilter = new QueryFilterClass(); double[][] adblTarget = new double[intNGroups][]; int[] aintNCounts = new int[intNGroups]; int i = 0; foreach (string uvValue in uvList) { pQfilter.WhereClause = strGroupFieldName + " = '" + uvValue + "'"; pFCursor = pTargetFLayer.Search(pQfilter, true); IFeature pFeature = pFCursor.NextFeature(); intNFeatureCount = pTargetFLayer.FeatureClass.FeatureCount(pQfilter); aintNCounts[i] = intNFeatureCount; adblTarget[i] = new double[intNFeatureCount]; int j = 0; while (pFeature != null) { adblTarget[i][j] = Convert.ToDouble(pFeature.get_Value(intFieldIdx)); j++; pFeature = pFCursor.NextFeature(); } pFCursor.Flush(); i++; } frmBoxPlotResults pfrmBoxplotResults = new frmBoxPlotResults(); pfrmBoxplotResults.Text = "Violin plot of " + pTargetFLayer.Name; pfrmBoxplotResults.pChart.Series.Clear(); ChartArea area = pfrmBoxplotResults.pChart.ChartAreas[0]; int intMaxFeatureNCount = aintNCounts.Max(); //Draw Lines for (int k = 0; k < intNGroups; k++) { string strNumbering = k.ToString(); double[] adblStats = new double[5]; adblStats = BoxPlotStats(adblTarget[k]); for (int l = 0; l < 5; l++) { adbQuantiles[l, k] = adblStats[l]; } int intXvalue = k * 2 + 1; double dblXmin = Convert.ToDouble(intXvalue) - 0.2; double dblXmax = Convert.ToDouble(intXvalue) + 0.2; double dblXBoxMin = Convert.ToDouble(intXvalue) - 0.1; double dblXBoxMax = Convert.ToDouble(intXvalue) + 0.1; //AddLineSeries(pfrmBoxplotResults, "min_" + strNumbering, Color.Black, 1, ChartDashStyle.Solid, dblXmin, dblXmax, adbQuantiles[0, k], adbQuantiles[0, k]); AddLineSeries(pfrmBoxplotResults, "BoxBottom_" + strNumbering, Color.Black, 1, ChartDashStyle.Solid, dblXBoxMin, dblXBoxMax, adbQuantiles[1, k], adbQuantiles[1, k]); AddLineSeries(pfrmBoxplotResults, "BoxLeft_" + strNumbering, Color.Black, 1, ChartDashStyle.Solid, dblXBoxMin, dblXBoxMin, adbQuantiles[1, k], adbQuantiles[3, k]); AddLineSeries(pfrmBoxplotResults, "BoxRight_" + strNumbering, Color.Black, 1, ChartDashStyle.Solid, dblXBoxMax, dblXBoxMax, adbQuantiles[1, k], adbQuantiles[3, k]); AddLineSeries(pfrmBoxplotResults, "Boxup_" + strNumbering, Color.Black, 1, ChartDashStyle.Solid, dblXBoxMin, dblXBoxMax, adbQuantiles[3, k], adbQuantiles[3, k]); AddLineSeries(pfrmBoxplotResults, "median_" + strNumbering, Color.Red, 2, ChartDashStyle.Solid, dblXmin, dblXmax, adbQuantiles[2, k], adbQuantiles[2, k]); //AddLineSeries(pfrmBoxplotResults, "max_" + strNumbering, Color.Black, 1, ChartDashStyle.Solid, dblXmin, dblXmax, adbQuantiles[4, k], adbQuantiles[4, k]); //AddLineSeries(pfrmBoxplotResults, "verDown_" + strNumbering, Color.Black, 1, ChartDashStyle.Dash, intXvalue, intXvalue, adbQuantiles[0, k], adbQuantiles[1, k]); //AddLineSeries(pfrmBoxplotResults, "verUp_" + strNumbering, Color.Black, 1, ChartDashStyle.Dash, intXvalue, intXvalue, adbQuantiles[3, k], adbQuantiles[4, k]); AddLineSeries(pfrmBoxplotResults, "ver_" + strNumbering, Color.Black, 1, ChartDashStyle.Dash, intXvalue, intXvalue, adbQuantiles[0, k], adbQuantiles[4, k]); //Draw Violin Plot var pviolin = new System.Windows.Forms.DataVisualization.Charting.Series { Name = "vio1_" + strNumbering, Color = Color.Black, BorderColor = Color.Black, IsVisibleInLegend = false, ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line }; pfrmBoxplotResults.pChart.Series.Add(pviolin); double dblBandwidth = RuleofThumb(adblTarget[k]); double[,] adblViolinStats = ViolinPlot(adblTarget[k], dblBandwidth); int intChartLenth = (adblViolinStats.Length) / 2; pviolin.Points.AddXY(intXvalue, adblViolinStats[0, 0]); for (int l = 0; l < intChartLenth; l++) { pviolin.Points.AddXY(intXvalue - adblViolinStats[l, 1], adblViolinStats[l, 0]); } pviolin.Points.AddXY(intXvalue, adblViolinStats[intChartLenth - 1, 0]); for (int l = intChartLenth - 1; l >= 0; l--) { pviolin.Points.AddXY(intXvalue + adblViolinStats[l, 1], adblViolinStats[l, 0]); } pviolin.Points.AddXY(intXvalue, adblViolinStats[0, 0]); //for (int l = 0; l < intChartLenth; l++) //{ // if (adblViolinStats[l, 0] > adblStats[0] && adblViolinStats[l, 0] < adblStats[4]) // pviolin.Points.AddXY(intXvalue - adblViolinStats[l, 1], adblViolinStats[l, 0]); //} //if (adblViolinStats[intChartLenth - 1, 0] < adblStats[4]) // pviolin.Points.AddXY(intXvalue, adblStats[4]); //else // pviolin.Points.AddXY(intXvalue, adblStats[4]); //for (int l = intChartLenth - 1; l >= 0; l--) // if (adblViolinStats[l, 0] > adblStats[0] && adblViolinStats[l, 0] < adblStats[4]) // pviolin.Points.AddXY(intXvalue + adblViolinStats[l, 1], adblViolinStats[l, 0]); //if (adblViolinStats[0, 0] > adblStats[0]) // pviolin.Points.AddXY(intXvalue, adblViolinStats[0, 0]); //else // pviolin.Points.AddXY(intXvalue, adblStats[0]); } //Add Points System.Drawing.Color pMarkerColor = System.Drawing.Color.Blue; var seriesOutPts = new System.Windows.Forms.DataVisualization.Charting.Series { Name = "Points", Color = pMarkerColor, BorderColor = pMarkerColor, IsVisibleInLegend = false, IsXValueIndexed = false, ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point, MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle }; pfrmBoxplotResults.pChart.Series.Add(seriesOutPts); for (int k = 0; k < intNGroups; k++) { int intXvalue = k * 2 + 1; foreach (double dblValue in adblTarget[k]) { //if (dblValue < adbQuantiles[1, k] || dblValue > adbQuantiles[3, k]) seriesOutPts.Points.AddXY(intXvalue, dblValue); } } pMarkerColor = System.Drawing.Color.Black; var seriesInPts = new System.Windows.Forms.DataVisualization.Charting.Series { Name = "InPoints", Color = pMarkerColor, BorderColor = pMarkerColor, IsVisibleInLegend = false, IsXValueIndexed = false, ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point, MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle }; pfrmBoxplotResults.pChart.Series.Add(seriesInPts); for (int k = 0; k < intNGroups; k++) { int intXvalue = k * 2 + 1; foreach (double dblValue in adblTarget[k]) { if (dblValue >= adbQuantiles[0, k] && dblValue <= adbQuantiles[4, k]) { seriesInPts.Points.AddXY(intXvalue, dblValue); } } } //Store variables in frmBoxPlotResults pfrmBoxplotResults.mForm = m_pForm; pfrmBoxplotResults.pActiveView = m_pActiveView; pfrmBoxplotResults.pFLayer = pTargetFLayer; pfrmBoxplotResults.strFieldName = strFieldName; pfrmBoxplotResults.strGroupFieldName = strGroupFieldName; pfrmBoxplotResults.uvList = uvList; //pfrmBoxplotResults.pFillColor = pFillColor; pfrmBoxplotResults.adbQuantiles = adbQuantiles; pfrmBoxplotResults.pChart.ChartAreas[0].AxisX.Title = strGroupFieldName; pfrmBoxplotResults.pChart.ChartAreas[0].AxisY.Title = strFieldName; pfrmBoxplotResults.pChart.ChartAreas[0].AxisY.IsStartedFromZero = false; pfrmBoxplotResults.pChart.ChartAreas[0].AxisX.Maximum = intNGroups * 2; pfrmBoxplotResults.pChart.ChartAreas[0].AxisX.Interval = 2; pfrmBoxplotResults.pChart.ChartAreas[0].AxisX.Minimum = 0; pfrmBoxplotResults.pChart.ChartAreas[0].AxisX.IntervalOffset = -1; pfrmBoxplotResults.pChart.ChartAreas[0].AxisX.IsLabelAutoFit = false; for (int n = 0; n < uvList.Count; n++) { int intXvalue = n * 2 + 1; double dblXmin = Convert.ToDouble(intXvalue) - 0.6; double dblXmax = Convert.ToDouble(intXvalue) + 0.6; CustomLabel pcutsomLabel = new CustomLabel(); pcutsomLabel.FromPosition = dblXmin; pcutsomLabel.ToPosition = dblXmax; pcutsomLabel.Text = uvList[n].ToString(); pfrmBoxplotResults.pChart.ChartAreas[0].AxisX.CustomLabels.Add(pcutsomLabel); } pfrmBoxplotResults.Show(); } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }