依次取出四边形的每条边代码

最近处理投影带的一些问题,需要将每个投影带的四个边取出来进行运算,经过咨询ESRI社区相关大哥,尤其enjoylives的大力相助,终于实现。

刚开始用了如下代码,polyline一直为空。

Code

 

最终代码如下:


            IPolygon poly = (IPolygon)pFeature.Shape;
            ISegmentCollection pSegCollection_total 
= new PolylineClass();
            pSegCollection_total 
= poly as ISegmentCollection;
            
for (int i = 0; i <= pSegCollection_total.SegmentCount - 1;i++ )
            {
                ISegment pSegment 
= pSegCollection_total.get_Segment(i);
                ISegmentCollection pSegCollection 
= new PolylineClass() as ISegmentCollection;
                pSegCollection.AddSegment(pSegment, 
ref o, ref o);
                IPolyline polyline 
= pSegCollection as IPolyline;
                MessageBox.Show(polyline.Length.ToString());
            }

 

这里需要注意,Segment和Polyline之间不能进行接口查询(第一段代码里面polyline = pSegment as IPolyline错误)。Segment和Polyline之间不能进行接口查询,而Line继承了Segment(也就是说它是Segment的一种类型),可以进行接口查询。Line和Polyline之间也不能直接转化。

附上OMD图,看的更清楚了:)

另外,利用ITopologicalOperator.Boundary Property也可以取出多边形的边界。

代码贴出来,希望没看过的人别和我犯同样的错误。

好长时间没看开发了,现在终于有时间了,加油!!

posted on 2008-09-17 19:16  duckweeds  阅读(782)  评论(1编辑  收藏  举报

导航