private void btnSummary_Click(object sender, EventArgs e) { try { frmProgress pfrmProgress = new frmProgress(); pfrmProgress.lblStatus.Text = "Processing:"; pfrmProgress.pgbProgress.Style = ProgressBarStyle.Marquee; pfrmProgress.Show(); int nFeature = m_pFClass.FeatureCount(null); double dblAdvancedValue = Convert.ToDouble(nudAdvanced.Value); //Plot command for R StringBuilder plotCommmand = new StringBuilder(); //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.ExploreSpatialWeightMatrix1(m_pEngine, m_pFClass, txtSWM.Text, pfrmProgress, dblAdvancedValue, chkCumulate.Checked); } else if (m_pFClass.ShapeType == esriGeometryType.esriGeometryPoint) { m_pEngine.Evaluate("sample.shp <- readShapePoints('" + strNameR + "')"); intSuccess = m_pSnippet.ExploreSpatialWeightMatrixPts(m_pEngine, m_pFClass, txtSWM.Text, pfrmProgress, dblAdvancedValue, chkCumulate.Checked, m_pClippedPolygon); } 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 variable index int intFIDIdx = m_pFClass.FindField(m_pFClass.OIDFieldName); // Collect FIDs to apply Brushing and Linking 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(); arrFID[i] = Convert.ToInt32(pFeature.get_Value(intFIDIdx)); i++; pFeature = pFCursor.NextFeature(); } pFCursor.Flush(); //Save Def_SWM clsSnippet.Def_SpatialWeightsMatrix pDefSWM = new clsSnippet.Def_SpatialWeightsMatrix(); pDefSWM.Geometry = m_pFClass.ShapeType; pDefSWM.Definition = txtSWM.Text; pDefSWM.AdvancedValue = dblAdvancedValue; pDefSWM.Cumulative = chkCumulate.Checked; pDefSWM.Subset = m_blnSubset; pDefSWM.FIDs = arrFID; pDefSWM.NBIDs = NBIDs; pDefSWM.XYCoord = m_arrXYCoord; m_pEngine.Evaluate("c.nb <- card(sample.nb)"); pDefSWM.FeatureCount = nFeature; pDefSWM.NeighborCounts = m_pEngine.Evaluate("c.nb").AsNumeric().ToArray(); pDefSWM.NonZeroLinkCount = Convert.ToInt32(pDefSWM.NeighborCounts.Sum()); pDefSWM.PercentNonZeroWeight = Convert.ToDouble(pDefSWM.NonZeroLinkCount) / Math.Pow(nFeature, 2) * 100; pDefSWM.AverageNumberofLink = pDefSWM.NeighborCounts.Average(); //For higher order; if (m_pFClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon) { if (dblAdvancedValue > 1) { int intMaxLag = Convert.ToInt32(dblAdvancedValue); pDefSWM.LinkCountforHigher = new double[intMaxLag]; pDefSWM.AverageforHigher = new double[intMaxLag]; for (int j = 0; j < intMaxLag; j++) { m_pEngine.Evaluate("h.nb <- card(sample.nblags[[" + (j + 1).ToString() + "]])"); pDefSWM.LinkCountforHigher[j] = m_pEngine.Evaluate("sum(h.nb)").AsNumeric().First(); pDefSWM.AverageforHigher[j] = m_pEngine.Evaluate("mean(h.nb)").AsNumeric().First(); } } } frmSWMSummary pSMWSummary = new frmSWMSummary(); pSMWSummary.Def_SWM = pDefSWM; pSMWSummary.txtLayer.Text = m_pFLayer.Name; pSMWSummary.m_pFLayer = m_pFLayer; pSMWSummary.Show(); pfrmProgress.Close(); } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }