2

enter image description hereI have validated the Telco Features based on the feature class name and their Type_Name. But I am not able to do same for tables like connection table etc. and others which mostly have different attributes and values and some I find don't have any values at all. Can you help me with your ideas, how to validate the attributes of all the tables added in the map.


In telco dataset, most of the feature class have their one of the attributes as "TYPE_NAME". Say for Transmedia there are 2 types with the TYPE_NAME "AERIAL" and "BURIED". Depending on the TYPE_NAME I have validated the other attributes' value of the featureclass. What I mean by other attributes is like Transmedia_Name, NUMBEROFFIBERS, NUMBEROFRIBBONS etc. I used some regular expression to validate. But now when there are some features and tables those I can add in the TOC but there are no TYPE_NAME. So rethinking about how to do that for those cases. I think as per my capacity I have explained what I am trying to do.

There are 5 methods which is doing the same #

  1. Reading the config Excel File into a datatable( one time activity )
  2. Reading the Header of the dataTable
  3. Reading the values in the columns of the datatable
  4. Reading the data from the feature.
  5. Validate

Reading the config Excel File into a datatable

 public void ReadExcelToDataTable(string configPath)
        {

            Excel.Application xlApp = new Excel.Application();
            Excel.Workbook workBook;
            Excel.Worksheet workSheet;
            //_dTable = new DataTable();
            // FileStream fileStream = new System.IO.FileStream(configPath, FileMode.Open);
            workBook = xlApp.Workbooks.Open(configPath);
            try
            {

                workSheet = (Excel.Worksheet)workBook.Worksheets[1];
                int columnCount = workSheet.UsedRange.Columns.Count;
                _dTable = new DataTable();
                DataRow row = _dTable.NewRow();
                _dTable.Clear();

                int noOfRow = 1;

                int stoppingCondition = 1;


                foreach (Microsoft.Office.Interop.Excel.Worksheet var in workBook.Worksheets)
                {

                    if (stoppingCondition > 1)
                    {
                        break;
                    }
                    int rows = var.UsedRange.Rows.Count;

                    int cols = var.UsedRange.Columns.Count;


                    for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++)
                    {

                        string colname = workSheet.Cells[1, columnIndex].Text;

                        _dTable.Columns.Add(colname);

                        noOfRow = 2;

                    }

                    for (int rowIndex = noOfRow; rowIndex <= rows; rowIndex++)
                    {

                        DataRow dr = _dTable.NewRow();

                        for (int columnIndex = 1; columnIndex <= cols; columnIndex++)
                        {
                            dr[columnIndex - 1] = var.Cells[rowIndex, columnIndex].Text;
                        }

                        _dTable.Rows.Add(dr);
                    }
                    stoppingCondition++;
                }

            }
            catch (Exception exp)
            {

                throw exp;
            }
            finally
            {
                workBook.Close();

                //Closing excel application
                xlApp.Quit();
            }

            //return _dTable;
        }

Reading header of the DataTable #

public List<string> GetDataTableHeaderRow(IFeature feature)
        {
            string[] strHeaderRow = new string[_dTable.Columns.Count];
            string name = feature.Class.AliasName.ToString();
            string[] splittedFeatureName = name.Split('.');
            string featureName = splittedFeatureName[1] + "_NAME";
            //headerRow[iCount] = featureName;
            List<string> lstConfigHeader = new List<string>();
            try
            {
                int iCount = 0;
                foreach (DataColumn col in _dTable.Columns)
                {
                    if ((col.ToString()).Equals("FeatureClass") == false)
                    {
                        strHeaderRow[iCount] = col.ToString();
                        lstConfigHeader.Add(col.ToString());
                    }
                    else
                    {
                        strHeaderRow[iCount] = featureName;
                        lstConfigHeader.Add(featureName);
                    }
                }
            }
            catch (Exception exp)
            {
                throw exp;
            }
           // return strHeaderRow; 
            return lstConfigHeader;
}

Reading the columns of the datatable

public  List<string> ReadDataTableValues(IFeature feature, string[] headerRow)
        {
            List<String> list = new List<String>();
            int fldIndx = -1;
            int iCount = 0;
            string name = feature.Class.AliasName.ToString();
            string featureName = "";
            string[] splittedFeatureName = name.Split('.');
            featureName = splittedFeatureName[1] + "_NAME";
            try
            {
                int fldIndex = feature.Fields.FindField("TYPE_NAME");
                DataRow[] rows = _dTable.Select("FeatureClass = '" + feature.Class.AliasName + "' AND TYPE_NAME = '" + feature.get_Value(fldIndex) + "'");

                foreach (var rowItem in rows)
                {
                    for (int iter = 1; iter <= _dTable.Columns.Count; iter++,iCount++)
                    {
                        fldIndx = feature.Fields.FindField(headerRow[iCount]);
                        if (fldIndx >= 0)
                        {
                            if (featureName.Equals(headerRow[iCount]) == true)
                            {
                                list.Add(rowItem["FEATURE_NAME"].ToString());
                            }

                            else if (!((rowItem[headerRow[iCount]].ToString()).IsNullEmptyOrWhiteSpace()) && (featureName.Equals(headerRow[iCount]) == false))
                            {
                                list.Add(rowItem[headerRow[iCount]].ToString());
                            }
                            else
                            {
                                list.Add(String.Empty);
                            }
                        }
                        //iCount++;
                    } 
                }

            }
            catch (Exception exp)
            {
                throw exp;
            }
            finally
            {

            }
            return list;
        }

Reading Data from feature #

public List<string> GetValuesFromFeatureClass(string[] headerRow, IFeature feature)
        {
            int fldIndex;
            int length = headerRow.Length;
            //int iter = 0;
            string[] featureFieldValues = new string[length];
            List<string> strList = new List<string>();
            try
            {
                for (int iCount = 0; iCount < headerRow.Length; iCount++)
                {
                    fldIndex = feature.Fields.FindField(headerRow[iCount]);
                    if (fldIndex >= 0)
                    {
                        strList.Add(feature.get_Value(fldIndex).ToString());
                        //featureFieldValues[iter] = feature.get_Value(fldIndex).ToString();
                        //iter++;
                    }
                }
            }
            catch (Exception exp)
            {
                throw exp;
            }

            return strList;

        }

I am not pasting here the code of validation. As you asked for the ArcGis Code and for making things clear What I did, I pasted the 4 methods which are working now.

  • Hey PolyGeo, Have updated with code my approach. Do you have any thoughts. – royan Jul 9 '17 at 15:32
  • I do not code using ArcObjects but now that you have code included your chances of attracting a potential answerer should have improved. – PolyGeo Sep 11 '17 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.