拆解一个Polygon,逐个改变X,Y,并封装回去

        // 将面Geometry拆分,逐个点进行坐标转换,再组装成面Geometry
        public static bool GetPolygon(IGeometry pGeometry, out IGeometry  pOutGeometry, out Exception error)
        {
            error = null;
            pOutGeometry = null;
            try
            {
                IPolygon4 pPolygon = pGeometry as IPolygon4;
                IGeometryCollection pAllGeometryCollection = new Polygon() as  IGeometryCollection;
                if (pPolygon != null)
                {
                    //获取多边形的所有外环
                    IGeometryBag bag = pPolygon.ExteriorRingBag;
                    IEnumGeometry geo = bag as IEnumGeometry;
                    geo.Reset();
                    IRing exRing = geo.Next() as IRing;
                    while (exRing != null)
                    {
                        IGeometryCollection pNewInCollectio = new Polygon() as  IGeometryCollection;
                        // 获取当前外环所包含的内环++
                        IGeometryBag bags = pPolygon.get_InteriorRingBag(exRing);
                        IEnumGeometry geos = bags as IEnumGeometry;
                        geos.Reset();
                        IRing inRing = geos.Next() as IRing;
                        while (inRing != null)
                        {
                            IGeometry pNewInRing = null;
                            if (!ReBuild(url, inRing, out pNewInRing, out error))
                            {
                                return false;
                            }
                            pNewInCollectio.AddGeometry(pNewInRing);
                            inRing = geos.Next() as IRing;
                        }
                        IGeometry pNewExRing = null;
                        if (!ReBuild(url, exRing, out pNewExRing, out error))
                        {
                            return false;
                        }
                        pAllGeometryCollection.AddGeometry(pNewExRing);
                        pAllGeometryCollection.AddGeometryCollection(pNewInCollectio);
                        exRing = geo.Next() as IRing;
                    }
                    pOutGeometry = pAllGeometryCollection as IGeometry;
                    return true;
                }
                else
                {
                    error = new Exception("图形为空");
                    return false;
                }
            }
            catch (Exception ex)
            {
                error = ex;
                return false;
            }
        }
        // 处理线性环
        public static bool ReBuild( IGeometry pGeometry, out IGeometry  pOutGeometry, out Exception error)
        {
            error = null;
            pOutGeometry = null;
            try
            {
                ISegmentCollection segmentCollection = pGeometry as ISegmentCollection;
                ISegmentCollection pNewSegmentCollection = new RingClass();
                Dictionary<string, string> dicXYAndAfterXY = new Dictionary<string,  string>();
                // 这是不可能的,除非是具有圆弧的线
                if (segmentCollection.SegmentCount == 1)
                {
                    error = new Exception("segmentCollection.SegmentCount == 1");
                    return false;
                }
                else
                {
                    double x = 0;
                    double y = 0;
                    for (int i = 0; i < segmentCollection.SegmentCount; i++)
                    {
                        ISegment segment = segmentCollection.Segment[i];
                        // 线段起点
                        IPoint pStartPoint = segment.FromPoint;
                        x = pStartPoint.X;
                        y = pStartPoint.Y;
                        pStartPoint.X = x - 300000;
                        pStartPoint.Y = y - 300000;
                        // 线段终点
                        IPoint pToPoint = segment.ToPoint;
                        x = pToPoint.X;
                        y = pToPoint.Y;
                        pToPoint.X = x - 300000;
                        pToPoint.Y = y - 300000;
                        ISegment pNewSegment = new LineClass();
                        pNewSegment.FromPoint = pStartPoint;
                        pNewSegment.ToPoint = pToPoint;
                        pNewSegmentCollection.AddSegment(pNewSegment);
                    }
                }
                pOutGeometry = pNewSegmentCollection as IRing;
                return true;
            }
            catch (Exception ex)
            {
                error = ex;
                return false;
            }
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值