Example #1
0
        /// <summary>
        /// 多部分(多外环)的多边形转成多个单部分的多边形
        /// </summary>
        /// <param name="polygon"></param>
        /// <returns></returns>
        public static IPolygon[] MultiPartToSinglePart(this IPolygon4 polygon)
        {
            List <IPolygon> polygons = new List <IPolygon>();

            //外部环
            IGeometryBag        exteriorRingGeometryBag        = polygon.ExteriorRingBag;
            IGeometryCollection exteriorRingGeometryCollection = exteriorRingGeometryBag as IGeometryCollection;

            for (int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++)
            {
                IGeometry exteriorRingGeometry = exteriorRingGeometryCollection.get_Geometry(i);
                IRing     ring = exteriorRingGeometry as IRing;
                ring.Close();
                IGeometryCollection pGeometryColl = new PolygonClass();
                pGeometryColl.AddGeometry(ring);

                //内部环
                IGeometryBag        interiorRingGeometryBag        = polygon.get_InteriorRingBag(exteriorRingGeometry as IRing);
                IGeometryCollection interiorRingGeometryCollection = interiorRingGeometryBag as IGeometryCollection;
                for (int k = 0; k < interiorRingGeometryCollection.GeometryCount; k++)
                {
                    IGeometry interiorRingGeometry = interiorRingGeometryCollection.get_Geometry(k);
                    IRing     ring2 = interiorRingGeometry as IRing;
                    ring2.Close();
                    pGeometryColl.AddGeometry(ring2);
                }

                ITopologicalOperator pTopological = pGeometryColl as ITopologicalOperator;
                pTopological.Simplify();
                IPolygon p = pGeometryColl as IPolygon;
                polygons.Add(p);
            }
            return(polygons.ToArray());
        }
Example #2
0
        /// <summary>
        /// 获取多边形指定外环所包含的内环
        /// </summary>
        /// <param name="polygon">多边形</param>
        /// <param name="exteriorRing">外部环,此外部环必须是指定多边形的</param>
        /// <returns></returns>
        public static List <IRing> GetInteriorRings(this IPolygon4 polygon, IRing exteriorRing)
        {
            List <IRing>        rings = new List <IRing>();
            IGeometryBag        interiorRingGeometryBag        = polygon.get_InteriorRingBag(exteriorRing);
            IGeometryCollection interiorRingGeometryCollection = (IGeometryCollection)interiorRingGeometryBag;

            for (int k = 0; k < interiorRingGeometryCollection.GeometryCount; k++)
            {
                IGeometry interiorRingGeometry = interiorRingGeometryCollection.get_Geometry(k);
                rings.Add(interiorRingGeometry as IRing);
            }
            return(rings);
        }
Example #3
0
        private List <IRing> method_7(IRing iring_0, IPolygon ipolygon_0)
        {
            List <IRing>  list     = new List <IRing>();
            IPolygon4     polygon  = ipolygon_0 as IPolygon4;
            IEnumGeometry geometry = polygon.get_InteriorRingBag(iring_0) as IEnumGeometry;

            geometry.Reset();
            for (IRing ring = geometry.Next() as IRing; ring != null; ring = geometry.Next() as IRing)
            {
                list.Add(ring);
            }
            return(list);
        }
Example #4
0
        private IGeometry BufferExtAndIntBoundary(IPolygon4 polygon, double bufferDistance, bool draw)
        {
            IGeometry           bndBuffer;
            object              obj = Type.Missing;
            IGeometryCollection bufferGeometries = new GeometryBagClass() as IGeometryCollection;

            IGeometryBag  exteriorRings     = polygon.ExteriorRingBag;
            IEnumGeometry exteriorRingsEnum = exteriorRings as IEnumGeometry;

            exteriorRingsEnum.Reset();
            IRing currentExteriorRing = exteriorRingsEnum.Next() as IRing;

            while (currentExteriorRing != null)
            {
                bndBuffer = BufferBoundary(currentExteriorRing, bufferDistance, false);
                bufferGeometries.AddGeometry(bndBuffer, ref obj, ref obj);

                //IPolygon4.get_InteriorRingBag should be used instead of IPolygon.QueryInteriorRings,
                //which does not work in .NET because of C-Style Arrays
                IGeometryBag  interiorRings     = polygon.get_InteriorRingBag(currentExteriorRing);
                IEnumGeometry interiorRingsEnum = interiorRings as IEnumGeometry;
                interiorRingsEnum.Reset();
                IRing currentInteriorRing = interiorRingsEnum.Next() as IRing;
                while (currentInteriorRing != null)
                {
                    bndBuffer = BufferBoundary(currentInteriorRing, bufferDistance, false);
                    bufferGeometries.AddGeometry(bndBuffer, ref obj, ref obj);
                    currentInteriorRing = interiorRingsEnum.Next() as IRing;
                }
                currentExteriorRing = exteriorRingsEnum.Next() as IRing;
            }

            ITopologicalOperator topoBufferGeometries = bufferGeometries as ITopologicalOperator;

            topoBufferGeometries.Simplify();
            IPolygon             buffPolygon  = new PolygonClass();
            ITopologicalOperator topoPolygon  = buffPolygon as ITopologicalOperator;
            IEnumGeometry        enumGeometry = bufferGeometries as IEnumGeometry;

            topoPolygon.ConstructUnion(enumGeometry);
            if (draw)
            {
                DrawGraphics(buffPolygon as IGeometry);
            }
            return(buffPolygon as IGeometry);
        }
        public static IEnumerable <List <CPoint> > GetIpgInteriorCptLtEb(IPolygon4 ipg)
        {
            //ipg.Close();
            if (ipg.ExteriorRingCount != 1)
            {
                throw new ArgumentException(
                          "I have not considered such a complicated case! A hole contains other holes! ");
            }

            IRing2 pExteriorRing = (ipg.ExteriorRingBag as IGeometryCollection).get_Geometry(0) as IRing2;
            IGeometryCollection pGeoColInteriorRing = (IGeometryCollection)ipg.get_InteriorRingBag(pExteriorRing);

            for (int i = 0; i < pGeoColInteriorRing.GeometryCount; i++)
            {
                yield return(GetCptEbByICol(pGeoColInteriorRing.get_Geometry(i) as IPointCollection4).ToList());
            }
        }
Example #6
0
        public List <string> PolygonToString(IPolygon4 polygon)
        {
            List <string>       list = new List <string>();
            IGeometryBag        exteriorRingGeometryBag        = polygon.ExteriorRingBag;
            IGeometryCollection exteriorRingGeometryCollection = exteriorRingGeometryBag as IGeometryCollection;

            for (int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++)
            {
                IGeometry exteriorRingGeometry = exteriorRingGeometryCollection.get_Geometry(i);

                IGeometryBag        interiorRingGeometryBag        = polygon.get_InteriorRingBag(exteriorRingGeometry as IRing);
                IGeometryCollection interiorRingGeometryCollection = interiorRingGeometryBag as IGeometryCollection;;
                for (int k = 0; k < interiorRingGeometryCollection.GeometryCount; k++)
                {
                    IGeometry        interiorRingGeometry        = interiorRingGeometryCollection.get_Geometry(k);
                    IPointCollection interiorRingPointCollection = interiorRingGeometry as IPointCollection;
                    for (int m = 0; m < interiorRingPointCollection.PointCount; m++)
                    {
                        if (m == interiorRingPointCollection.PointCount - 1)
                        {
                            list.Add(PointToString(interiorRingPointCollection.get_Point(m)) + "-;");
                        }
                        else
                        {
                            list.Add(PointToString(interiorRingPointCollection.get_Point(m)) + ";");
                        }
                    }
                }

                IPointCollection exteriorRingPointCollection = exteriorRingGeometry as IPointCollection;
                for (int j = 0; j < exteriorRingPointCollection.PointCount; j++)
                {
                    if (j == exteriorRingPointCollection.PointCount - 1)
                    {
                        list.Add(PointToString(exteriorRingPointCollection.get_Point(j)) + "+;");
                    }
                    else
                    {
                        list.Add(PointToString(exteriorRingPointCollection.get_Point(j)) + ";");
                    }
                }
            }
            return(list);
        }
    //----------------------------------------------------------------------------------

    public static void SchrijfPolygon(IFeature pFeat)
    {
        IPolygon4 pPolygon = (IPolygon4)pFeat.ShapeCopy;

        //Schrijf aantal ringen
        IGeometryCollection GeoColl = (IGeometryCollection)pPolygon;
        int aantalringen            = GeoColl.GeometryCount;

        Naar3dsMax.binWriter.Write(aantalringen);     //int

        //Loop door Buitenringen
        IGeometryBag        BuitenringenVerzameling = pPolygon.ExteriorRingBag;
        IGeometryCollection Buitenringen            = (IGeometryCollection)BuitenringenVerzameling;
        int aantalBuitenringen = Buitenringen.GeometryCount;

        for (int i = 0; i < aantalBuitenringen; i++)
        {
            //Schrijf Buitenringvlag = true
            Boolean Buitenringvlag = true;
            WriteBoolean(Buitenringvlag);

            //Schrijf Buitenring
            IGeometry Buitenring = Buitenringen.get_Geometry(i);
            SchrijfRing(Buitenring);

            //Loop door Binnenringen
            IGeometryBag        BinnenringenVerzameling = pPolygon.get_InteriorRingBag(Buitenring as IRing);
            IGeometryCollection Binnenringen            = BinnenringenVerzameling as IGeometryCollection;
            int aantalBinnenringen = Binnenringen.GeometryCount;
            for (int k = 0; k < aantalBinnenringen; k++)
            {
                //Schrijf Buitenringvlag = false
                Buitenringvlag = false;
                WriteBoolean(Buitenringvlag);

                //Schrijf Binnenring
                IGeometry Binnenring = Binnenringen.get_Geometry(k);
                SchrijfRing(Binnenring);
            }
        }
    }
Example #8
0
        /// <summary>
        /// 根据外环获取到内环
        /// </summary>
        /// <param name="ring">外环</param>
        /// <param name="polygon">多边形</param>
        /// <returns></returns>
        public static IRing[] GetInteriorRingsByExterior(IRing ring, IPolygon polygon)
        {
            List <IRing> interRingList = new List <IRing>();
            IPolygon4    polygon4      = polygon as IPolygon4;

            IGeometryBag  interRings     = polygon4.get_InteriorRingBag(ring);
            IEnumGeometry interRingsEnum = interRings as IEnumGeometry;

            interRingsEnum.Reset();

            IRing tmpring = interRingsEnum.Next() as IRing;

            while (tmpring != null)
            {
                interRingList.Add(tmpring);

                tmpring = interRingsEnum.Next() as IRing;
            }

            return(interRingList.ToArray());
        }
Example #9
0
        private IList <IGeometry> GetGeometrys(IGeometry pGeo)
        {
            IList <IGeometry> list = new List <IGeometry>();

            try
            {
                if (pGeo.GeometryType == esriGeometryType.esriGeometryPolyline)
                {
                    IGeometryCollection geometrys = pGeo as IGeometryCollection;
                    int geometryCount             = geometrys.GeometryCount;
                    for (int i = 0; i < geometryCount; i++)
                    {
                        IGeometry inGeometry = geometrys.get_Geometry(i);
                        if (!inGeometry.IsEmpty)
                        {
                            IGeometryCollection geometrys2 = new PolylineClass();
                            object missing = System.Type.Missing;
                            geometrys2.AddGeometry(inGeometry, ref missing, ref missing);
                            IGeometry item = geometrys2 as IGeometry;
                            item.SpatialReference = pGeo.SpatialReference;
                            list.Add(item);
                        }
                    }
                    return(list);
                }
                if (pGeo.GeometryType == esriGeometryType.esriGeometryPolygon)
                {
                    IPolygon4 polygon = pGeo as IPolygon4;
                    if (polygon.ExteriorRingCount < 2)
                    {
                        list.Add(pGeo);
                        return(list);
                    }
                    IEnumGeometry exteriorRingBag = polygon.ExteriorRingBag as IEnumGeometry;
                    exteriorRingBag.Reset();
                    for (IRing ring = exteriorRingBag.Next() as IRing; ring != null; ring = exteriorRingBag.Next() as IRing)
                    {
                        IGeometryBag        bag2       = polygon.get_InteriorRingBag(ring);
                        object              before     = System.Type.Missing;
                        IGeometryCollection geometrys3 = null;
                        geometrys3 = new PolygonClass();
                        geometrys3.AddGeometry(ring, ref before, ref before);
                        IPolygon polygon2 = geometrys3 as IPolygon;
                        polygon2.SpatialReference = pGeo.SpatialReference;
                        ITopologicalOperator2 @operator = (ITopologicalOperator2)polygon2;
                        @operator.IsKnownSimple_2 = false;
                        @operator.Simplify();
                        if (!bag2.IsEmpty)
                        {
                            IGeometryCollection geometrys4 = new PolygonClass();
                            IEnumGeometry       geometry4  = bag2 as IEnumGeometry;
                            geometry4.Reset();
                            for (IRing ring2 = geometry4.Next() as IRing; ring2 != null; ring2 = geometry4.Next() as IRing)
                            {
                                geometrys4.AddGeometry(ring2, ref before, ref before);
                            }
                            IPolygon other = geometrys4 as IPolygon;
                            other.SpatialReference = pGeo.SpatialReference;
                            ITopologicalOperator2 operator2 = (ITopologicalOperator2)other;
                            operator2.IsKnownSimple_2 = false;
                            operator2.Simplify();
                            IGeometry geometry5 = @operator.Difference(other);
                            list.Add(geometry5);
                        }
                        else
                        {
                            list.Add(polygon2);
                        }
                    }
                }
                return(list);
            }
            catch
            {
                return(null);
            }
            return(list);
        }
Example #10
0
        /// <summary>
        /// 获取VCT面实体节点
        /// </summary>
        public override EntityNode GetEntityNode()
        {
            try
            {
                m_PolygonNode = new PolygonNode();
                IFeature pFeature = this.Feature as IFeature;
                ///标识码赋值
                int dBSMIndex = -1;
                dBSMIndex = this.Feature.Fields.FindField(m_strEntityIDFiled);
                if (dBSMIndex != -1)
                    m_PolygonNode.EntityID = Convert.ToInt32(this.Feature.get_Value(dBSMIndex));

                ///图形表现赋值 
                 //m_PolygonNode.Representation = pFeature.Class.AliasName;

                ///要素代码赋值
                //int dSYDMIndex = -1;
                //dSYDMIndex = this.Feature.Fields.FindField(m_strYSDMField);
                //if (dSYDMIndex != -1)
                //    m_PolygonNode.FeatureCode = this.Feature.get_Value(dSYDMIndex).ToString();
                //string sAttriTableName = (pFeature.Class as IDataset).Name;
                //m_PolygonNode.FeatureCode = MetaDataFile.GetFeatureCodeByName(sAttriTableName);
                m_PolygonNode.FeatureCode = this.FeatureCode;

                //设置间接坐标面构成类型、面特征类型、图形表现代码
                m_PolygonNode.PolygonType = 100;
                //m_PolygonNode.Representation = pFeature.Class.AliasName;

                ///add by 曾平 2011-9-7 添加裁切
                IGeometry pFeatureGeometry = null;
                if (m_bCut)
                {
                     pFeatureGeometry = GetSubGeometry();
                    if (pFeatureGeometry == null)
                    {
                        pFeatureGeometry = pFeature.Shape;
                    }
                }
                else
                {
                    pFeatureGeometry = pFeature.Shape;
                }

                IPolygon4 pGeoPolygon = pFeatureGeometry as IPolygon4;
                List<LineNodeEx> pListNodeEx = new List<LineNodeEx>();

                IGeometryBag pExteriorRings = pGeoPolygon.ExteriorRingBag;
                ///获取外环集合
                IEnumGeometry pExteriorRingsEnum = pExteriorRings as IEnumGeometry;
                pExteriorRingsEnum.Reset();
                IRing pCurrentExteriorRing = pExteriorRingsEnum.Next() as IRing;

                ////构面的线段要素代码都是面的要素代码
                string strLineFeatureCode =m_PolygonNode.FeatureCode;
                string strRepresentation = m_PolygonNode.Representation;


                ///遍历所有外环及关联的内环
                while (pCurrentExteriorRing != null)
                {
                    ///设置当前外环数据
                    //List<LineNodeEx> pListExLine = GetLineByRing(pCurrentExteriorRing, strLineFeatureCode,strRepresentation, m_PolygonNode.EntityID);
                    List<LineNodeEx> pListExLine = GetLineNodeExsByRing(pCurrentExteriorRing, strLineFeatureCode, strRepresentation, m_PolygonNode.EntityID);
                    if (pListExLine != null)
                    {
                        pListNodeEx.AddRange(pListExLine);

                        ///不相连的环添加标识码为0的空数据
                        LineNodeEx pOutTempLineNodeEx = new LineNodeEx();
                        pOutTempLineNodeEx.EntityID = 0;
                        pOutTempLineNodeEx.PolygonID = m_PolygonNode.EntityID;
                        pListNodeEx.Add(pOutTempLineNodeEx);

                        ///获取当前外环的关联内环
                        IGeometryBag pInteriorRings = pGeoPolygon.get_InteriorRingBag(pCurrentExteriorRing);
                        IEnumGeometry pInteriorRingsEnum = pInteriorRings as IEnumGeometry;
                        pInteriorRingsEnum.Reset();
                        IRing pCurrentInteriorRing = pInteriorRingsEnum.Next() as IRing;
                        ////遍历内环
                        while (pCurrentInteriorRing != null)
                        {

                            List<LineNodeEx> pListInLine = GetLineByRing(pCurrentInteriorRing, strLineFeatureCode, strRepresentation, m_PolygonNode.EntityID);
                            if (pListInLine != null)
                            {
                                pListNodeEx.AddRange(pListInLine);

                                ///不相连的环添加标识码为0的空数据
                                LineNodeEx pInTempLineNodeEx = new LineNodeEx();
                                pInTempLineNodeEx.EntityID = 0;
                                pInTempLineNodeEx.PolygonID = m_PolygonNode.EntityID;
                                pListNodeEx.Add(pInTempLineNodeEx);

                            }

                            //处理下一个内环
                            pCurrentInteriorRing = pInteriorRingsEnum.Next() as IRing;
                        }
                    }
                    ///处理下一个外环
                    pCurrentExteriorRing = pExteriorRingsEnum.Next() as IRing;
                }

                ///删除集合中最后一位补零线段
                if (pListNodeEx.Count>0&& pListNodeEx[pListNodeEx.Count - 1].EntityID == 0)
                    pListNodeEx.RemoveAt(pListNodeEx.Count - 1);
                m_PolygonNode.LineNodes = pListNodeEx;
                //获取标志点
                IArea pArea = pFeature.Shape as IArea;
                if (pArea != null)
                    m_PolygonNode.LablePointInfoNode = new PointInfoNode(pArea.LabelPoint.X, pArea.LabelPoint.Y);
                return m_PolygonNode;
            }
            catch (Exception ex)
            {
                LogAPI.WriteErrorLog(ex);
                return null;
            }
        }
Example #11
0
 /// <summary>
 /// 获取多边形指定外环所包含的内环的数量
 /// </summary>
 /// <param name="polygon"></param>
 /// <param name="exteriorRing"></param>
 /// <returns></returns>
 public static int GetInnerRingCount(this IPolygon4 polygon, IRing exteriorRing)
 {
     return(((IGeometryCollection)polygon.get_InteriorRingBag(exteriorRing)).GeometryCount);
 }
Example #12
0
        public void OtherRule(string idname, string checkname, string IN_RuleType, string TABLENAME, string SUPTABLE, string inputtext, IHookHelper m_hookHelper)
        {
            CommonClass common = new CommonClass();

            IFeatureClass     IN_FeatureClass     = common.GetLayerByName(TABLENAME).FeatureClass;
            IGeoDataset       pGeoDataset         = IN_FeatureClass as IGeoDataset;
            ISpatialReference spatialReference    = pGeoDataset.SpatialReference;
            IFeatureClass     IN_Sup_FeatureClass = null;

            if (SUPTABLE != null)
            {
                IN_Sup_FeatureClass = common.GetLayerByName(SUPTABLE).FeatureClass;
            }
            string ErrorFilePath = this.topoDir + "\\" + checkname + idname + ".shp";

            if (IN_RuleType == "面多部件检查")
            {
                try
                {
                    common.CreatShpFile(this.topoDir, spatialReference, esriGeometryType.esriGeometryPolygon, checkname + idname);
                    List <ErrorEntity> list   = new List <ErrorEntity>();
                    IFeatureCursor     cursor = IN_FeatureClass.Search(null, false);
                    int      tempCount        = 0;
                    IFeature pFeature         = cursor.NextFeature();
                    while (pFeature != null)
                    {
                        IGeometry            pGeo          = pFeature.ShapeCopy;
                        ITopologicalOperator pTopoOperator = pGeo as ITopologicalOperator;
                        int iCount = 0;
                        if (IN_FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                        {
                            iCount = (pGeo as IPolygon).ExteriorRingCount;
                        }
                        else if (IN_FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                        {
                            iCount = ((pGeo as IPolyline) as IGeometryCollection).GeometryCount;
                        }
                        else if (IN_FeatureClass.ShapeType == esriGeometryType.esriGeometryMultipoint)
                        {
                            iCount = ((pGeo as IMultipoint) as IPointCollection).PointCount;
                        }
                        if (iCount > 1)
                        {
                            tempCount++;
                            common.GenerateSHPFile(pFeature.ShapeCopy, ErrorFilePath);
                        }
                        pFeature = cursor.NextFeature();
                    }
                    //new ErrorTable().AddErr(list, ErrType.MultiPart, idname);
                    if (!DicTopoError.ContainsKey(idname))
                    {
                        DicTopoError.Add(idname, tempCount);
                    }
                    else
                    {
                        DicTopoError[idname] = tempCount;
                    }

                    Marshal.ReleaseComObject(cursor);

                    if (tempCount == 0)
                    {
                        string            shpFolder         = System.IO.Path.GetDirectoryName(ErrorFilePath);
                        IWorkspaceFactory pWorkspaceFac     = new ShapefileWorkspaceFactoryClass();
                        IWorkspace        pWorkSpace        = pWorkspaceFac.OpenFromFile(ErrorFilePath, 0);
                        IFeatureWorkspace pFeatureWorkSpace = pWorkSpace as IFeatureWorkspace;
                        if (System.IO.File.Exists(ErrorFilePath))
                        {
                            IFeatureClass pFCChecker = pFeatureWorkSpace.OpenFeatureClass(ErrorFilePath);
                            if (pFCChecker != null)
                            {
                                IDataset pds = pFCChecker as IDataset;
                                pds.Delete();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog(typeof(TopoChecker), ex);
                }
            }
            else if (IN_RuleType == "面自相交检查")
            {
                int errorCount = 0;
                try
                {
                    common.CreatShpFile(this.topoDir, spatialReference, esriGeometryType.esriGeometryPoint, checkname + idname);
                    IFeatureLayer pLayer = new FeatureLayer();
                    pLayer.FeatureClass = IN_FeatureClass;
                    TopoClassChecker topo = new TopoClassChecker();

                    IFeatureCursor cursor;
                    IQueryFilter   filter = new QueryFilterClass();
                    filter.SubFields = pLayer.FeatureClass.OIDFieldName + "," + pLayer.FeatureClass.ShapeFieldName;
                    cursor           = pLayer.FeatureClass.Search(filter, true);
                    IFeature feature = null;
                    object   missing = Type.Missing;
                    while ((feature = cursor.NextFeature()) != null)
                    {
                        IPoint              tempPoint = null;
                        StringBuilder       builder   = new StringBuilder();
                        IGeometryCollection shape     = feature.Shape as IGeometryCollection;
                        for (int i = 0; i < shape.GeometryCount; i++)
                        {
                            esriNonSimpleReasonEnum enum2;
                            IPointCollection        newPoints = shape.get_Geometry(i) as IPointCollection;
                            IRing ring = newPoints as IRing;
                            int   num2 = 0;
                            if (ring.IsClosed)
                            {
                                num2 = 1;
                            }
                            PolylineClass o = new PolylineClass();
                            o.AddPointCollection(newPoints);
                            o.SpatialReference = spatialReference;

                            ITopologicalOperator3 @operator = o;
                            @operator.IsKnownSimple_2 = false;
                            if ([email protected]_IsSimpleEx(out enum2) && (enum2 == esriNonSimpleReasonEnum.esriNonSimpleSelfIntersections))
                            {
                                List <string> list2 = new List <string>();
                                List <string> list3 = new List <string>();
                                for (int j = num2; j < newPoints.PointCount; j++)
                                {
                                    IPoint point = newPoints.get_Point(j);
                                    tempPoint = point;
                                    string item = point.X.ToString() + "," + point.Y.ToString();
                                    if (list2.Contains(item))
                                    {
                                        if (!list3.Contains(item))
                                        {
                                            builder.Append(";");
                                            builder.Append(item);
                                            list3.Add(item);
                                        }
                                    }
                                    else
                                    {
                                        list2.Add(item);
                                    }
                                }
                            }
                            Marshal.ReleaseComObject(o);
                            o = null;
                        }
                        if (builder.Length > 0)
                        {
                            errorCount++;

                            string[] strArray = builder.ToString().Substring(1).Split(new char[] { ';' });
                            ESRI.ArcGIS.Geometry.IPointCollection pPointCollection1 = new ESRI.ArcGIS.Geometry.MultipointClass();
                            foreach (string str in strArray)
                            {
                                if (!string.IsNullOrEmpty(str))
                                {
                                    string[] strArray2 = str.Split(new char[] { ',' });
                                    double   pX        = double.Parse(strArray2[0]);
                                    double   pY        = double.Parse(strArray2[1]);
                                    ESRI.ArcGIS.Geometry.IPoint point = new ESRI.ArcGIS.Geometry.PointClass();
                                    point.X = pX;
                                    point.Y = pY;
                                    common.GenerateSHPFile(point, ErrorFilePath);
                                }
                            }
                        }
                    }
                    Marshal.ReleaseComObject(cursor);
                    if (errorCount == 0)
                    {
                        string            shpFolder         = System.IO.Path.GetDirectoryName(ErrorFilePath);
                        IWorkspaceFactory pWorkspaceFac     = new ShapefileWorkspaceFactoryClass();
                        IWorkspace        pWorkSpace        = pWorkspaceFac.OpenFromFile(ErrorFilePath, 0);
                        IFeatureWorkspace pFeatureWorkSpace = pWorkSpace as IFeatureWorkspace;
                        if (System.IO.File.Exists(ErrorFilePath))
                        {
                            IFeatureClass pFCChecker = pFeatureWorkSpace.OpenFeatureClass(ErrorFilePath);
                            if (pFCChecker != null)
                            {
                                IDataset pds = pFCChecker as IDataset;
                                pds.Delete();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog(typeof(TopoChecker), ex);
                }
                if (!DicTopoError.ContainsKey(idname))
                {
                    DicTopoError.Add(idname, errorCount);
                }
                else
                {
                    DicTopoError[idname] = errorCount;
                }
            }
            else if (IN_RuleType == "缝隙检查")
            {
                int errorCount = 0;
                try
                {
                    common.CreatShpFile(this.topoDir, spatialReference, esriGeometryType.esriGeometryPolygon, checkname + idname);
                    this.m_hookHelper = m_hookHelper;
                    IFeatureClass pFClass = IN_FeatureClass;
                    //获取空间参考
                    IGeometry   geometryBag = new GeometryBagClass();
                    IGeoDataset geoDataset  = pFClass as IGeoDataset;
                    geometryBag.SpatialReference = geoDataset.SpatialReference;

                    ////属性过滤
                    IFeatureCursor featureCursor = pFClass.Search(null, false);

                    // 遍历游标
                    IFeature            currentFeature     = featureCursor.NextFeature();
                    IGeometryCollection geometryCollection = geometryBag as IGeometryCollection;
                    object missing = Type.Missing;
                    while (currentFeature != null)
                    {
                        geometryCollection.AddGeometry(currentFeature.Shape, ref missing, ref missing);
                        currentFeature = featureCursor.NextFeature();
                    }

                    // 合并要素
                    ITopologicalOperator unionedPolygon = null;
                    unionedPolygon = new Polygon() as ITopologicalOperator;
                    unionedPolygon.ConstructUnion(geometryCollection as IEnumGeometry);

                    Marshal.ReleaseComObject(featureCursor);
                    IPolygon4           pMergerPolygon     = unionedPolygon as IPolygon4;
                    IGeometryBag        pOutGeometryBag    = pMergerPolygon.ExteriorRingBag; //获取外部环
                    IGeometryCollection pOutGmtyCollection = pOutGeometryBag as IGeometryCollection;

                    for (int i = 0; i < pOutGmtyCollection.GeometryCount; i++)   //对外部环遍历
                    {
                        IGeometry pOutRing = pOutGmtyCollection.get_Geometry(i); //外部环
                        //【此处可以对外部环进行操作】
                        IPointCollection pOutRingCollection = pOutRing as IPointCollection;
                        for (int j = 0; j < pOutRingCollection.PointCount; j++)
                        {
                            IPoint pOutRingPoint = pOutRingCollection.get_Point(j);//获取外环上的点
                        }

                        IGeometryBag        pInteriotGeometryBag        = pMergerPolygon.get_InteriorRingBag(pOutRing as IRing); //获取内部环
                        IGeometryCollection pInteriorGeometryCollection = pInteriotGeometryBag as IGeometryCollection;

                        for (int j = 0; j < pInteriorGeometryCollection.GeometryCount; j++)
                        {
                            ISegmentCollection SegCol = pInteriorGeometryCollection.get_Geometry(j) as ISegmentCollection;

                            IPolygon           PPolygon  = new PolygonClass();
                            ISegmentCollection newSegCol = PPolygon as ISegmentCollection;
                            newSegCol.AddSegmentCollection(SegCol);
                            //pInteriorGeometry即为多边形的内部环
                            IGeometry inRing = PPolygon as IGeometry;
                            inRing.SpatialReference = geometryBag.SpatialReference;
                            IArea  area    = inRing as IArea;
                            Double getarea = System.Math.Abs(Convert.ToDouble(area.Area));
                            if (inputtext == null || inputtext == "" || getarea < Convert.ToDouble(inputtext))
                            {
                                Boolean        flag   = true;
                                ISpatialFilter filter = new SpatialFilterClass();
                                filter.Geometry   = inRing;
                                filter.SubFields  = pFClass.OIDFieldName + "," + pFClass.ShapeFieldName;
                                filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                IFeatureCursor o       = pFClass.Search(filter, true);
                                IFeature       feature = o.NextFeature();
                                while (feature != null && flag)
                                {
                                    IPolygon4           pPolygon           = feature.Shape as IPolygon4;
                                    IGeometryBag        iOutGeometryBag    = pPolygon.ExteriorRingBag; //获取外部环
                                    IGeometryCollection iOutGmtyCollection = iOutGeometryBag as IGeometryCollection;

                                    for (int m = 0; m < iOutGmtyCollection.GeometryCount && flag; m++)  //对外部环遍历
                                    {
                                        IGeometry           outGeo     = iOutGmtyCollection.get_Geometry(m);
                                        IGeometryCollection polyGonGeo = new PolygonClass();
                                        polyGonGeo.AddGeometry(outGeo);
                                        IPolygon iPolygon = polyGonGeo as IPolygon;
                                        iPolygon.SimplifyPreserveFromTo();
                                        IRelationalOperator2 pRelationalOperator2 = iPolygon as IRelationalOperator2;
                                        if (!pRelationalOperator2.Contains(inRing))
                                        {
                                            errorCount++;
                                            common.GenerateSHPFile(inRing, ErrorFilePath);
                                            flag = false;
                                        }
                                    }
                                    feature = o.NextFeature();
                                }
                                Marshal.ReleaseComObject(o);
                            }
                        }
                        if (errorCount == 0)
                        {
                            string            shpFolder         = System.IO.Path.GetDirectoryName(ErrorFilePath);
                            IWorkspaceFactory pWorkspaceFac     = new ShapefileWorkspaceFactoryClass();
                            IWorkspace        pWorkSpace        = pWorkspaceFac.OpenFromFile(ErrorFilePath, 0);
                            IFeatureWorkspace pFeatureWorkSpace = pWorkSpace as IFeatureWorkspace;
                            if (System.IO.File.Exists(ErrorFilePath))
                            {
                                IFeatureClass pFCChecker = pFeatureWorkSpace.OpenFeatureClass(ErrorFilePath);
                                if (pFCChecker != null)
                                {
                                    IDataset pds = pFCChecker as IDataset;
                                    pds.Delete();
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog(typeof(TopoChecker), ex);
                }
                if (!DicTopoError.ContainsKey(idname))
                {
                    DicTopoError.Add(idname, errorCount);
                }
                else
                {
                    DicTopoError[idname] = errorCount;
                }
            }
            else if (IN_RuleType == "面重叠检查")
            {
                IFeatureClass outIFC = null;
                this.m_hookHelper = m_hookHelper;
                ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect();
                string outString = this.topoDir + "\\" + checkname + idname + ".shp";
                intersect.in_features       = common.GetPathByName(TABLENAME);
                intersect.out_feature_class = outString;
                Geoprocessor geoProcessor = new Geoprocessor();
                geoProcessor.OverwriteOutput = true;
                try
                {
                    if (this.gp == null)
                    {
                        this.gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                    }
                    IGeoProcessorResult result = (IGeoProcessorResult)this.gp.Execute(intersect, null);

                    if (result.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
                    {
                        Console.WriteLine("gp工具执行错误");
                    }
                    else
                    {
                        outIFC = this.gp.Open(result.ReturnValue) as IFeatureClass;
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog(typeof(TopoChecker), ex);
                    Console.WriteLine(ex.Message);
                }

                if (outIFC.FeatureCount(null) == 0)
                {
                    string            shpFolder         = System.IO.Path.GetDirectoryName(ErrorFilePath);
                    IWorkspaceFactory pWorkspaceFac     = new ShapefileWorkspaceFactoryClass();
                    IWorkspace        pWorkSpace        = pWorkspaceFac.OpenFromFile(ErrorFilePath, 0);
                    IFeatureWorkspace pFeatureWorkSpace = pWorkSpace as IFeatureWorkspace;
                    if (System.IO.File.Exists(ErrorFilePath))
                    {
                        IFeatureClass pFCChecker = pFeatureWorkSpace.OpenFeatureClass(ErrorFilePath);
                        if (pFCChecker != null)
                        {
                            IDataset pds = pFCChecker as IDataset;
                            pds.Delete();
                        }
                    }
                }

                if (!DicTopoError.ContainsKey(idname))
                {
                    DicTopoError.Add(idname, outIFC.FeatureCount(null));
                }
                else
                {
                    DicTopoError[idname] = outIFC.FeatureCount(null);
                }
            }
            else if (IN_RuleType == "面重叠检查(与其他图层)")
            {
                IFeatureClass outIFC = null;
                this.m_hookHelper = m_hookHelper;
                ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect();
                string outString = this.topoDir + "\\" + checkname + idname + ".shp";
                intersect.in_features       = @common.GetPathByName(TABLENAME) + ";" + @common.GetPathByName(SUPTABLE);
                intersect.out_feature_class = outString;
                Geoprocessor geoProcessor = new Geoprocessor();
                geoProcessor.OverwriteOutput = true;
                try
                {
                    if (this.gp == null)
                    {
                        this.gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                    }
                    IGeoProcessorResult result = (IGeoProcessorResult)this.gp.Execute(intersect, null);

                    if (result.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
                    {
                        Console.WriteLine("gp工具执行错误");
                    }
                    else
                    {
                        outIFC = this.gp.Open(result.ReturnValue) as IFeatureClass;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    LogHelper.WriteLog(typeof(TopoChecker), ex);
                }
                if (outIFC.FeatureCount(null) == 0)
                {
                    string            shpFolder         = System.IO.Path.GetDirectoryName(ErrorFilePath);
                    IWorkspaceFactory pWorkspaceFac     = new ShapefileWorkspaceFactoryClass();
                    IWorkspace        pWorkSpace        = pWorkspaceFac.OpenFromFile(ErrorFilePath, 0);
                    IFeatureWorkspace pFeatureWorkSpace = pWorkSpace as IFeatureWorkspace;
                    if (System.IO.File.Exists(ErrorFilePath))
                    {
                        IFeatureClass pFCChecker = pFeatureWorkSpace.OpenFeatureClass(ErrorFilePath);
                        if (pFCChecker != null)
                        {
                            IDataset pds = pFCChecker as IDataset;
                            pds.Delete();
                        }
                    }
                }
                if (!DicTopoError.ContainsKey(idname))
                {
                    DicTopoError.Add(idname, outIFC.FeatureCount(null));
                }
                else
                {
                    DicTopoError[idname] = outIFC.FeatureCount(null);
                }
            }
            Marshal.ReleaseComObject(IN_FeatureClass);
            if (SUPTABLE != null)
            {
                Marshal.ReleaseComObject(IN_Sup_FeatureClass);
            }
        }
Example #13
0
        /// <summary>
        /// 缝隙检查。融合后去内环。
        /// </summary>
        /// <param name="pFeature"></param>
        /// <returns></returns>
        public List <Dictionary <string, IGeometry> > CheckFeatureGap(IFeatureClass pFClass, string inputtext)
        {
            List <Dictionary <string, IGeometry> > listGeo = new List <Dictionary <string, IGeometry> >();

            if (pFClass == null)
            {
                return(null);
            }

            //Stopwatch watch = new Stopwatch();
            //watch.Start();

            //获取空间参考
            IGeometry   geometryBag = new GeometryBagClass();
            IGeoDataset geoDataset  = pFClass as IGeoDataset;

            geometryBag.SpatialReference = geoDataset.SpatialReference;

            ////属性过滤
            //ISpatialFilter queryFilter = new SpatialFilterClass();
            //queryFilter.SubFields = "Shape";
            IFeatureCursor featureCursor = pFClass.Search(null, false);

            // 遍历游标
            IFeature currentFeature = featureCursor.NextFeature();

            if (currentFeature == null)
            {
                return(null);
            }
            IGeometryCollection geometryCollection = geometryBag as IGeometryCollection;
            object missing = Type.Missing;

            while (currentFeature != null)
            {
                geometryCollection.AddGeometry(currentFeature.Shape, ref missing, ref missing);
                currentFeature = featureCursor.NextFeature();
            }

            // 合并要素
            ITopologicalOperator unionedPolygon = null;

            if (pFClass.ShapeType == esriGeometryType.esriGeometryPoint)
            {
                unionedPolygon = new Multipoint() as ITopologicalOperator;
                unionedPolygon.ConstructUnion(geometryCollection as IEnumGeometry);
            }
            else if (pFClass.ShapeType == esriGeometryType.esriGeometryPolyline)
            {
                unionedPolygon = new Polyline() as ITopologicalOperator;
                unionedPolygon.ConstructUnion(geometryCollection as IEnumGeometry);
            }
            else
            {
                unionedPolygon = new Polygon() as ITopologicalOperator;
                unionedPolygon.ConstructUnion(geometryCollection as IEnumGeometry);
            }
            Marshal.ReleaseComObject(featureCursor);
            IPolygon4           pMergerPolygon     = unionedPolygon as IPolygon4;
            IGeometryBag        pOutGeometryBag    = pMergerPolygon.ExteriorRingBag; //获取外部环
            IGeometryCollection pOutGmtyCollection = pOutGeometryBag as IGeometryCollection;

            for (int i = 0; i < pOutGmtyCollection.GeometryCount; i++)   //对外部环遍历
            {
                IGeometry pOutRing = pOutGmtyCollection.get_Geometry(i); //外部环
                //【此处可以对外部环进行操作】
                IPointCollection pOutRingCollection = pOutRing as IPointCollection;
                for (int j = 0; j < pOutRingCollection.PointCount; j++)
                {
                    IPoint pOutRingPoint = pOutRingCollection.get_Point(j);//获取外环上的点
                }

                IGeometryBag        pInteriotGeometryBag        = pMergerPolygon.get_InteriorRingBag(pOutRing as IRing); //获取内部环
                IGeometryCollection pInteriorGeometryCollection = pInteriotGeometryBag as IGeometryCollection;


                for (int j = 0; j < pInteriorGeometryCollection.GeometryCount; j++)
                {
                    ISegmentCollection SegCol = pInteriorGeometryCollection.get_Geometry(j) as ISegmentCollection;

                    IPolygon           PPolygon  = new PolygonClass();
                    ISegmentCollection newSegCol = PPolygon as ISegmentCollection;
                    newSegCol.AddSegmentCollection(SegCol);
                    //pInteriorGeometry即为多边形的内部环
                    IGeometry inRing = PPolygon as IGeometry;
                    inRing.SpatialReference = geometryBag.SpatialReference;
                    IArea  area    = inRing as IArea;
                    Double getarea = System.Math.Abs(Convert.ToDouble(area.Area));
                    if (inputtext == null || inputtext == "" || getarea < Convert.ToDouble(inputtext))
                    {
                        Boolean        flag   = true;
                        ISpatialFilter filter = new SpatialFilterClass();
                        filter.Geometry   = inRing;
                        filter.SubFields  = pFClass.OIDFieldName + "," + pFClass.ShapeFieldName;
                        filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                        IFeatureCursor o       = pFClass.Search(filter, true);
                        IFeature       feature = o.NextFeature();
                        while (feature != null && flag)
                        {
                            Console.WriteLine(feature.OID);
                            IPolygon4           pPolygon           = feature.Shape as IPolygon4;
                            IGeometryBag        iOutGeometryBag    = pPolygon.ExteriorRingBag; //获取外部环
                            IGeometryCollection iOutGmtyCollection = iOutGeometryBag as IGeometryCollection;

                            for (int m = 0; m < iOutGmtyCollection.GeometryCount && flag; m++)  //对外部环遍历
                            {
                                IGeometry           outGeo     = iOutGmtyCollection.get_Geometry(m);
                                IGeometryCollection polyGonGeo = new PolygonClass();
                                polyGonGeo.AddGeometry(outGeo);
                                IPolygon iPolygon = polyGonGeo as IPolygon;
                                iPolygon.SimplifyPreserveFromTo();
                                IRelationalOperator2 pRelationalOperator2 = iPolygon as IRelationalOperator2;
                                if (!pRelationalOperator2.Contains(inRing))
                                {
                                    Dictionary <string, IGeometry> itemDic = new Dictionary <string, IGeometry>();
                                    itemDic.Add(feature.OID.ToString(), inRing);
                                    listGeo.Add(itemDic);
                                    flag = false;
                                }
                            }
                            feature = o.NextFeature();
                        }
                        Marshal.ReleaseComObject(o);
                    }
                }
            }
            if (listGeo.Count > 0)
            {
                return(listGeo);
            }
            else
            {
                return(null);
            }
        }
        private void CutSelectedPolygon()
        {
            bool isSuccess = false;

            if (m_selectedFeature == null)
            {
                MessageBox.Show("请先选择要分割的面要素!!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                m_toolPhase = ToolPhase.SelectFeature;
                return;
            }

            //在屏幕上绘制用于分割的线要素
            IScreenDisplay    screenDisplay = m_activeView.ScreenDisplay;
            ISimpleLineSymbol sym           = new SimpleLineSymbolClass();
            IRgbColor         color         = new RgbColorClass();

            color.Red   = 255;
            color.Green = 128;
            color.Blue  = 128;
            sym.Color   = color;
            sym.Style   = esriSimpleLineStyle.esriSLSSolid;
            sym.Width   = 2;
            IRubberBand cutBand         = new RubberLineClass();
            IGeometry   reshaprGeometry = cutBand.TrackNew(screenDisplay, sym as ISymbol);

            screenDisplay.StartDrawing(screenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
            screenDisplay.SetSymbol(sym as ISymbol);
            screenDisplay.DrawPolyline(reshaprGeometry);
            screenDisplay.FinishDrawing();

            IFeatureClass  featureClass  = m_selectedFeature.Class as IFeatureClass;
            IDataset       dataset       = featureClass as IDataset;
            IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit;

            if (!(workspaceEdit.IsBeingEdited()))
            {
                return;
            }

            //分割选择的面要素
            if (reshaprGeometry.IsEmpty == true)
            {
                return;
            }
            try
            {
                IPolyline           reshapePolyline, sourcePolyline = null;
                IPolygon4           polygon = null;
                IRing               ring = null, innerRing = null, outRing = null;
                IPath               reshapePath    = null;
                IGeometryCollection pathCollection = null;

                IGeometry geometry = m_selectedFeature.Shape;
                switch (geometry.GeometryType)
                {
                case esriGeometryType.esriGeometryPolygon:
                    bool                outerSuccess = false, innerSuccess = false;
                    IGeometryBag        innerRingGeometryBag        = null;
                    IGeometryCollection innerRingGeometryCollection = null;
                    reshapePolyline = reshaprGeometry as IPolyline;
                    pathCollection  = reshapePolyline as IGeometryCollection;
                    //只可能产生一条polyline,直接写死
                    reshapePath = pathCollection.Geometry[0] as IPath;
                    polygon     = geometry as IPolygon4;
                    IGeometryBag        exteriorRingGeometryBag        = polygon.ExteriorRingBag;
                    IGeometryCollection exteriorRingGeometryCollection = exteriorRingGeometryBag as IGeometryCollection;
                    for (int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++)
                    {
                        outRing = exteriorRingGeometryCollection.Geometry[i] as IRing;
                        bool a = outRing.Reshape(reshapePath);
                        outerSuccess = outerSuccess || a;

                        innerRingGeometryBag        = polygon.get_InteriorRingBag(outRing);
                        innerRingGeometryCollection = innerRingGeometryBag as IGeometryCollection;
                        for (int j = 0; j < innerRingGeometryCollection.GeometryCount; j++)
                        {
                            innerRing = innerRingGeometryCollection.Geometry[j] as IRing;
                            bool b = innerRing.Reshape(reshapePath);
                            innerSuccess = innerSuccess || b;
                        }
                    }
                    isSuccess = innerSuccess || outerSuccess;
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    sourcePolyline  = geometry as IPolyline;
                    reshapePolyline = reshaprGeometry as IPolyline;
                    pathCollection  = reshapePolyline as IGeometryCollection;
                    //只可能产生一条polyline,直接写死
                    reshapePath = pathCollection.Geometry[0] as IPath;
                    isSuccess   = sourcePolyline.Reshape(reshapePath);
                    break;
                }

                if (isSuccess)
                {
                    workspaceEdit.StartEditOperation();
                    m_selectedFeature.Shape = geometry;//如果没加这句gdb无法编辑
                    m_selectedFeature.Store();
                    m_activeView.Refresh();
                    workspaceEdit.StopEditOperation();
                }
                else
                {
                    throw new Exception("重塑要素失败!");
                }
                m_activeView.Refresh();
            }
            catch (Exception ex)
            {
                workspaceEdit.AbortEditOperation();
                MessageBox.Show("分割面要素失败!!" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_activeView.Extent);
            m_toolPhase = ToolPhase.SelectFeature;
        }