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

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

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

实现思路是这样的:

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

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

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

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

下面贴代码

取点集,去个重:

class UserPoints
    {
        public static  List<IPoint> FeatureLayer2PointList(IFeatureLayer pFeatureLayer)
        {
            List<IPoint> pointList = new List<IPoint>();
            IFeatureCursor pFeatureCursor = pFeatureLayer.FeatureClass.Search(null, true);
            try
            {
                IFeature pFeatuare = pFeatureCursor.NextFeature();
                while (pFeatuare != null)
                {
                    IPointCollection pcol = pFeatuare.Shape as IPointCollection;
                    for (int i = 0; i < pcol.PointCount - 1; i++)
                    {
                        pointList.Add(pcol.Point[i]);
                    }
                    pFeatuare = pFeatureCursor.NextFeature();
                }
                pointList = pointList.Distinct(new Compare()).ToList<IPoint>();
            }
            catch (Exception exp)
            {
                ErrorF err = new ErrorF(exp.Message + "\r\n" + exp.StackTrace);
                err.Show();
            }
            finally
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);             
            }
            return pointList;
        }
    }

    class Compare : IEqualityComparer<IPoint>
    {

        bool IEqualityComparer<IPoint>.Equals(IPoint a, IPoint b)
        {
            if (a == null && b == null)
                return false;
            else
                return Math.Round(a.X, 4) == Math.Round(b.X, 4) && Math.Round(a.Y, 4) == Math.Round(b.Y, 4);
        }

        int IEqualityComparer<IPoint>.GetHashCode(IPoint obj)
        {
            return obj.ToString().GetHashCode();
        }
    }

拓扑一下:

public static List<IPoint> CheckLackJunctionPointOrSuspendedPoint(IFeatureLayer pFeatureLayer, double distance)
        {
            IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)m_hookHelper.FocusMap.ActiveGraphicsLayer;
            pGraphicsContainer.DeleteAllElements();
            IColor innerColor = new RgbColorClass();
            innerColor.NullColor = true;
            IColor outLineColor = DisplayUtils.RGBColor(255, 0, 0);
            IElement pElement;
            List<IPoint> listError = new List<IPoint>();
            IFeatureCursor pFeatureCursor=null;
            IFeature pFeature;
            try
            {
                IGeometry pGeometry;
                foreach (IPoint point in UserPoints.FeatureLayer2PointList(pFeatureLayer))
                {
                    ITopologicalOperator pTopologicalOperator = point as ITopologicalOperator;
                    ISpatialFilter pSpatialFilter = FilterUtil.SpatialFilter(point as IGeometry, esriSpatialRelEnum.esriSpatialRelIntersects);  
                    int count = pFeatureLayer.FeatureClass.FeatureCount(pSpatialFilter);
                    if (count == 1)
                    {
                        IGeometry pGeometryPointBuffer =pTopologicalOperator.Buffer(distance);
                        pGeometry = pTopologicalOperator.Buffer(distance) ;
                        pSpatialFilter = FilterUtil.SpatialFilter(pGeometry, esriSpatialRelEnum.esriSpatialRelIntersects);
                        if (pFeatureLayer.FeatureClass.FeatureCount(pSpatialFilter) > 1)
                        {
                            pElement = DisplayUtils.CircleMarkElement(point, innerColor, outLineColor, 8.0);
                            pGraphicsContainer.AddElement(pElement, 0);
                            listError.Add(point);
                        }
                    }
                    else if (count > 1)
                    {
                        pFeatureCursor = pFeatureLayer.FeatureClass.Search(pSpatialFilter, true);
                        pFeature = pFeatureCursor.NextFeature();
                        int count2 = 0;
                        while (pFeature != null)
                        {
                            IPointCollection pPointCollection = pFeature.Shape as IPointCollection;
                            IPoint pPointtemp = new PointClass();
                            for (int k = 0; k < pPointCollection.PointCount - 1; k++)
                            {
                                pPointCollection.QueryPoint(k, pPointtemp);
                                if (Math.Abs(pPointtemp.X - point.X) < 0.001 && Math.Abs(pPointtemp.Y - point.Y) < 0.001)
                                {
                                    count2++;
                                    break;
                                }
                            }
                            pFeature = pFeatureCursor.NextFeature();
                        }
                        if (count2 < count)
                        {
                            pElement = DisplayUtils.CircleMarkElement(point, innerColor, outLineColor, 8.0);
                            pGraphicsContainer.AddElement(pElement, 0);
                            listError.Add(point);
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                ErrorF err = new ErrorF(exp.Message + "\r\n" + exp.StackTrace);
                err.Show();
            }
            finally
            {
                Marshal.FinalReleaseComObject(pFeatureCursor);
            }
            return listError;
        }

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

转载自:https://blog.csdn.net/qq_29011299/article/details/84797020

You may also like...