1
/// <summary>
/// Gets a list of all geoms in a Feature Class
/// </summary>
/// <param name="FClass">The Feature Class</param>
/// <returns>a List of Geometries</returns>
private List<T> GetGeometries<T>(IFeatureClass FClass)
{
    List<T> List_Geometries = new List<T>();

    IQueryFilter aQF = new QueryFilter();
    aQF.WhereClause = "";
    ISelectionSet selectionSet = FClass.Select(aQF, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionNormal, null);
    IEnumIDs enumId = selectionSet.IDs;
    int nFeatures = selectionSet.Count;
    enumId.Reset();
    int id;
    for (int j = 0; j < nFeatures; j++)
    {
        id = enumId.Next();
        IGeometry pGeom = FClass.GetFeature(id).Shape;
        List_Geometries.Add((T)pGeom);
    }
    return List_Geometries;
}

I don't get any diagnostics errors on the above routine. However I do get an error when I attempt to call this method. How can I call this method from the following set of code?

private List<IPoint> GetPointsList(IFeatureRepository Bfr)
{
IFeatureClass Bfc = Bfr.GetFeatureClassByName("PointFeatureClass");
List<IPoint> listPoints = GetGeometries(Bfc);
return listPoints;
} 

By the way, this is not the way to do it, but I'm just trying to give an example of what I'm trying to do.

  • Shouldn't it be: List<IPoint> listPoints = GetGeometries<IPoint>(Bfc); (Been a while since I have done C#) – Nathan W Sep 30 '13 at 13:40
  • @NathanW Yes, it was such a simple thing. Thanks! I think we were both posting the answer at the same time :-) – Renee Cammarere Sep 30 '13 at 13:49
1

I resolved it on my own. The following method of calling this routine works:

   private List<IPoint> GetPointsList(IFeatureRepository Bfr)
    {
        IFeatureClass Bfc = Bfr.GetFeatureClassByName("PointFeatureClass");
        List<IPoint> listPoints = GetGeometries<IPoint>(Bfc);
        return listPoints;
    }

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.