2010-07-11 69 views
0

我有個馬路shape文件ň我想找到懸而不創建拓撲懸,是有可能找到懸而不拓撲使用ArcObjects請入資產我,因爲它太頭痛的創建地理數據庫,toplogy,正所有事情請說我? Thanx提前查找道路shape文件

回答

0

此代碼的工作對我來說:

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; 
}