예제 #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                string strLayerName = cboLayer.Text;
                string strFieldType = cboType.Text;
                string strFieldName = txtName.Text;

                if (strLayerName == "" || strFieldType == "" || strFieldName == "")
                {
                    MessageBox.Show("Please select variables");
                }

                clsBlockNames pBlockNames = new clsBlockNames();
                if (pBlockNames.BlockPreDeterminedName(strFieldName))
                {
                    return;
                }

                int    intLIndex = pSnippet.GetIndexNumberFromLayerName(pActiveView, strLayerName);
                ILayer pLayer    = mForm.axMapControl1.get_Layer(intLIndex);

                IFeatureLayer pFLayer   = pLayer as IFeatureLayer;
                IFeatureClass pFClass   = pFLayer.FeatureClass;
                int           intFldIdx = pFClass.FindField(strFieldName);
                if (intFldIdx != -1)
                {
                    MessageBox.Show("The field name is already assigned.");
                    return;
                }

                AddField(pFClass, strFieldName, strFieldType);
                MessageBox.Show("Done");

                if (intHandle != IntPtr.Zero)
                {
                    frmAttributeTable pfrmAttributeTable = pSnippet.returnAttTable(intHandle);
                    if (pfrmAttributeTable == null)
                    {
                        return;
                    }
                    pSnippet.LoadingAttributeTable(pLayer, pfrmAttributeTable);
                }

                this.Close();
            }
            catch (Exception ex)
            {
                frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
                return;
            }
        }
예제 #2
0
        //private void BrushingToOptimizeGraph(frmClassificationGraph pfrmClassGraph, IFeatureLayer pFLayer, IFeatureSelection featureSelection)
        //{
        //    try
        //    {
        //        if (pfrmClassGraph.m_pFLayer == pFLayer)
        //        {
        //            IFeatureClass pFeatureClass = pFLayer.FeatureClass;
        //            int intVar1Idx = pFeatureClass.Fields.FindField(pfrmClassGraph.strValueFldName);

        //            int intLastSeriesIdx = pfrmClassGraph.pChart.Series.Count - 1;

        //            //Remove Previous Selection
        //            if (pfrmClassGraph.pChart.Series[intLastSeriesIdx].Name == "SelSeries")
        //                pfrmClassGraph.pChart.Series.RemoveAt(intLastSeriesIdx);

        //            ICursor pCursor = null;
        //            featureSelection.SelectionSet.Search(null, false, out pCursor);
        //            int selCnties = featureSelection.SelectionSet.Count;

        //            IRow pRow = pCursor.NextRow();
        //            //IFeature pFeature = pFCursor.NextFeature();

        //            //int dblOriPtsSize = pfrmClassGraph.pChart.Series[0].MarkerSize;

        //            //System.Drawing.Color pMarkerColor = System.Drawing.Color.Red;
        //            var Selseries = new System.Windows.Forms.DataVisualization.Charting.Series
        //            {
        //                Name = "SelSeries",
        //                Color = System.Drawing.Color.Red,
        //                BorderColor = System.Drawing.Color.Black,
        //                BackHatchStyle = ChartHatchStyle.DiagonalCross,
        //                IsVisibleInLegend = false,
        //                ChartType = SeriesChartType.Column,
        //            };


        //            pfrmClassGraph.pChart.Series.Add(Selseries);

        //            while (pRow != null)
        //            {
        //                double dblEstValue = Convert.ToDouble(pRow.get_Value(intVar1Idx));
        //                for (int i = 0; i < pfrmClassGraph.pChart.Series[0].Points.Count; i++)
        //                {
        //                    double dblYValue = pfrmClassGraph.pChart.Series[0].Points[i].YValues[0] + pfrmClassGraph.pChart.Series[1].Points[i].YValues[0];
        //                    if (dblEstValue == dblYValue)
        //                    {
        //                        double dblSelYValue = pfrmClassGraph.pChart.Series[0].Points[i].YValues[0] + pfrmClassGraph.pChart.Series[1].Points[i].YValues[0] + pfrmClassGraph.pChart.Series[2].Points[i].YValues[0];
        //                        Selseries.Points.AddXY(pfrmClassGraph.pChart.Series[0].Points[i].XValue, dblSelYValue);
        //                    }
        //                }
        //                pRow = pCursor.NextRow();
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show("Exception:" + ex.Message);
        //        return;
        //    }
        //}
        //private void BrushingToClassSepGraph(frmCSDesign pfrmCSDesign, IFeatureLayer pFLayer, IFeatureSelection featureSelection)
        //{
        //    try
        //    {
        //        if (pfrmCSDesign.pFLayer == pFLayer)
        //        {
        //            IFeatureClass pFeatureClass = pFLayer.FeatureClass;
        //            int intVar1Idx = pFeatureClass.Fields.FindField(pfrmCSDesign.strValueFldName);

        //            int intLastSeriesIdx = pfrmCSDesign.pChart.Series.Count - 1;

        //            //Remove Previous Selection
        //            if (pfrmCSDesign.pChart.Series[intLastSeriesIdx].Name == "SelSeries")
        //                pfrmCSDesign.pChart.Series.RemoveAt(intLastSeriesIdx);

        //            ICursor pCursor = null;
        //            featureSelection.SelectionSet.Search(null, false, out pCursor);
        //            int selCnties = featureSelection.SelectionSet.Count;

        //            IRow pRow = pCursor.NextRow();
        //            //IFeature pFeature = pFCursor.NextFeature();

        //            //int dblOriPtsSize = pfrmClassGraph.pChart.Series[0].MarkerSize;

        //            //System.Drawing.Color pMarkerColor = System.Drawing.Color.Red;
        //            var Selseries = new System.Windows.Forms.DataVisualization.Charting.Series
        //            {
        //                Name = "SelSeries",
        //                Color = System.Drawing.Color.Red,
        //                BorderColor = System.Drawing.Color.Black,
        //                BackHatchStyle = ChartHatchStyle.DiagonalCross,
        //                IsVisibleInLegend = false,
        //                ChartType = SeriesChartType.Column,
        //            };


        //            pfrmCSDesign.pChart.Series.Add(Selseries);

        //            while (pRow != null)
        //            {
        //                double dblEstValue = Convert.ToDouble(pRow.get_Value(intVar1Idx));
        //                for (int i = 0; i < pfrmCSDesign.pChart.Series[0].Points.Count; i++)
        //                {
        //                    double dblYValue = pfrmCSDesign.pChart.Series[0].Points[i].YValues[0] + pfrmCSDesign.pChart.Series[1].Points[i].YValues[0];
        //                    if (dblEstValue == dblYValue)
        //                    {
        //                        double dblSelYValue = pfrmCSDesign.pChart.Series[0].Points[i].YValues[0] + pfrmCSDesign.pChart.Series[1].Points[i].YValues[0] + pfrmCSDesign.pChart.Series[2].Points[i].YValues[0];
        //                        Selseries.Points.AddXY(pfrmCSDesign.pChart.Series[0].Points[i].XValue, dblSelYValue);
        //                    }
        //                }
        //                pRow = pCursor.NextRow();
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show("Exception:" + ex.Message);
        //        return;
        //    }
        //}

        private void BrushingToAttTable(frmAttributeTable pfrmAttTable, IFeatureLayer pFLayer, IFeatureSelection featureSelection)
        {
            try
            {
                if (pfrmAttTable.dgvAttTable.SelectedRows.Count > 0)
                {
                    pfrmAttTable.dgvAttTable.ClearSelection();
                }
                IFeatureLayer pFormFLayer = pfrmAttTable.m_pLayer as IFeatureLayer;
                if (pFormFLayer == pFLayer)
                {
                    IFeatureClass pFeatureClass = pFLayer.FeatureClass;

                    int intFIDIdx = pFeatureClass.FindField(pFeatureClass.OIDFieldName);

                    ICursor pCursor = null;
                    featureSelection.SelectionSet.Search(null, false, out pCursor);

                    IRow pRow = pCursor.NextRow();

                    int   intNfeature = featureSelection.SelectionSet.Count;
                    int   i           = 0;
                    int[] intFIDs     = new int[intNfeature];
                    while (pRow != null)
                    {
                        intFIDs[i] = Convert.ToInt32(pRow.get_Value(intFIDIdx));
                        pfrmAttTable.dgvAttTable.Rows[intFIDs[i]].Selected = true;
                        i++;
                        pRow = pCursor.NextRow();
                    }
                }
                else
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception:" + ex.Message);
                return;
            }
        }
예제 #3
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                string strLayerName = cboLayer.Text;

                int    intLIndex = pSnippet.GetIndexNumberFromLayerName(pActiveView, strLayerName);
                ILayer pLayer    = mForm.axMapControl1.get_Layer(intLIndex);

                IFeatureLayer pFLayer = pLayer as IFeatureLayer;
                IFeatureClass pFClass = pFLayer.FeatureClass;
                if (clistFields.CheckedItems.Count > 0)
                {
                    for (int i = 0; i < clistFields.CheckedItems.Count; i++)
                    {
                        pSnippet.DeleteField(pFClass, (string)clistFields.CheckedItems[i]);
                    }
                }
                else
                {
                    MessageBox.Show("Select Fields to delete");
                }

                MessageBox.Show("Done");
                if (intHandle != IntPtr.Zero)
                {
                    frmAttributeTable pfrmAttributeTable = pSnippet.returnAttTable(intHandle);
                    if (pfrmAttributeTable == null)
                    {
                        return;
                    }
                    pSnippet.LoadingAttributeTable(pLayer, pfrmAttributeTable);
                }

                this.Close();
            }
            catch (Exception ex)
            {
                frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
                return;
            }
        }
예제 #4
0
        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;
            }
        }
예제 #5
0
        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;
            //}
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                string strLayerName  = cboLayer.Text;
                string strExpression = txtNExpression.Text;
                string strTargetFld  = txtTargetField.Text;

                //Load Feature Class
                int    intLIndex = pSnippet.GetIndexNumberFromLayerName(pActiveView, strLayerName);
                ILayer pLayer    = mForm.axMapControl1.get_Layer(intLIndex);

                IFeatureLayer pFLayer = pLayer as IFeatureLayer;
                IFeatureClass pFClass = pFLayer.FeatureClass;


                if (strTargetFld == "")
                {
                    MessageBox.Show("Please select the target field");
                    return;
                }
                else if (strExpression == "")
                {
                    MessageBox.Show("Please insert expression to calculate field");
                    return;
                }

                if (radR.Checked)
                {
                    try
                    {
                        REngine pEngine = mForm.pEngine;
                        // Split the text into an array of words
                        string[] words = strExpression.Split(new char[] { ',', '$', '(', ')', '/', '*', '+', '-', '^', '=', ' ' }, StringSplitOptions.RemoveEmptyEntries); //Any other splitters?

                        //Get number and names of Expressed fields
                        int intNField        = lstFields.Items.Count;
                        int intNExpressedFld = 0;

                        string[] fieldNames = new string[intNField];

                        for (int j = 0; j < intNField; j++)
                        {
                            string strTemp = (string)lstFields.Items[j];
                            if (words.Contains(strTemp))
                            {
                                fieldNames[intNExpressedFld] = (string)lstFields.Items[j];
                                intNExpressedFld++;
                            }
                        }

                        //Get Features
                        int nFeature = pFClass.FeatureCount(null);

                        IFeatureCursor pFCursor = pFLayer.Search(null, true);
                        IFeature       pFeature = pFCursor.NextFeature();

                        //Get index for target and source fields
                        int    intTargetIdx = pFLayer.FeatureClass.Fields.FindField(strTargetFld);
                        IField pField       = pFLayer.FeatureClass.Fields.Field[intTargetIdx];

                        ////Allow calculation for other field types (v.1.0.6)
                        //if (pField.Type != esriFieldType.esriFieldTypeDouble)
                        //{
                        //    MessageBox.Show("R sytanx is only applicable to Double field type");
                        //    return;
                        //}

                        NumericVector vecResult = null;
                        bool          blnINF    = false;
                        bool          blnNAN    = false;
                        LogicalVector vecINF    = null;
                        LogicalVector vecNAN    = null;

                        //Get values from selected fields
                        if (intNExpressedFld > 0)
                        {
                            int[] idxes = new int[intNExpressedFld];
                            for (int j = 0; j < intNExpressedFld; j++)
                            {
                                idxes[j] = pFLayer.FeatureClass.Fields.FindField(fieldNames[j]);
                            }

                            //Store values in source fields into Array
                            //double[,] arrSource = new double[nFeature, intNExpressedFld];
                            double[][] arrSource = new double[intNExpressedFld][];

                            for (int j = 0; j < intNExpressedFld; j++)
                            {
                                arrSource[j] = new double[nFeature];
                            }

                            int i = 0;
                            while (pFeature != null)
                            {
                                for (int j = 0; j < intNExpressedFld; j++)
                                {
                                    arrSource[j][i] = Convert.ToDouble(pFeature.get_Value(idxes[j]));
                                }

                                i++;
                                pFeature = pFCursor.NextFeature();
                            }

                            //Source value to R vector
                            for (int j = 0; j < intNExpressedFld; j++)
                            {
                                //double[] arrVector = arrSource.GetColumn<double>(j);
                                NumericVector vecSource = pEngine.CreateNumericVector(arrSource[j]);
                                pEngine.SetSymbol(fieldNames[j], vecSource);
                            }

                            //Verifying before evaluation
                            vecINF = pEngine.Evaluate("is.infinite(" + strExpression + ")").AsLogical();
                            vecNAN = pEngine.Evaluate("is.nan(" + strExpression + ")").AsLogical();

                            for (int k = 0; k < vecINF.Length; k++)
                            {
                                blnINF = vecINF[k];
                                blnNAN = vecNAN[k];
                                if (blnINF)
                                {
                                    MessageBox.Show("INF");
                                    return;
                                }
                                else if (blnNAN)
                                {
                                    MessageBox.Show("NAN");
                                    return;
                                }
                            }

                            //Calculate
                            vecResult = pEngine.Evaluate(strExpression).AsNumeric();
                        }
                        else if (intNExpressedFld == 0) //Constant
                        {
                            //Verifying before evaluation
                            blnINF = pEngine.Evaluate("is.infinite(" + strExpression + ")").AsLogical().First();
                            blnNAN = pEngine.Evaluate("is.nan(" + strExpression + ")").AsLogical().First();
                            if (blnINF)
                            {
                                MessageBox.Show("INF");
                                return;
                            }
                            else if (blnNAN)
                            {
                                MessageBox.Show("NAN");
                                return;
                            }

                            vecResult = pEngine.Evaluate("rep(" + strExpression + ", " + nFeature.ToString() + ")").AsNumeric();
                        }

                        //Update Field
                        pFCursor = pFLayer.FeatureClass.Update(null, false);
                        pFeature = pFCursor.NextFeature();

                        int featureIdx = 0;

                        try
                        {
                            while (pFeature != null)
                            {
                                pFeature.set_Value(intTargetIdx, (object)vecResult[featureIdx]);
                                pFCursor.UpdateFeature(pFeature);

                                pFeature = pFCursor.NextFeature();
                                featureIdx++;
                            }
                        }
                        catch
                        {
                            MessageBox.Show("Fail to update field values. The field type might not support this calculation.", "Field Calcualation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("R Syntax Error: " + ex.ToString());
                        return;
                    }
                }
                else
                {
                    try
                    {
                        //Not working in 10.5
                        ICalculator pCal = null;
                        try
                        {
                            pCal = new Calculator();
                        }
                        catch
                        {
                            MessageBox.Show("Fail to load the ArcGIS Field Calculator due to a license issue. Please use a R sytanx", "Field Calcualation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        IFeatureCursor pFCursor = pFClass.Update(null, false);
                        pCal.Cursor        = (ICursor)pFCursor;
                        pCal.Expression    = strExpression;
                        pCal.PreExpression = "";
                        pCal.Field         = strTargetFld;
                        pCal.Calculate();

                        ////Not working
                        //ITable pTable = (ITable)pFClass;
                        //Geoprocessor gp = new Geoprocessor();
                        //CalculateField pCalFld = new CalculateField();
                        //pCalFld.in_table = pTable;
                        //pCalFld.field = strTargetFld;
                        //pCalFld.field = pFClass.Fields.Field[pFClass.FindField(strTargetFld)];
                        //pCalFld.expression = strExpression;
                        //pCalFld.expression = "5";
                        //pCalFld.expression_type = "VB";

                        //gp.Execute(pCalFld, null);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("ArcGIS Syntax Error: " + ex.ToString());
                        return;
                    }
                }

                MessageBox.Show("Done");
                if (intHandle != IntPtr.Zero)
                {
                    frmAttributeTable pfrmAttributeTable = pSnippet.returnAttTable(intHandle);
                    if (pfrmAttributeTable == null)
                    {
                        return;
                    }
                    pSnippet.LoadingAttributeTable(pLayer, pfrmAttributeTable);
                }
            }
            catch (Exception ex)
            {
                frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
                return;
            }
        }
예제 #8
0
        public override void OnClick()
        {
            ILayer pLayer = (ILayer)m_mapControl.CustomProperty;
            //IFeatureLayer pFLayer = pLayer as IFeatureLayer;
            //string strLayerName = pFLayer.Name;
            //IAttributeTable pAttributeTable = pFLayer as IAttributeTable;
            //ITable pTable = pAttributeTable as ITable;
            frmAttributeTable pfrmAttTable = new frmAttributeTable();

            LoadingAttributeTable(pLayer, pfrmAttTable);
            pfrmAttTable.Show();
            //IQueryFilter pQFilter = new QueryFilterClass();
            //pQFilter = null;

            ////pSnippet.funcTableView(pLayer, pTable, pfrmTableView, pQFilter);

            //System.Data.DataTable shpDataTable;
            //shpDataTable = new DataTable("shpDataTable");

            ////IQueryFilter que = new QueryFilterClass();
            //ICursor pCursor = pTable.Search(pQFilter, true);
            //IRow pRow = pCursor.NextRow();
            //if (pRow != null)
            //{
            //    for (int i = 0; i < pRow.Fields.FieldCount; i++)
            //    {

            //        DataColumn column;
            //        column = new DataColumn();
            //        column.ColumnName = pRow.Fields.get_Field(i).Name;
            //        if (pRow.Fields.Field[i].Type == esriFieldType.esriFieldTypeOID) column.DataType = System.Type.GetType("System.Int32");
            //        if (pRow.Fields.Field[i].Type == esriFieldType.esriFieldTypeInteger) column.DataType = System.Type.GetType("System.Int32");
            //        if (pRow.Fields.Field[i].Type == esriFieldType.esriFieldTypeSingle) column.DataType = System.Type.GetType("System.Single");
            //        if (pRow.Fields.Field[i].Type == esriFieldType.esriFieldTypeDouble) column.DataType = System.Type.GetType("System.Double");
            //        if (pRow.Fields.Field[i].Type == esriFieldType.esriFieldTypeSmallInteger) column.DataType = System.Type.GetType("System.Int16");
            //        Debug.WriteLine(i + " " + pRow.Fields.get_Field(i).Name + " " + pRow.Fields.Field[i].Type);
            //        shpDataTable.Columns.Add(column);

            //    }
            //    while (pRow != null)
            //    {
            //        DataRow pDataRow = shpDataTable.NewRow();
            //        for (int j = 0; j < pCursor.Fields.FieldCount; j++)
            //            pDataRow[j] = pRow.get_Value(j);
            //        shpDataTable.Rows.Add(pDataRow);
            //        pRow = pCursor.NextRow();
            //    }
            //}



            //pfrmAttTable.dgvAttTable.DataSource = shpDataTable;
            //pfrmAttTable.Text = "Attribute of " + strLayerName;


            //for (int i = 0; i < shpDataTable.Columns.Count; i++)
            //{
            //    if (i != 1)
            //    {
            //        if (shpDataTable.Columns[i].DataType == System.Type.GetType("System.Int16")) pfrmAttTable.dgvAttTable.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            //        if (shpDataTable.Columns[i].DataType == System.Type.GetType("System.Int32")) pfrmAttTable.dgvAttTable.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            //        if (shpDataTable.Columns[i].DataType == System.Type.GetType("System.Single")) pfrmAttTable.dgvAttTable.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            //        if (shpDataTable.Columns[i].DataType == System.Type.GetType("System.Double")) pfrmAttTable.dgvAttTable.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            //    }
            //}

            //pfrmAttTable.dgvAttTable.Columns["Shape"].Visible = false;
            //pfrmAttTable.dgvAttTable.AllowUserToAddRows = false;
            //pfrmAttTable.pLayer = pLayer;
            //pfrmAttTable.ShowDialog();
        }
예제 #9
0
        private void LoadingAttributeTable(ILayer pLayer, frmAttributeTable pfrmAttTable)
        {
            IFeatureLayer   pFLayer         = pLayer as IFeatureLayer;
            string          strLayerName    = pFLayer.Name;
            IAttributeTable pAttributeTable = pFLayer as IAttributeTable;
            ITable          pTable          = pAttributeTable as ITable;

            IQueryFilter pQFilter = new QueryFilterClass();

            pQFilter = null;

            //pSnippet.funcTableView(pLayer, pTable, pfrmTableView, pQFilter);

            System.Data.DataTable shpDataTable;
            shpDataTable = new DataTable("shpDataTable");

            //IQueryFilter que = new QueryFilterClass();
            ICursor pCursor = pTable.Search(pQFilter, true);
            IRow    pRow    = pCursor.NextRow();

            if (pRow != null)
            {
                for (int i = 0; i < pRow.Fields.FieldCount; i++)
                {
                    DataColumn column;
                    column            = new DataColumn();
                    column.ColumnName = pRow.Fields.get_Field(i).Name;
                    if (pRow.Fields.Field[i].Type == esriFieldType.esriFieldTypeOID)
                    {
                        column.DataType = System.Type.GetType("System.Int32");
                    }
                    if (pRow.Fields.Field[i].Type == esriFieldType.esriFieldTypeInteger)
                    {
                        column.DataType = System.Type.GetType("System.Int32");
                    }
                    if (pRow.Fields.Field[i].Type == esriFieldType.esriFieldTypeSingle)
                    {
                        column.DataType = System.Type.GetType("System.Single");
                    }
                    if (pRow.Fields.Field[i].Type == esriFieldType.esriFieldTypeDouble)
                    {
                        column.DataType = System.Type.GetType("System.Double");
                    }
                    if (pRow.Fields.Field[i].Type == esriFieldType.esriFieldTypeSmallInteger)
                    {
                        column.DataType = System.Type.GetType("System.Int16");
                    }
                    Debug.WriteLine(i + " " + pRow.Fields.get_Field(i).Name + " " + pRow.Fields.Field[i].Type);
                    shpDataTable.Columns.Add(column);
                }
                while (pRow != null)
                {
                    DataRow pDataRow = shpDataTable.NewRow();
                    for (int j = 0; j < pCursor.Fields.FieldCount; j++)
                    {
                        pDataRow[j] = pRow.get_Value(j);
                    }
                    shpDataTable.Rows.Add(pDataRow);
                    pRow = pCursor.NextRow();
                }
            }



            pfrmAttTable.dgvAttTable.DataSource = shpDataTable;
            pfrmAttTable.Text = "Attribute of " + strLayerName;


            for (int i = 0; i < shpDataTable.Columns.Count; i++)
            {
                if (i != 1)
                {
                    if (shpDataTable.Columns[i].DataType == System.Type.GetType("System.Int16"))
                    {
                        pfrmAttTable.dgvAttTable.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                    }
                    if (shpDataTable.Columns[i].DataType == System.Type.GetType("System.Int32"))
                    {
                        pfrmAttTable.dgvAttTable.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                    }
                    if (shpDataTable.Columns[i].DataType == System.Type.GetType("System.Single"))
                    {
                        pfrmAttTable.dgvAttTable.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                    }
                    if (shpDataTable.Columns[i].DataType == System.Type.GetType("System.Double"))
                    {
                        pfrmAttTable.dgvAttTable.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                    }
                }
            }

            pfrmAttTable.dgvAttTable.Columns["Shape"].Visible = false;
            pfrmAttTable.dgvAttTable.AllowUserToAddRows       = false;
            pfrmAttTable.m_pLayer = pLayer;
            pfrmAttTable.Refresh();
        }