ArcGis相接面补节点c#

相接(Touch)面执行切割后 新面与原相接面会缺少公共节点。

 1  private void AddPointToTouchesPolygon(IFeatureCursor newFeatureCursor, IFeatureClass featureClass)
 2         {
 3             IFeature newFeature = newFeatureCursor.NextFeature();
 4             while (newFeature != null)
 5             {
 6                 IPointCollection pointCollectionNewFeature = newFeature.Shape as IPointCollection;
 7                 for (int i = 0; i < pointCollectionNewFeature.PointCount-1; i++)
 8                 {
 9                     ITopologicalOperator pTopologicalOperator = pointCollectionNewFeature.Point[i] as IGeometry as ITopologicalOperator;
10                     IGeometry pGeometryPointBuffer = pTopologicalOperator.Buffer(0.001);
11                     ISpatialFilter spatialFilter0 = Utils.FilterUtils.SpatialFilter(pGeometryPointBuffer, esriSpatialRelEnum.esriSpatialRelIntersects);
12                     IFeatureCursor featureCursor0 = featureClass.Update(spatialFilter0, false);
13                     IFeature feature0 = featureCursor0.NextFeature();
14                     while (feature0 != null)
15                     {
16                         IPointCollection pointCollection1 = feature0.Shape as IPointCollection;
17                         IPoint pointTemp = new PointClass();
18                         int count = 0;
19                         for (int k = 0; k < pointCollection1.PointCount-1; k++)
20                         {
21                             pointCollection1.QueryPoint(k, pointTemp);
22                             if (Math.Abs(pointTemp.X - pointCollectionNewFeature.Point[i].X) < 0.001 && Math.Abs(pointTemp.Y - pointCollectionNewFeature.Point[i].Y) < 0.001)
23                                 count++;
24                         }
25                         if (count == 0)
26                         {
27                             pointCollection1.AddPoint(pointCollectionNewFeature.Point[i]);
28                             ITopologicalOperator topologicalOperator = feature0.Shape as ITopologicalOperator;
29                             topologicalOperator.Simplify();
30                             featureCursor0.UpdateFeature(feature0);
31                             featureCursor0.Flush();
32                         }
33                         feature0 = featureCursor0.NextFeature();
34                     }
35                 }
36                 newFeature = newFeatureCursor.NextFeature();
37             }
38         }

该方法只适用于规则的多边形,欢迎提出改进意见、bug及其解决

=============================================================================================================

更新方法:

 1      private void AddPointToTouchesPolygon(IFeatureCursor newFeatureCursor, IFeatureClass featureClass)
 2         {
 3             IFeature newFeature = newFeatureCursor.NextFeature();
 4             IFeatureCursor featureCursor0 = null;
 5             try
 6             {
 7                 while (newFeature != null)
 8                 {
 9                     IPointCollection pointCollectionNewFeature = newFeature.Shape as IPointCollection;
10                     for (int i = 0; i < pointCollectionNewFeature.PointCount - 1; i++)
11                     {
12                         ITopologicalOperator pTopologicalOperator = pointCollectionNewFeature.Point[i] as IGeometry as ITopologicalOperator;
13                         IGeometry pGeometryPointBuffer = pTopologicalOperator.Buffer(0.001);
14                         ISpatialFilter spatialFilter0 = Utils.FilterUtils.SpatialFilter(pGeometryPointBuffer, esriSpatialRelEnum.esriSpatialRelIntersects);
15                         featureCursor0 = featureClass.Update(spatialFilter0, false);
16                         IFeature adjoinFeature = featureCursor0.NextFeature();
17                         while (adjoinFeature != null)
18                         {
19                             IPointCollection pointCollectionAdjoinFeature = adjoinFeature.Shape as IPointCollection;
20                             IPointCollection pointCollectionAdjoinFeatureCpoy = adjoinFeature.ShapeCopy as IPointCollection;
21                             int count = 0;
22                             for (int k = 0; k < pointCollectionAdjoinFeature.PointCount - 1; k++)
23                             {
24                                 if (Math.Abs(pointCollectionAdjoinFeature.Point[k].X - pointCollectionNewFeature.Point[i].X) < 0.001 && Math.Abs(pointCollectionAdjoinFeature.Point[k].Y - pointCollectionNewFeature.Point[i].Y) < 0.001)
25                                 {
26                                     count++;
27                                     break;
28                                 }
29                             }
30                             if (count == 0)
31                             {
32                                 for (int j = 0; j < pointCollectionAdjoinFeatureCpoy.PointCount - 1; j++)
33                                 {
34                                     if(IsPointOnSegment(pointCollectionNewFeature.Point[i], pointCollectionAdjoinFeatureCpoy.Point[j], pointCollectionAdjoinFeatureCpoy.Point[j + 1]))
35                                     {
36                                         //before 在这个索引之前加
37                                         pointCollectionAdjoinFeature.AddPoint(pointCollectionNewFeature.Point[i], j + 1, Type.Missing);
38                                         break;
39                                     }
40                                 }
41                                 ITopologicalOperator topologicalOperator = adjoinFeature.Shape as ITopologicalOperator;
42                                 topologicalOperator.Simplify();
43                                 featureCursor0.UpdateFeature(adjoinFeature);
44                                 featureCursor0.Flush();
45                             }
46                             adjoinFeature = featureCursor0.NextFeature();
47                         }
48                     }
49                     newFeature = newFeatureCursor.NextFeature();
50                 }
51             }
52             catch (Exception exp)
53             {
54                 throw new Exception("添加公共节点时发生错误!" + "\r\n" + exp.Message + "\r\n" + exp.StackTrace);
55             }
56         }

 

posted @ 2019-06-21 11:50  yzhyingcool  阅读(874)  评论(2编辑  收藏  举报