tags:

views:

32

answers:

1

I have a road shapefile n I want to find Dangles without creating a topology, is it possible to find Dangles without topology with arcobjects please assest me coz its too much headach to create geodatabase, toplogy, n all things please assest me? Thanx in advance

A: 

This code works for me:

public static void TestGetDangles(IMap map)
{
    IFeatureLayer fLayer = map.get_Layer(0) as IFeatureLayer;
    // to achieve cluster tolerance capability, tweak the format string
    Dictionary<string, int> valences = GetValences(fLayer.FeatureClass, "{0},{1}");
    List<IPoint> danglePoints = GetDangles(valences, ",");
    if (danglePoints.Count == 0)
        return;
    IScreenDisplay disp = ((IActiveView)map).ScreenDisplay;
    disp.StartDrawing(0, (short)esriScreenCache.esriNoScreenCache);
    disp.SetSymbol(new SimpleMarkerSymbolClass());
    foreach (IPoint p in danglePoints)
    {
        disp.DrawPoint(p);
    }
    disp.FinishDrawing();
}

public static List<IPoint> GetDangles(Dictionary<string, int> dict, string delim)
{
    List<IPoint> list = new List<IPoint>();
    foreach (KeyValuePair<string, int> kvp in dict)
    {
        if (kvp.Value == 1)
        {
            IPoint pnt = new PointClass();
            string[] s = kvp.Key.Split(delim.ToCharArray());
            pnt.PutCoords(double.Parse(s[0]), double.Parse(s[1]));
            list.Add(pnt);
        }
    }
    return list;
}

public static Dictionary<string, int> GetValences(IFeatureClass fc, string format)
{
    Dictionary<string,int> dict = new Dictionary<string,int>();
    IFeatureCursor fCur = fc.Search(null, false);
    IFeature feat;
    while ((feat = fCur.NextFeature()) != null)
    {
        IPolyline polyline = feat.Shape as IPolyline;
        string fkey = String.Format(format, polyline.FromPoint.X, polyline.FromPoint.Y);
        if (!dict.ContainsKey(fkey))
            dict.Add(fkey, 1);
        else
            dict[fkey] += 1;
        string tkey = string.Format(format, polyline.ToPoint.X, polyline.ToPoint.Y);
        if (!dict.ContainsKey(tkey))
            dict.Add(tkey, 1);
        else
            dict[tkey] += 1;
    }
    Marshal.FinalReleaseComObject(fCur);
    return dict;
}
Kirk Kuykendall

related questions