AO 直线相交

  注意的问题  :

直线的相交的部分有可能是Multipoint,也有可能是的Polyline,下面的例子中只判断了前一种情况,后一种情况尽管比较少见,但仍然需要判断。

使用IConstructPoint接口的ConstructIntersection方法可以直接构造交点

  1. //获取IGeometryCollection集合,因为存在两条线存在多个交点的情况,  
  2.   
  3. //所以必须返回geometryCollection而非PointCollection  
  4.   
  5. private IGeometryCollection GetGeometries(IFeatureLayer pFL)  
  6.   
  7. {  
  8.   
  9.     IFeatureClass pFeatureClass = pFL.FeatureClass;  
  10.   
  11.     //求线条的总数  
  12.   
  13.     int intCount = pFeatureClass.FeatureCount(null);  
  14.   
  15.     //AddGeometry的参数  
  16.   
  17.     object Missing = Type.Missing;  
  18.   
  19.     //交点置于此变量中,必须用此对象初始化,因为两条线,可能存在多个交点,  
  20.   
  21.     //即多点构成一个geometry,而GeometryBagClass对象的包容性强  
  22.   
  23.     IGeometryCollection pGeometryCollection = new GeometryBagClass();  
  24.   
  25.     IFeature pFeature1;  
  26.   
  27.     ITopologicalOperator pTopologicalOperator;  
  28.   
  29.     for (int i = 0; i < intCount; i++)  
  30.   
  31.     {  
  32.   
  33.         pFeature1 = pFeatureClass.GetFeature(i);  
  34.   
  35.         pTopologicalOperator = (ITopologicalOperator)pFeature1.Shape;  
  36.   
  37.         IFeature pFeature2;  
  38.   
  39.         IGeometry pGeometry;  
  40.   
  41.         for (int j = i + 1; j < intCount; j++)  
  42.   
  43.         {  
  44.   
  45.             pFeature2 = pFeatureClass.GetFeature(j);  
  46.   
  47.             pGeometry = pTopologicalOperator.Intersect(pFeature2.Shape, esriGeometryDimension.esriGeometry0Dimension);  
  48.   
  49.             if (pGeometry != null)  
  50.   
  51.             {  
  52.   
  53.                 pGeometryCollection.AddGeometry(pGeometry,ref Missing,ref Missing);  
  54.   
  55.             }  
  56.   
  57.         }  
  58.   
  59.     }  
  60.   
  61.     return pGeometryCollection;  
  62.   
  63. }  
  64.   
  65.   
  66.   
  67. //用于拆分GeometryCollection里的multipoint这种情况,最终将所有点填入PointCollection中  
  68.   
  69. private IPointCollection AddPoint()  
  70.   
  71. {  
  72.   
  73.     //调用此方法,获得所有Geometry  
  74.   
  75.     IGeometryCollection pGC = this.GetGeometries((IFeatureLayer)this.axMapControl1.get_Layer(0));  
  76.   
  77.     //定义一个pPointCollection接口变量,用MultipointClass对象实例化  
  78.   
  79.     IPointCollection pPointCollection = new MultipointClass();  
  80.   
  81.     object Missing = Type.Missing;  
  82.   
  83.   
  84.   
  85.     //循环geometrycollection里的每一个geometry,判断它是否是IPointCollection类型  
  86.   
  87.     for (int i = 0; i < pGC.GeometryCount; i++)  
  88.   
  89.     {  
  90.   
  91.         IGeometry pGeometry = pGC.get_Geometry(i);  
  92.   
  93.         //将每个geometry转换成IPointCollection类型,转换失败,pPC就会等于null,并以此作为判断是否是多点的依据  
  94.   
  95.         IPointCollection pPC = pGeometry as IPointCollection;  
  96.   
  97.         if (pPC != null)//转换成功,是个多点的geometry,则将里面的点分别提取出来  
  98.   
  99.         {  
  100.   
  101.             for (int j = 0; j < pPC.PointCount; j++)  
  102.   
  103.             {  
  104.   
  105.                 pPointCollection.AddPoint(pPC.get_Point(j), ref Missing, ref Missing);  
  106.   
  107.             }  
  108.   
  109.         }  
  110.   
  111.         else//转换失败,是只有一个点的geometry,则直接添加到pPointCollection里面  
  112.   
  113.         {  
  114.   
  115.             pPointCollection.AddPoint((IPoint)pGeometry, ref Missing, ref Missing);  
  116.   
  117.         }  
  118.   
  119.     }  
  120.   
  121.     return pPointCollection;//返回最终结果  
  122.   
  123. }  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值