private void btnRun_Click(object sender, EventArgs e) { try { frmProgress pfrmProgress = new frmProgress(); pfrmProgress.lblStatus.Text = "Processing:"; pfrmProgress.pgbProgress.Style = ProgressBarStyle.Marquee; pfrmProgress.Show(); if (cboFldNm1.Text == "") { MessageBox.Show("Please select a proper field"); return; } // Creates the input and output matrices from the shapefile// //string strLayerName = cboTargetLayer.Text; //int intLIndex = m_pSnippet.GetIndexNumberFromLayerName(m_pActiveView, strLayerName); //ILayer pLayer = m_pForm.axMapControl1.get_Layer(intLIndex); //IFeatureLayer pFLayer = pLayer as IFeatureLayer; //pFClass = pFLayer.FeatureClass; int nFeature = m_pFClass.FeatureCount(null); //Plot command for R StringBuilder plotCommmand = new StringBuilder(); if (!m_blnCreateSWM) { //Get the file path and name to create spatial weight matrix string strNameR = m_pSnippet.FilePathinRfromLayer(m_pFLayer); if (strNameR == null) { return; } //Create spatial weight matrix in R if (m_pFClass.ShapeType == esriGeometryType.esriGeometryPolygon) { m_pEngine.Evaluate("sample.shp <- readShapePoly('" + strNameR + "')"); } else if (m_pFClass.ShapeType == esriGeometryType.esriGeometryPoint) { m_pEngine.Evaluate("sample.shp <- readShapePoints('" + strNameR + "')"); } else { MessageBox.Show("This geometry type is not supported"); pfrmProgress.Close(); this.Close(); } int intSuccess = m_pSnippet.CreateSpatialWeightMatrix(m_pEngine, m_pFClass, txtSWM.Text, pfrmProgress); if (intSuccess == 0) { return; } } ////Get the file path and name to create spatial weight matrix //string strNameR = m_pSnippet.FilePathinRfromLayer(m_pFLayer); //if (strNameR == null) // return; //int intSuccess = 0; ////Create spatial weight matrix in R //if (m_pFClass.ShapeType == esriGeometryType.esriGeometryPolygon) //{ // m_pEngine.Evaluate("sample.shp <- readShapePoly('" + strNameR + "')"); // intSuccess = m_pSnippet.CreateSpatialWeightMatrix1(m_pEngine, m_pFClass, txtSWM.Text, pfrmProgress, Convert.ToDouble(nudAdvanced.Value), chkCumulate.Checked); //} //else if (m_pFClass.ShapeType == esriGeometryType.esriGeometryPoint) //{ // m_pEngine.Evaluate("sample.shp <- readShapePoints('" + strNameR + "')"); // //intSuccess = m_pSnippet.ExploreSpatialWeightMatrix1(m_pEngine, m_pFClass, txtSWM.Text, pfrmProgress, Convert.ToDouble(nudAdvanced.Value), chkCumulate.Checked); // intSuccess = m_pSnippet.CreateSpatialWeightMatrixPts(m_pEngine, m_pFClass, txtSWM.Text, pfrmProgress, Convert.ToDouble(nudAdvanced.Value), chkCumulate.Checked, m_pClippedPolygon); // //chkCumulate.Visible = false; //} //else //{ // MessageBox.Show("This geometry type is not supported"); // pfrmProgress.Close(); // this.Close(); //} //if (intSuccess == 0) // return; IFeatureCursor pFCursor = m_pFClass.Search(null, true); IFeature pFeature = pFCursor.NextFeature(); //Get index for independent and dependent variables //Get variable index string strVarNM = (string)cboFldNm1.SelectedItem; int intVarIdx = m_pFClass.FindField(strVarNM); int intFIDIdx = m_pFClass.FindField(m_pFClass.OIDFieldName); // Collect FIDs to apply Brushing and Linking //Store Variable at Array double[] arrVar = new double[nFeature]; int[] arrFID = new int[nFeature]; int i = 0; m_arrXYCoord = new double[nFeature, 2]; List <int>[] NBIDs = new List <int> [nFeature]; IArea pArea; IPoint pPoint; while (pFeature != null) { if (m_pFClass.ShapeType == esriGeometryType.esriGeometryPolygon) { pArea = (IArea)pFeature.Shape; m_arrXYCoord[i, 0] = pArea.Centroid.X; m_arrXYCoord[i, 1] = pArea.Centroid.Y; } else if (m_pFClass.ShapeType == esriGeometryType.esriGeometryPoint) { pPoint = (IPoint)pFeature.Shape; m_arrXYCoord[i, 0] = pPoint.X; m_arrXYCoord[i, 1] = pPoint.Y; } NBIDs[i] = m_pEngine.Evaluate("sample.nb[[" + (i + 1).ToString() + "]]").AsInteger().ToList(); arrVar[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx)); arrFID[i] = Convert.ToInt32(pFeature.get_Value(intFIDIdx)); i++; pFeature = pFCursor.NextFeature(); } pFCursor.Flush(); //Collect NB for Brushing and linking NumericVector vecVar = m_pEngine.CreateNumericVector(arrVar); m_pEngine.SetSymbol(strVarNM, vecVar); if (chkStd.Checked) { m_pEngine.Evaluate(strVarNM + " <- scale(" + strVarNM + ")"); //Scaled vecVar = m_pEngine.Evaluate(strVarNM).AsNumeric(); } NumericVector vecWeightVar = null; if (cboMethod.Text == "MC") { vecWeightVar = m_pEngine.Evaluate("wx.sample <- lag.listw(sample.listw, " + strVarNM + ", zero.policy=TRUE)").AsNumeric(); } else if (cboMethod.Text == "GR") { string strStartPath = m_pForm.strPath; string pathr = strStartPath.Replace(@"\", @"/"); m_pEngine.Evaluate("source('" + pathr + "/AllFunctions.R')"); vecWeightVar = m_pEngine.Evaluate("wx.sample <- diff.lag.listw(sample.listw, " + strVarNM + ")").AsNumeric(); } else if (cboMethod.Text == "L") { string strStartPath = m_pForm.strPath; string pathr = strStartPath.Replace(@"\", @"/"); m_pEngine.Evaluate("source('" + pathr + "/AllFunctions.R')"); vecWeightVar = m_pEngine.Evaluate("wx.sample <- diff.lag.listw(sample.listw, " + strVarNM + ")").AsNumeric(); } m_pEngine.SetSymbol("WVar.sample", vecWeightVar); //double[] arrWeightVar = vecWeightVar.ToArray(); NumericVector vecCoeff = m_pEngine.Evaluate("lm(WVar.sample~" + strVarNM + ")$coefficients").AsNumeric(); frmMScatterResults pfrmMScatterResult = new frmMScatterResults(); pfrmMScatterResult.m_arrXYCoord = m_arrXYCoord; pfrmMScatterResult.m_NBIDs = NBIDs; pfrmMScatterResult.pChart.ChartAreas[0].AxisX.IsStartedFromZero = false; pfrmMScatterResult.pChart.ChartAreas[0].AxisX.IsMarginVisible = true; pfrmMScatterResult.pChart.ChartAreas[0].AxisY.IsStartedFromZero = false; pfrmMScatterResult.Text = "Moran Scatter Plot of " + m_pFLayer.Name; pfrmMScatterResult.pChart.Series.Clear(); System.Drawing.Color pMarkerColor = System.Drawing.Color.Blue; var seriesPts = 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 }; pfrmMScatterResult.pChart.Series.Add(seriesPts); for (int j = 0; j < vecVar.Length; j++) { seriesPts.Points.AddXY(vecVar[j], vecWeightVar[j]); } var VLine = new System.Windows.Forms.DataVisualization.Charting.Series { Name = "VLine", Color = System.Drawing.Color.Black, BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash, //BorderColor = System.Drawing.Color.Black, IsVisibleInLegend = false, IsXValueIndexed = false, ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line }; pfrmMScatterResult.pChart.Series.Add(VLine); VLine.Points.AddXY(vecVar.Average(), vecWeightVar.Min()); VLine.Points.AddXY(vecVar.Average(), vecWeightVar.Max()); var HLine = new System.Windows.Forms.DataVisualization.Charting.Series { Name = "HLine", Color = System.Drawing.Color.Black, BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash, //BorderColor = System.Drawing.Color.Black, IsVisibleInLegend = false, IsXValueIndexed = false, ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line }; pfrmMScatterResult.pChart.Series.Add(HLine); HLine.Points.AddXY(vecVar.Min(), vecWeightVar.Average()); HLine.Points.AddXY(vecVar.Max(), vecWeightVar.Average()); var seriesLine = new System.Windows.Forms.DataVisualization.Charting.Series { Name = "RegLine", Color = System.Drawing.Color.Red, //BorderColor = System.Drawing.Color.Black, IsVisibleInLegend = false, IsXValueIndexed = false, ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line }; pfrmMScatterResult.pChart.Series.Add(seriesLine); seriesLine.Points.AddXY(vecVar.Min(), vecVar.Min() * vecCoeff[1] + vecCoeff[0]); seriesLine.Points.AddXY(vecVar.Max(), vecVar.Max() * vecCoeff[1] + vecCoeff[0]); if (chkStd.Checked) { pfrmMScatterResult.pChart.ChartAreas[0].AxisX.Title = "standardized " + strVarNM; pfrmMScatterResult.pChart.ChartAreas[0].AxisY.Title = "Spatially lagged standardized " + strVarNM; pfrmMScatterResult.lblRegression.Text = "Spatially lagged standardized " + strVarNM + " = " + vecCoeff[1].ToString("N3") + " * " + "standardized " + strVarNM; } else { pfrmMScatterResult.pChart.ChartAreas[0].AxisX.Title = strVarNM; pfrmMScatterResult.pChart.ChartAreas[0].AxisY.Title = "Spatially lagged " + strVarNM; pfrmMScatterResult.lblRegression.Text = "Spatially lagged " + strVarNM + " = " + vecCoeff[1].ToString("N3") + " * " + strVarNM + " + " + vecCoeff[0].ToString("N3"); } pfrmMScatterResult.m_pForm = m_pForm; pfrmMScatterResult.m_pFLayer = m_pFLayer; pfrmMScatterResult.m_pActiveView = m_pActiveView; pfrmMScatterResult.arrVar = arrVar; pfrmMScatterResult.arrFID = arrFID; pfrmMScatterResult.strFIDNM = m_pFClass.OIDFieldName; //pfrmMScatterResult.arrWeightVar = arrWeightVar; pfrmMScatterResult.pMakerColor = pMarkerColor; pfrmMScatterResult.strVarNM = strVarNM; if (chkStd.Checked) { pfrmMScatterResult.pChart.ChartAreas[0].AxisX.IsLabelAutoFit = false; pfrmMScatterResult.pChart.ChartAreas[0].AxisX.CustomLabels.Clear(); pfrmMScatterResult.pChart.ChartAreas[0].AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; //pfrmMScatterResult.pChart.ChartAreas[0].AxisX.MajorTickMark.Interval = 1; //pfrmMScatterResult.pChart.ChartAreas[0].AxisX.MajorTickMark.IntervalOffset = -2; int intMin = Convert.ToInt32(Math.Floor(vecVar.Min())); int intMax = Convert.ToInt32(Math.Ceiling(vecVar.Max())); for (int n = intMin; n < intMax; n++) { System.Windows.Forms.DataVisualization.Charting.CustomLabel pcutsomLabel = new System.Windows.Forms.DataVisualization.Charting.CustomLabel(); pcutsomLabel.FromPosition = n - 0.5; pcutsomLabel.ToPosition = n + 0.5; pcutsomLabel.Text = n.ToString(); pfrmMScatterResult.pChart.ChartAreas[0].AxisX.CustomLabels.Add(pcutsomLabel); } } pfrmMScatterResult.Show(); pfrmProgress.Close(); //this.Close(); } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }
private void btnRun_Click(object sender, EventArgs e) { if (cboFldnm1.Text == "" || cboFldnm2.Text == "") { MessageBox.Show("Please select target field"); return; } frmProgress pfrmProgress = new frmProgress(); pfrmProgress.lblStatus.Text = "Processing:"; pfrmProgress.pgbProgress.Style = ProgressBarStyle.Marquee; pfrmProgress.Show(); REngine pEngine = m_pForm.pEngine; int nFeature = m_pFClass.FeatureCount(null); IFeatureCursor pFCursor = m_pFClass.Search(null, true); IFeature pFeature = pFCursor.NextFeature(); //Get index for independent and dependent variables //Get variable index string strVarNM1 = (string)cboFldnm1.SelectedItem; string strVarNM2 = (string)cboFldnm2.SelectedItem; int intVarIdx1 = m_pFClass.FindField(strVarNM1); int intVarIdx2 = m_pFClass.FindField(strVarNM2); int intFIDIdx = m_pFClass.FindField(m_pFClass.OIDFieldName); //Store Variable at Array double[] arrVar1 = new double[nFeature]; double[] arrVar2 = new double[nFeature]; int[] arrFID = new int[nFeature]; int i = 0; while (pFeature != null) { arrVar1[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx1)); arrVar2[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx2)); arrFID[i] = Convert.ToInt32(pFeature.get_Value(intFIDIdx)); i++; pFeature = pFCursor.NextFeature(); } pFCursor.Flush(); //Plot command for R StringBuilder plotCommmand = new StringBuilder(); string strStartPath = m_pForm.strPath; string pathr = strStartPath.Replace(@"\", @"/"); pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_LARRY.R')"); pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_neighbor.R')"); pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_SASbi.R')"); //Get the file path and name to create spatial weight matrix string strNameR = m_pSnippet.FilePathinRfromLayer(m_pFLayer); if (strNameR == null) { return; } //Create spatial weight matrix in R pEngine.Evaluate("library(spdep); library(maptools)"); pEngine.Evaluate("sample.shp <- readShapePoly('" + strNameR + "')"); //pEngine.Evaluate("sample.nb <- poly2nb(sample.shp, queen=FALSE)"); pEngine.Evaluate("sample.nb <- poly2nb(sample.shp)"); NumericVector vecVar1 = pEngine.CreateNumericVector(arrVar1); pEngine.SetSymbol("sample.v1", vecVar1); NumericVector vecVar2 = pEngine.CreateNumericVector(arrVar2); pEngine.SetSymbol("sample.v2", vecVar2); string strNonZero = null; if (chkDiagZero.Checked) { strNonZero = "FALSE"; } else { strNonZero = "TRUE"; } string[] strSPQuadrants = null; double[] adblVar1 = null; double[] adblVar2 = null; NumericVector vecCoeff = null; if (cboMeasure.Text == "Lee's L") { pEngine.Evaluate("sample.result <- LARRY.bivariate.quadrant.lee(sample.v1, sample.v2, 1:length(sample.nb), sample.nb, style = 'W', diag.zero = " + strNonZero + ")"); strSPQuadrants = pEngine.Evaluate("as.character(sample.result$quad)").AsCharacter().ToArray(); if (chkScatterplot.Checked) { adblVar1 = pEngine.Evaluate("as.numeric(sample.result$v.z.x)").AsNumeric().ToArray(); adblVar2 = pEngine.Evaluate("as.numeric(sample.result$v.z.y)").AsNumeric().ToArray(); vecCoeff = pEngine.Evaluate("lm(sample.result$v.z.y~sample.result$v.z.x)$coefficients").AsNumeric(); } } else if (cboMeasure.Text == "Local Pearson") { pEngine.Evaluate("sample.result <- LARRY.bivariate.quadrant.pearson(sample.v1, sample.v2, 1:length(sample.nb))"); strSPQuadrants = pEngine.Evaluate("as.character(sample.result$quad)").AsCharacter().ToArray(); if (chkScatterplot.Checked) { adblVar1 = pEngine.Evaluate("as.numeric(sample.result$z.x)").AsNumeric().ToArray(); adblVar2 = pEngine.Evaluate("as.numeric(sample.result$z.y)").AsNumeric().ToArray(); vecCoeff = pEngine.Evaluate("lm(sample.result$z.y~sample.result$z.x)$coefficients").AsNumeric(); } } //Save Output on SHP //Add Target fields to store results in the shapefile // Keep loop for (int j = 0; j < 1; j++) { string strfldName = lvFields.Items[j].SubItems[1].Text; if (m_pFClass.FindField(strfldName) == -1) { IField newField = new FieldClass(); IFieldEdit fieldEdit = (IFieldEdit)newField; fieldEdit.Name_2 = strfldName; fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; m_pFClass.AddField(newField); } } //Update Field pFCursor = m_pFClass.Update(null, false); pFeature = pFCursor.NextFeature(); string strSpQuadFldName = lvFields.Items[0].SubItems[1].Text; int intSpQuadFldIdx = m_pFClass.FindField(strSpQuadFldName); int featureIdx = 0; while (pFeature != null) { pFeature.set_Value(intSpQuadFldIdx, strSPQuadrants[featureIdx]); pFCursor.UpdateFeature(pFeature); pFeature = pFCursor.NextFeature(); featureIdx++; } pFCursor.Flush(); if (chkMap.Checked) { ITable pTable = (ITable)m_pFClass; IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); pUniqueValueRenderer.FieldCount = 1; pUniqueValueRenderer.set_Field(0, strSpQuadFldName); if (cboMaptype.Text == "choropleth map") { ISimpleFillSymbol pSymbol; IQueryFilter pQFilter = new QueryFilterClass(); int intTotalCount = 0; string strLabel = null; for (int j = 0; j < 4; j++) { pSymbol = new SimpleFillSymbolClass(); pSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSymbol.Color = m_pSnippet.getRGB(m_pQuadrantSymbols[j].R, m_pQuadrantSymbols[j].G, m_pQuadrantSymbols[j].B); pQFilter.WhereClause = strSpQuadFldName + " = '" + m_pQuadrantSymbols[j].Value + "'"; intTotalCount = pTable.RowCount(pQFilter); strLabel = m_pQuadrantSymbols[j].Label + " (" + intTotalCount.ToString() + ")"; pUniqueValueRenderer.AddValue(m_pQuadrantSymbols[j].Value, null, (ISymbol)pSymbol); pUniqueValueRenderer.set_Label(m_pQuadrantSymbols[j].Value, strLabel); } pUniqueValueRenderer.UseDefaultSymbol = false; } else if (cboMaptype.Text == "point map") { ICharacterMarkerSymbol pSymbol; stdole.IFontDisp stdFontCls = ((stdole.IFontDisp)(new stdole.StdFont())); stdFontCls.Name = "ESRI NIMA VMAP1&2 PT"; stdFontCls.Size = 10; IQueryFilter pQFilter = new QueryFilterClass(); int intTotalCount = 0; string strLabel = null; for (int j = 0; j < 4; j++) { pSymbol = new CharacterMarkerSymbolClass(); pSymbol.CharacterIndex = 248; //pSymbol.Color = m_pSnippet.getRGB(m_pQuadrantSymbols[j].R, m_pQuadrantSymbols[j].G, m_pQuadrantSymbols[j].B); pSymbol.Size = 10; pSymbol.Font = stdFontCls; pSymbol.Angle = m_pQuadrantSymbols[j].Angle; //Create a Fill Symbol for the Mask ISimpleFillSymbol smpFill = new SimpleFillSymbol(); smpFill.Color = m_pSnippet.getRGB(0, 0, 0); smpFill.Style = esriSimpleFillStyle.esriSFSSolid; //Create a MultiLayerMarkerSymbol IMultiLayerMarkerSymbol multiLyrMrk = new MultiLayerMarkerSymbol(); //Add the simple marker to the MultiLayer multiLyrMrk.AddLayer(pSymbol); //Create a Mask for the MultiLayerMarkerSymbol IMask mrkMask = (IMask)multiLyrMrk; mrkMask.MaskSymbol = smpFill; mrkMask.MaskStyle = esriMaskStyle.esriMSHalo; mrkMask.MaskSize = 0.5; pQFilter.WhereClause = strSpQuadFldName + " = '" + m_pQuadrantSymbols[j].Value + "'"; intTotalCount = pTable.RowCount(pQFilter); strLabel = m_pQuadrantSymbols[j].Label + " (" + intTotalCount.ToString() + ")"; pUniqueValueRenderer.AddValue(m_pQuadrantSymbols[j].Value, null, (ISymbol)multiLyrMrk); pUniqueValueRenderer.set_Label(m_pQuadrantSymbols[j].Value, strLabel); } pUniqueValueRenderer.UseDefaultSymbol = false; } IFeatureLayer pNewFLayer = new FeatureLayerClass(); pNewFLayer.FeatureClass = m_pFClass; pNewFLayer.Name = "Bivariate Spatial Quadrants"; IGeoFeatureLayer pGFLayer = (IGeoFeatureLayer)pNewFLayer; pGFLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer; m_pActiveView.FocusMap.AddLayer(pGFLayer); m_pActiveView.Refresh(); m_pForm.axTOCControl1.Update(); } if (chkScatterplot.Checked) { frmMScatterResults pfrmMScatterResult = new frmMScatterResults(); pfrmMScatterResult.pChart.ChartAreas[0].AxisX.IsStartedFromZero = false; pfrmMScatterResult.pChart.ChartAreas[0].AxisX.IsMarginVisible = true; pfrmMScatterResult.pChart.ChartAreas[0].AxisY.IsStartedFromZero = false; pfrmMScatterResult.Text = cboMeasure.Text + " Scatter Plot of " + m_pFLayer.Name; pfrmMScatterResult.pChart.Series.Clear(); System.Drawing.Color pMarkerColor = System.Drawing.Color.Blue; var seriesPts = 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 }; pfrmMScatterResult.pChart.Series.Add(seriesPts); for (int j = 0; j < adblVar1.Length; j++) { seriesPts.Points.AddXY(adblVar1[j], adblVar2[j]); } var VLine = new System.Windows.Forms.DataVisualization.Charting.Series { Name = "VLine", Color = System.Drawing.Color.Black, BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash, //BorderColor = System.Drawing.Color.Black, IsVisibleInLegend = false, IsXValueIndexed = false, ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line }; pfrmMScatterResult.pChart.Series.Add(VLine); VLine.Points.AddXY(adblVar1.Average(), adblVar2.Min()); VLine.Points.AddXY(adblVar1.Average(), adblVar2.Max()); var HLine = new System.Windows.Forms.DataVisualization.Charting.Series { Name = "HLine", Color = System.Drawing.Color.Black, BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash, //BorderColor = System.Drawing.Color.Black, IsVisibleInLegend = false, IsXValueIndexed = false, ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line }; pfrmMScatterResult.pChart.Series.Add(HLine); HLine.Points.AddXY(adblVar1.Min(), adblVar2.Average()); HLine.Points.AddXY(adblVar1.Max(), adblVar2.Average()); var seriesLine = new System.Windows.Forms.DataVisualization.Charting.Series { Name = "RegLine", Color = System.Drawing.Color.Red, //BorderColor = System.Drawing.Color.Black, IsVisibleInLegend = false, IsXValueIndexed = false, ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line }; pfrmMScatterResult.pChart.Series.Add(seriesLine); seriesLine.Points.AddXY(adblVar1.Min(), adblVar1.Min() * vecCoeff[1] + vecCoeff[0]); seriesLine.Points.AddXY(adblVar1.Max(), adblVar1.Max() * vecCoeff[1] + vecCoeff[0]); if (cboMeasure.Text == "Local Pearson") { pfrmMScatterResult.pChart.ChartAreas[0].AxisX.Title = "z-transformed " + cboFldnm1.Text; pfrmMScatterResult.pChart.ChartAreas[0].AxisY.Title = "z-transformed " + cboFldnm2.Text; pfrmMScatterResult.lblRegression.Text = string.Empty; } else { pfrmMScatterResult.pChart.ChartAreas[0].AxisX.Title = "z-transformed SMA of " + cboFldnm1.Text; pfrmMScatterResult.pChart.ChartAreas[0].AxisY.Title = "z-transformed SMA of " + cboFldnm2.Text; pfrmMScatterResult.lblRegression.Text = string.Empty; } pfrmMScatterResult.m_pForm = m_pForm; pfrmMScatterResult.m_pFLayer = m_pFLayer; pfrmMScatterResult.m_pActiveView = m_pActiveView; pfrmMScatterResult.arrVar = adblVar1; pfrmMScatterResult.arrFID = arrFID; pfrmMScatterResult.strFIDNM = m_pFClass.OIDFieldName; //pfrmMScatterResult.arrWeightVar = arrWeightVar; pfrmMScatterResult.pMakerColor = pMarkerColor; pfrmMScatterResult.strVarNM = cboFldnm1.Text; pfrmMScatterResult.pChart.ChartAreas[0].AxisX.IsLabelAutoFit = false; pfrmMScatterResult.pChart.ChartAreas[0].AxisX.CustomLabels.Clear(); pfrmMScatterResult.pChart.ChartAreas[0].AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; //pfrmMScatterResult.pChart.ChartAreas[0].AxisX.MajorTickMark.Interval = 1; //pfrmMScatterResult.pChart.ChartAreas[0].AxisX.MajorTickMark.IntervalOffset = -2; int intMin = Convert.ToInt32(Math.Floor(adblVar1.Min())); int intMax = Convert.ToInt32(Math.Ceiling(adblVar1.Max())); for (int n = intMin; n < intMax; n++) { System.Windows.Forms.DataVisualization.Charting.CustomLabel pcutsomLabel = new System.Windows.Forms.DataVisualization.Charting.CustomLabel(); pcutsomLabel.FromPosition = n - 0.5; pcutsomLabel.ToPosition = n + 0.5; pcutsomLabel.Text = n.ToString(); pfrmMScatterResult.pChart.ChartAreas[0].AxisX.CustomLabels.Add(pcutsomLabel); } pfrmMScatterResult.Show(); } pfrmProgress.Close(); }
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 BrushingToMScatterPlot(frmMScatterResults pfrmMScatterResults, IFeatureLayer pFLayer, IFeatureSelection featureSelection) { try { if (pfrmMScatterResults.m_pFLayer == pFLayer) { IFeatureClass pFeatureClass = pFLayer.FeatureClass; //int intVarIdx = pFeatureClass.Fields.FindField(pfrmMScatterResults.strVarNM); int intFIDIdx = pFeatureClass.FindField(pFeatureClass.OIDFieldName); ICursor pCursor = null; featureSelection.SelectionSet.Search(null, false, out pCursor); IRow pRow = pCursor.NextRow(); //IFeature pFeature = pFCursor.NextFeature(); int dblOriPtsSize = pfrmMScatterResults.pChart.Series[0].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 }; //Clear previous selection int intLastSeriesIdx = pfrmMScatterResults.pChart.Series.Count - 1; //Remove Previous Selection if (pfrmMScatterResults.pChart.Series[intLastSeriesIdx].Name == "SelPoints") { pfrmMScatterResults.pChart.Series.RemoveAt(intLastSeriesIdx); } pfrmMScatterResults.pChart.Series.Add(seriesPts); while (pRow != null) { //double dblSelVar = Convert.ToDouble(pRow.get_Value(intVarIdx)); //for (int i = 0; i < pfrmMScatterResults.pChart.Series[0].Points.Count; i++) //{ // if (dblSelVar == pfrmMScatterResults.pChart.Series[0].Points[i].XValue) // { // double dblWeightVar = pfrmMScatterResults.pChart.Series[0].Points[i].YValues[0]; // seriesPts.Points.AddXY(dblSelVar, dblWeightVar); // } //} int intSelFID = Convert.ToInt32(pRow.get_Value(intFIDIdx)); for (int i = 0; i < pfrmMScatterResults.arrFID.Length; i++) { if (intSelFID == pfrmMScatterResults.arrFID[i]) { seriesPts.Points.AddXY(pfrmMScatterResults.pChart.Series[0].Points[i].XValue, pfrmMScatterResults.pChart.Series[0].Points[i].YValues[0]); } } 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); } }