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

本文解决了一个关于如何从投影带地理数据中提取四个边界的问题。通过正确的接口转换和遍历操作,成功实现了边界提取并展示了完整的代码示例。

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

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

ExpandedBlockStart.gifCode
IPolygon poly = (IPolygon)pFeature.Shape;
ISegmentCollection pSegColl 
= new PolylineClass();
pSegColl 
= poly as ISegmentCollection; 
ISegment pSegment 
= pSegColl.get_Segment(0);

IPolyline polyline 
= new PolylineClass();
polyline 
= pSegment as IPolyline;

 

最终代码如下:

ExpandedBlockStart.gifCode
            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也可以取出多边形的边界。

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

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

转载于:https://www.cnblogs.com/secenes/archive/2008/09/17/1292801.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值