shravan.phil

Getting the layer by name - unable to execute

Discussion created by shravan.phil on Nov 26, 2010
Latest reply on Nov 26, 2010 by shravan.phil
Here, i am trying to get the watershed layer for perfoming my analysis, when i am building the solution, its working perfectly - but when i run the tool - its not running, could you please tell me where i went wrong.

I am thinking that I am unable to get the watershed layer properly refered into my analysis;

             int i;
            IMxDocument pMxDoc = null;
            IMap pMap = null;
            IFeatureLayer pFLayer = null;
            IFeatureClass pFClass = null;
            //IFeatureSelection pSelection = null;
            //ISelectionSet psetSelection = null;
            pMxDoc = mxdoc;
            pMap = pMxDoc.FocusMap;


            for (i = 0; i <= pMap.LayerCount - 1; i++)
            {
                if (pFLayer.Name == "Watershed")
                {
                   
                   
                    pFLayer = pMap.get_Layer(i) as IFeatureLayer;

                    pFClass = pFLayer.FeatureClass;

                   
                    IQueryFilter pQFilter = new QueryFilterClass();
                    pQFilter.WhereClause = "";

                    // 'Establish a cursor used for looping
                    IFeatureCursor pFCursor = null;
                    pFCursor = pFClass.Search(pQFilter, true);
                    IFeature pFeature = null;
                    pFeature = pFCursor.NextFeature();
                    StringBuilder sb = new StringBuilder();
                    //'Loop thru all features and write attributes to output filew

                    int fldIndex1 = pFClass.Fields.FindField("Name");
                    int fldIndex2 = pFClass.Fields.FindField("County");
                    int fldIndex3 = pFClass.Fields.FindField("Towers");
                    int fldIndex4 = pFClass.Fields.FindField("Count");
                    string fldValues = string.Empty;
                    fldValues = "Name" + delimiter + "County" + delimiter + "Towers + delimiter + "Count";
                    sb.AppendLine(fldValues);
                    while (pFeature != null)
                    {




                       
                        fldValues = pFeature.get_Value(fldIndex1).ToString() + delimiter + pFeature.get_Value(fldIndex2).ToString() + delimiter + pFeature.get_Value(fldIndex3).ToString() + delimiter + pFeature.get_Value(fldIndex4).ToString();


                      
                        pFeature = pFCursor.NextFeature();
                        sb.AppendLine(fldValues);
                        fldValues = string.Empty;

                    }
                    File.WriteAllText(filePath, sb.ToString());

                }


            

            }

       
       
       
        }




    }

}

Outcomes