ArcGis 拓扑检查——缺顶点、悬挂检查代码 C#

2021-06-29 01:05

阅读:814

标签:sea   img   end   ash   hook   check   ext   RKE   runtime   

看了些源码,效率挺垃圾的,折腾了一个垃圾得不太彻底的代码,还是慢。

不会折腾底层直接怼COM的悲伤……

实现思路是这样的:

1、把面层的点都塞进List,去重,取坐标4位,后边的检查使用容差0.001

2、遍历点,通过点在面层寻相交的面

3、如果结果是1,那么这个面在这个点处没有毗邻面,把点缓冲区一下给定距离,如果能找到面了,那么悬挂悬挂。

如果结果>1,那么遍历所有相交面,如果面的PointCollect里有这个点,那么计数+1;如果存在PointCollection里不包含这个点的面 ,那么缺顶点缺顶点

下面贴代码

取点集,去个重:

技术分享图片技术分享图片
 1   class UserPoints
 2     {
 3         public static  List FeatureLayer2PointList(IFeatureLayer pFeatureLayer)
 4         {
 5             List pointList = new List();
 6             IFeatureCursor pFeatureCursor = pFeatureLayer.FeatureClass.Search(null, true);
 7             try
 8             {
 9                 IFeature pFeatuare = pFeatureCursor.NextFeature();
10                 while (pFeatuare != null)
11                 {
12                     IPointCollection pcol = pFeatuare.Shape as IPointCollection;
13                     for (int i = 0; i 1; i++)
14                     {
15                         pointList.Add(pcol.Point[i]);
16                     }
17                     pFeatuare = pFeatureCursor.NextFeature();
18                 }
19                 pointList = pointList.Distinct(new Compare()).ToList();
20             }
21             catch (Exception exp)
22             {
23                 ErrorF err = new ErrorF(exp.Message + "\r\n" + exp.StackTrace);
24                 err.Show();
25             }
26             finally
27             {
28                 System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);             
29             }
30             return pointList;
31         }
32     }
33 
34     class Compare : IEqualityComparer35     {
36 
37         bool IEqualityComparer.Equals(IPoint a, IPoint b)
38         {
39             if (a == null && b == null)
40                 return false;
41             else
42                 return Math.Round(a.X, 4) == Math.Round(b.X, 4) && Math.Round(a.Y, 4) == Math.Round(b.Y, 4);
43         }
44 
45         int IEqualityComparer.GetHashCode(IPoint obj)
46         {
47             return obj.ToString().GetHashCode();
48         }
49     }
View Code

拓扑一下:

技术分享图片技术分享图片
 1      public static List CheckLackJunctionPointOrSuspendedPoint(IFeatureLayer pFeatureLayer, double distance)
 2         {
 3             IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)m_hookHelper.FocusMap.ActiveGraphicsLayer;
 4             pGraphicsContainer.DeleteAllElements();
 5             IColor innerColor = new RgbColorClass();
 6             innerColor.NullColor = true;
 7             IColor outLineColor = DisplayUtils.RGBColor(255, 0, 0);
 8             IElement pElement;
 9             List listError = new List();
10             IFeatureCursor pFeatureCursor=null;
11             IFeature pFeature;
12             try
13             {
14                 IGeometry pGeometry;
15                 foreach (IPoint point in UserPoints.FeatureLayer2PointList(pFeatureLayer))
16                 {
17                     ITopologicalOperator pTopologicalOperator = point as ITopologicalOperator;
18                     ISpatialFilter pSpatialFilter = FilterUtil.SpatialFilter(point as IGeometry, esriSpatialRelEnum.esriSpatialRelIntersects);  
19                     int count = pFeatureLayer.FeatureClass.FeatureCount(pSpatialFilter);
20                     if (count == 1)
21                     {
22                         IGeometry pGeometryPointBuffer =pTopologicalOperator.Buffer(distance);
23                         pGeometry = pTopologicalOperator.Buffer(distance) ;
24                         pSpatialFilter = FilterUtil.SpatialFilter(pGeometry, esriSpatialRelEnum.esriSpatialRelIntersects);
25                         if (pFeatureLayer.FeatureClass.FeatureCount(pSpatialFilter) > 1)
26                         {
27                             pElement = DisplayUtils.CircleMarkElement(point, innerColor, outLineColor, 8.0);
28                             pGraphicsContainer.AddElement(pElement, 0);
29                             listError.Add(point);
30                         }
31                     }
32                     else if (count > 1)
33                     {
34                         pFeatureCursor = pFeatureLayer.FeatureClass.Search(pSpatialFilter, true);
35                         pFeature = pFeatureCursor.NextFeature();
36                         int count2 = 0;
37                         while (pFeature != null)
38                         {
39                             IPointCollection pPointCollection = pFeature.Shape as IPointCollection;
40                             IPoint pPointtemp = new PointClass();
41                             for (int k = 0; k 1; k++)
42                             {
43                                 pPointCollection.QueryPoint(k, pPointtemp);
44                                 if (Math.Abs(pPointtemp.X - point.X) 0.001 && Math.Abs(pPointtemp.Y - point.Y) 0.001)
45                                 {
46                                     count2++;
47                                     break;
48                                 }
49                             }
50                             pFeature = pFeatureCursor.NextFeature();
51                         }
52                         if (count2  count)
53                         {
54                             pElement = DisplayUtils.CircleMarkElement(point, innerColor, outLineColor, 8.0);
55                             pGraphicsContainer.AddElement(pElement, 0);
56                             listError.Add(point);
57                         }
58                     }
59                 }
60             }
61             catch (Exception exp)
62             {
63                 ErrorF err = new ErrorF(exp.Message + "\r\n" + exp.StackTrace);
64                 err.Show();
65             }
66             finally
67             {
68                 Marshal.FinalReleaseComObject(pFeatureCursor);
69             }
70             return listError;
71         }
View Code

 

哪位有高效率的代码,求侮辱!

ArcGis 拓扑检查——缺顶点、悬挂检查代码 C#

标签:sea   img   end   ash   hook   check   ext   RKE   runtime   

原文地址:https://www.cnblogs.com/yzhyingcool/p/10026859.html


评论


亲,登录后才可以留言!