point\polyline\polygon的转化(转)

首先你要明白Polyline是由path对象构成,Polygon是由ring对象构成,因此实现polyline向polygon的转换,思路如下:
1.提取polyline中的所有path对象
2.将path对象转换成ring对象,由于IRing继承自IPath,因此该转换是合理的
3.利用IGeometryCollection.AddGeometry添加ring对象,构成polygon
示例如下:

  1.       //cast the polyline object to the polygon
  2.             ISegmentCollection pRing;
  3.             IGeometryCollection pPolygon = new PolygonClass();
  4.             object o = Type.Missing;
  5.             for (int i = 0; i < pPolyline.GeometryCount;i++ )
  6.             {
  7.                 pRing = new RingClass();
  8.                 pRing.AddSegmentCollection(pPolyline.get_Geometry(i) as ISegmentCollection);
  9.                 pPolygon.AddGeometry(pRing as IGeometry, ref o, ref o);
  10.             }
复制代码

point转为polyline,思路如下:
polyline是由path构成,path是由segment构成,因此首先构建segment对象,然后利用ISegmentCollection.AddSegment构造path,最后利用IGeometryCollection.AddGeometry构造polyline
示例如下:

  1.       IPoint point1 = new PointClass();
  2.             point1.PutCoords(100, 200);
  3.             IPoint point2 = new PointClass();
  4.             point2.PutCoords(600, 700);
  5.             IPoint point3 = new PointClass();
  6.             point3.PutCoords(450, 800);
  7.             [color=Blue]//new a line object[/color]
  8.             ILine pLine = new LineClass();
  9.             object o = Type.Missing;
  10.             pLine.PutCoords(point1, point2);
  11.             [color=Blue]//new a path[/color]
  12.             ISegmentCollection pPath = new PathClass();
  13.             pPath.AddSegment((ISegment)pLine, ref o, ref o);
  14.             pLine = new LineClass();
  15.             pLine.PutCoords(point2, point3);
  16.             pPath.AddSegment((ISegment)pLine, ref o, ref o);
  17.             [color=Blue]//new a polyline[/color]
  18.             IGeometryCollection pPolyline = new PolylineClass();
  19.             pPolyline.AddGeometry((IGeometry)pPath, ref o, ref o);
复制代码

 

转载于:https://www.cnblogs.com/lxc-binary/p/3198482.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值