//生成的Polyline要这样加点,ITopologicalOperator拓扑操作才正常,如果使用IPointCollection很有可能是COM错误
IPoint pt1 = new PointClass();
pt1.PutCoords(0, 100);
IPoint pt2 = new PointClass();
pt2.PutCoords(100, 100);
IPoint pt3 = new PointClass();
pt3.PutCoords(200, 100);
IPoint pt4 = new PointClass();
pt4.PutCoords(300, 100);
IPoint pt5 = new PointClass();
pt5.PutCoords(400, 100);
IPoint pt6 = new PointClass();
pt6.PutCoords(500, 100);
IPoint pt7 = new PointClass();
pt7.PutCoords(600, 100);
object missing = Type.Missing;
IGeometryCollection line1 = new PolylineClass();
ISegmentCollection path1 = new PathClass();
var L1 = new LineClass(); L1.PutCoords(pt1, pt2); path1.AddSegment(L1);
var L2 = new LineClass(); L2.PutCoords(pt2, pt3); path1.AddSegment(L2);
var L3 = new LineClass(); L3.PutCoords(pt3, pt4); path1.AddSegment(L3);
var L4 = new LineClass(); L4.PutCoords(pt4, pt5); path1.AddSegment(L4);
var L5 = new LineClass(); L5.PutCoords(pt5, pt6); path1.AddSegment(L5);
var L6 = new LineClass(); L6.PutCoords(pt6, pt7); path1.AddSegment(L6);
line1.AddGeometry(path1 as IGeometry, ref missing, ref missing);
((ITopologicalOperator)line1).Simplify();
IPoint pt6a = new PointClass();
pt6.PutCoords(500, 100);
IPoint pt7a = new PointClass();
pt7.PutCoords(600, 100);
IGeometryCollection line2 = new PolylineClass();
ISegmentCollection path2 = new PathClass();
var L6a = new LineClass(); L6a.PutCoords(pt6a, pt7a); path2.AddSegment(L6a);
line2.AddGeometry(path2 as IGeometry, ref missing, ref missing);
((ITopologicalOperator)line2).Simplify();
var topo = line1 as ITopologicalOperator;
IGeometry geo1 = null;
IGeometry geo2 = null;
//var topo2 = line as IRelationalOperator;
//bool contain = topo2.Contains(intersectline);
geo1 = topo.Difference(line2 as IGeometry);
var diffGeo = (geo1 as IGeometryCollection).get_Geometry(0) as ISegmentCollection;
生成的Polyline这样示例拓扑
最新推荐文章于 2024-04-28 17:55:26 发布