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);

复制代码

上一篇:Hadoop1.1.2伪分布式安装笔记


下一篇:Java中守护线程的总结