作者:小賑賑_533 | 来源:互联网 | 2023-10-12 14:02
小米是用pointCollection来创建polygon的,程序编译通过无误,但小米想更换了pointCollection。Add()的顺序后成一新的polygon,就通不过了,弱弱的想不明白。
小米是用pointCollection 来创建polygon的,程序编译通过无误,但小米想更换了pointCollection。Add ()的顺序后成一新的polygon,就通不过了,弱弱的想不明白。
上部分代码:
IWorkspaceEdit workspaceEdit = workspace as IWorkspaceEdit;
workspaceEdit.StartEditing(true);
workspaceEdit.StartEditOperation();
IPoint point = new PointClass();
point.X = 155.00; //点的坐标传入。
point.Y = 39.00;
IPoint point2 = new PointClass();
point2.X = 155.00; //点的坐标传入。
point2.Y = 40.00;
IPoint point3 = new PointClass();
point3.X = 156.00; //点的坐标传入。
point3.Y = 41.00;
IPoint point4 = new PointClass();
point4.X = 154.50; //点的坐标传入。
point4.Y = 39.00;
IPointCollection4 pointCollection = new PolylineClass();
object miss = Type.Missing;
pointCollection.AddPoint(point, ref miss, ref miss);
pointCollection.AddPoint(point2, ref miss, ref miss);
pointCollection.AddPoint(point3, ref miss, ref miss);
pointCollection.AddPoint(point4, ref miss, ref miss); //少了这一点通过
pointCollection.AddPoint(point, ref miss, ref miss);// end点一定要和以前某点闭合
IGeometryCollection pGeoColl = pointCollection as IGeometryCollection;
ISegmentCollection pRing = new RingClass();
pRing.AddSegmentCollection(pGeoColl as ISegmentCollection);
IGeometryCollection pPolygon = new PolygonClass();
pPolygon.AddGeometry(pRing as IGeometry, ref miss, ref miss);
IFeature feature = feaPointClass.CreateFeature();
feature.Shape = (IGeometry)pPolygon;
//feature.set_Value(feature.Fields.FindField("Traj_projection_name"), "sagfre");
//feature.set_Value(feature.Fields.FindField("bbb"), "safas");
feature.Store();
workspaceEdit.StopEditOperation();
workspaceEdit.StopEditing(true);
4 个解决方案
解决了,要做拓扑处理,加一句
ITopologicalOperator topologicalOperator = pPolygon as ITopologicalOperator;
topologicalOperator.Simplify();
IFeature feature = feaPointClass.CreateFeature();
feature.Shape = (IGeometry)pPolygon;