Example #1
0
        /// <summary>
        /// 将Envelope转换为多边形
        /// </summary>
        /// <param name="layerExtent">Envelope</param>
        /// <param name="pPolygon">结果多边形</param>
        /// <returns>操作结果</returns>
        public static bool ExchangeToPolygon(IEnvelope layerExtent, ref IPolygon4 pPolygon)
        {
            try
            {
                object           Missing   = Type.Missing;
                IPoint           pPoint    = new PointClass();
                IPointCollection pPointCol = new PolygonClass();
                pPoint.PutCoords(layerExtent.XMin, layerExtent.YMax);
                pPointCol.AddPoint(pPoint, ref Missing, ref Missing);
                pPoint.PutCoords(layerExtent.XMax, layerExtent.YMax);
                pPointCol.AddPoint(pPoint, ref Missing, ref Missing);
                pPoint.PutCoords(layerExtent.XMax, layerExtent.YMin);
                pPointCol.AddPoint(pPoint, ref Missing, ref Missing);
                pPoint.PutCoords(layerExtent.XMin, layerExtent.YMin);
                pPointCol.AddPoint(pPoint, ref Missing, ref Missing);
                pPoint.PutCoords(layerExtent.XMin, layerExtent.YMax);
                pPointCol.AddPoint(pPoint, ref Missing, ref Missing);
                pPolygon = pPointCol as IPolygon4;
                return(true);
            }
            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// 多边形是否由多部分组成(即是否多个外环)
        /// </summary>
        /// <param name="polygon"></param>
        /// <returns></returns>
        public static bool IsMultiPart(this IPolygon4 polygon)
        {
            IGeometryBag        exteriorRingGeometryBag        = polygon.ExteriorRingBag;
            IGeometryCollection exteriorRingGeometryCollection = exteriorRingGeometryBag as IGeometryCollection;

            return(exteriorRingGeometryCollection.GeometryCount > 1);
        }
Example #3
0
        /// <summary>
        /// Helper function to get a polygon object from the selected feature in the
        /// specified layer.
        /// </summary>
        /// <param name="layerName">The polygon layer that contains exactly one selected feature.</param>
        /// <returns>The polygon object, or null if none could be retrieved.</returns>
        private IPolygon4 GetPolygonFromSpecifiedLayer(ILayer layerObj)
        {
            // Set the AOI of the job, if there is one
            // Ensure that there's nothing wrong with the AOI feature that is selected, if any
            IPolygon4 aoiPolygon = null;

            if (layerObj != null)
            {
                ICursor           cursor    = null;
                IFeatureLayer     featLayer = layerObj as IFeatureLayer;
                IFeatureSelection featSel   = layerObj as IFeatureSelection;
                ISelectionSet     selSet    = featSel.SelectionSet as ISelectionSet;

                if (featLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolygon)
                {
                    throw new WmauException(new WmauError(WmauErrorCodes.C_AOI_NOT_POLYGON_ERROR));
                }
                else if (selSet.Count != 1)
                {
                    throw new WmauException(new WmauError(WmauErrorCodes.C_EXPECTED_ONE_SELECTED_FEATURE_ERROR));
                }

                // If we get this far, we know that there's exactly one selected feature, so we
                // don't have to loop through the selection set
                selSet.Search(null, true, out cursor);
                IFeatureCursor featureCursor = cursor as IFeatureCursor;
                IFeature       aoiCandidate  = featureCursor.NextFeature();

                // We also know that the feature is a polygon, so just make the cast
                aoiPolygon = aoiCandidate.Shape as IPolygon4;
            }

            return(aoiPolygon);
        }
Example #4
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 #5
0
        /// <summary>
        /// 获取构成多边形的所有环的点集(包括外环和内环),返回的环内的点集统一按顺时针或逆时针排序
        /// </summary>
        /// <param name="polygon"></param>
        /// <param name="clockwise">时针方向,true为顺时针,false为逆时针</param>
        /// <returns></returns>
        public static List <List <IPoint> > GetRingPointsByClockwise(this IPolygon4 polygon, bool clockwise)
        {
            List <List <IPoint> > rings = new List <List <IPoint> >();
            //外部环
            IGeometryBag        exteriorRingGeometryBag        = polygon.ExteriorRingBag;//全部外部环
            IGeometryCollection exteriorRingGeometryCollection = (IGeometryCollection)exteriorRingGeometryBag;

            for (int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++)
            {
                IGeometry        exteriorRingGeometry        = exteriorRingGeometryCollection.get_Geometry(i);
                IPointCollection exteriorRingPointCollection = exteriorRingGeometry as IPointCollection;
                var exteriorPoints = exteriorRingPointCollection.GetPointList();
                if (!clockwise)//外环的点是顺时针排序的,要求逆时针排序时反序List
                {
                    exteriorPoints.Reverse();
                }
                rings.Add(exteriorPoints);                                                         //外部环

                var interiorRings = GetInteriorRingPoints(polygon, exteriorRingGeometry as IRing); //内部环
                if (clockwise)                                                                     //内环的点是逆时针排序的,要求顺时针排序时反序List
                {
                    foreach (var ring in interiorRings)
                    {
                        ring.Reverse();
                    }
                }
                rings.AddRange(interiorRings);
            }
            return(rings);
        }
Example #6
0
        private IPolygon4 GetIntersectionWithAreasOfInterest(
            [NotNull] IPolygon4 multiGapPolygon,
            [NotNull] IEnvelope clipEnvelope)
        {
            if (_tileAreasOfInterest.Count == 0)
            {
                // return entire combined gap polygon
                return(multiGapPolygon);
            }

            ISpatialReference spatialReference = multiGapPolygon.SpatialReference;

            // clip the areas of interest before unioning
            IPolygon unionedAreaOfInterest = UnionPolygons(
                GetClippedPolygons(_tileAreasOfInterest, clipEnvelope),
                spatialReference);

            GeometryUtils.AllowIndexing(unionedAreaOfInterest);

            var topoOp       = (ITopologicalOperator)multiGapPolygon;
            var intersection = (IPolygon4)topoOp.Intersect(
                unionedAreaOfInterest,
                esriGeometryDimension.esriGeometry2Dimension);

            return(intersection);
        }
 /// <summary>
 ///   Initializes a new instance of the <see cref="GetSolarPotentialCommand" /> class.
 /// </summary>
 /// <param name="polygon"> The polygon. </param>
 /// <param name="propertyValueIndexMap"> The property value index map. </param>
 /// <param name="durationThreshhold"> The duration threshhold. </param>
 public GetSolarPotentialCommand(IPolygon4 polygon,
                                 Dictionary <MonthTypeContainer, IndexFieldMap> propertyValueIndexMap,
                                 double durationThreshhold)
 {
     _polygon = polygon;
     _propertyValueIndexMap = propertyValueIndexMap;
     _durationThreshhold    = durationThreshhold;
 }
Example #8
0
        public static ISegmentCollection GetSegmentCollectionOfPolygon(IGeometry pGeometry)
        {
            IPolygon4     pPolygon            = pGeometry as IPolygon4;
            IGeometryBag  exteriorRings       = pPolygon.ExteriorRingBag;
            IEnumGeometry exteriorRingsEnum   = exteriorRings as IEnumGeometry;
            IRing         currentExteriorRing = exteriorRingsEnum.Next() as IRing;

            return(currentExteriorRing as ISegmentCollection);
        }
Example #9
0
        /// <summary>
        /// 获取构成多边形的所有环的数量
        /// </summary>
        /// <param name="polygon"></param>
        /// <returns></returns>
        public static int GetRingCount(this IPolygon4 polygon)
        {
            int count = 0;
            IGeometryCollection exteriorRingGeometryCollection = (IGeometryCollection)polygon.ExteriorRingBag;//全部外部环

            for (int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++)
            {
                count++;
                IGeometry exteriorRingGeometry = exteriorRingGeometryCollection.get_Geometry(i);
                count += GetInnerRingCount(polygon, exteriorRingGeometry as IRing); //内部环
            }
            return(count);
        }
Example #10
0
        /// <summary>
        /// 获取多边形的外环
        /// </summary>
        /// <param name="polygon"></param>
        /// <returns></returns>
        public static List <IRing> GetExteriorRings(this IPolygon4 polygon)
        {
            List <IRing>        rings = new List <IRing>();
            IGeometryBag        exteriorRingGeometryBag        = polygon.ExteriorRingBag;//全部外部环
            IGeometryCollection exteriorRingGeometryCollection = (IGeometryCollection)exteriorRingGeometryBag;

            for (int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++)
            {
                IGeometry exteriorRingGeometry = exteriorRingGeometryCollection.get_Geometry(i);
                rings.Add(exteriorRingGeometry as IRing);
            }
            return(rings);
        }
Example #11
0
        private List <IRing> method_6(IPolygon ipolygon_0)
        {
            IPolygon4     polygon         = ipolygon_0 as IPolygon4;
            List <IRing>  list            = new List <IRing>();
            IEnumGeometry exteriorRingBag = polygon.ExteriorRingBag as IEnumGeometry;

            exteriorRingBag.Reset();
            for (IRing ring = exteriorRingBag.Next() as IRing; ring != null; ring = exteriorRingBag.Next() as IRing)
            {
                list.Add(ring);
            }
            return(list);
        }
Example #12
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 #13
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 #14
0
        /// <summary>
        /// chenyafei  20110420  add :获得要素的坐标串
        /// </summary>
        /// <param name="pFea"></param>
        /// <returns></returns>
        private string GetCoor(IGeometry pInGeo)
        {
            if (pInGeo.IsEmpty)
            {
                return("");
            }
            string CoorStr = "";

            if (pInGeo.GeometryType == esriGeometryType.esriGeometryPoint)
            {
                IPoint mPnt = pInGeo as IPoint;
                CoorStr = mPnt.X + "," + mPnt.Y;
            }
            else if (pInGeo.GeometryType == esriGeometryType.esriGeometryPolyline)
            {
                IPointCollection pPntColl = pInGeo as IPointCollection;
                for (int i = 0; i < pPntColl.PointCount; i++)
                {
                    IPoint pPnt = pPntColl.get_Point(i);
                    CoorStr += pPnt.X + "," + pPnt.Y + ";";
                }
                if (CoorStr != "")
                {
                    CoorStr = CoorStr.Substring(0, CoorStr.Length - 1);
                }
            }
            else if (pInGeo.GeometryType == esriGeometryType.esriGeometryPolygon)
            {
                IPolygon4 pPolygon4  = pInGeo as IPolygon4;
                int       pRingCount = pPolygon4.ExteriorRingCount;
                if (pRingCount > 0)
                {
                    IGeometryBag  pGeoBag  = pPolygon4.ExteriorRingBag;
                    IEnumGeometry pEnumGeo = pGeoBag as IEnumGeometry;
                    pEnumGeo.Reset();
                    IGeometry        mGeo     = pEnumGeo.Next();
                    IPointCollection pPntColl = mGeo as IPointCollection;
                    for (int i = 0; i < pPntColl.PointCount; i++)
                    {
                        IPoint pPnt = pPntColl.get_Point(i);
                        CoorStr += pPnt.X + "," + pPnt.Y + ";";
                    }
                    if (CoorStr != "")
                    {
                        CoorStr = CoorStr.Substring(0, CoorStr.Length - 1);
                    }
                }
            }
            return(CoorStr);
        }
Example #15
0
        public static void MatchCpg(ref List <CPolygon> pLSCPgLt, ref List <CPolygon> pSSCPgLt, ref List <CPolygon> InterLSAttentionCPgLt, ref List <CPolygon> SSAttentionCPgLt)
        {
            //for a SSCPg, we calculate the intersect area with each exsiting InterLSCPg, and calcuate the intersect area
            foreach (var cpg in pLSCPgLt)
            {
                cpg.isMatched = false;
            }

            foreach (var pSSCPg in pSSCPgLt)
            {
                pSSCPg.CorrCGeoLt = new List <CGeoBase>();
                ITopologicalOperator pSSCPgTop = pSSCPg.pPolygon as ITopologicalOperator;

                foreach (var cpg in pLSCPgLt)
                {
                    if (cpg.isMatched == false)
                    {
                        //Console.WriteLine(pSSCPg.CptLt[0].X);
                        //Console.WriteLine(pSSCPg.CptLt[0].Y);
                        //Console.WriteLine(cpg.CptLt[0].X);
                        //Console.WriteLine(cpg.CptLt[0].Y);

                        IPolygon4 ipg = cpg.pPolygon;
                        double    dblIntersectArea  = (pSSCPgTop.Intersect(ipg as IGeometry, esriGeometryDimension.esriGeometry2Dimension) as IArea).Area;
                        double    dblIntersectRatio = dblIntersectArea / (ipg as IArea).Area;

                        if (dblIntersectRatio > 0.5)
                        {
                            pSSCPg.CorrCGeoLt.Add(cpg);
                            cpg.isMatched = true;
                        }
                    }
                }

                if (pSSCPg.CorrCGeoLt.Count == 0)
                {
                    SSAttentionCPgLt.Add(pSSCPg);
                }
            }


            //InterLSAttentionCPgLt
            foreach (var lscpg in pLSCPgLt)
            {
                if (lscpg.isMatched == false)
                {
                    InterLSAttentionCPgLt.Add(lscpg);
                }
            }
        }
        protected IEnumerable <IRing> GetInteriorRings(IPolygon4 polygon, IRing exteriorRing)
        {
            var interiorRings = (IGeometryCollection)polygon.InteriorRingBag[exteriorRing];

            for (int i = 0, n = interiorRings.GeometryCount; i < n; i++)
            {
                var ring            = (IRing)interiorRings.Geometry[i];
                var pointCollection = (IPointCollection)ring;

                if (ring.IsClosed && pointCollection.PointCount > 3 && ring.Length > _serializerSettings.Tolerance)
                {
                    yield return(ring);
                }
            }
        }
        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 #18
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);
        }
Example #19
0
        /// <summary>
        /// 获取构成多边形的所有环的点集(包括外环和内环)
        /// </summary>
        /// <param name="polygon"></param>
        /// <returns></returns>
        public static List <List <IPoint> > GetRingPoints(this IPolygon4 polygon)
        {
            List <List <IPoint> > rings = new List <List <IPoint> >();
            //外部环
            IGeometryBag        exteriorRingGeometryBag        = polygon.ExteriorRingBag;//全部外部环
            IGeometryCollection exteriorRingGeometryCollection = (IGeometryCollection)exteriorRingGeometryBag;

            for (int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++)
            {
                IGeometry        exteriorRingGeometry        = exteriorRingGeometryCollection.get_Geometry(i);
                IPointCollection exteriorRingPointCollection = exteriorRingGeometry as IPointCollection;
                var exteriorPoints = exteriorRingPointCollection.GetPointList();
                rings.Add(exteriorPoints);                                                     //外部环
                rings.AddRange(GetInteriorRingPoints(polygon, exteriorRingGeometry as IRing)); //内部环
            }
            return(rings);
        }
Example #20
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);
        }
Example #21
0
        /// <summary>
        /// 获取多边形的所有外环
        /// </summary>
        /// <param name="polygon">多边形</param>
        /// <returns></returns>
        public static IRing[] GetExteriorRings(IPolygon polygon)
        {
            IPolygon4    polygon4         = polygon as IPolygon4;
            List <IRing> exteriorRingList = new List <IRing>();

            IGeometryBag  exteriorRings    = polygon4.ExteriorRingBag;
            IEnumGeometry exteriorRingEnum = exteriorRings as IEnumGeometry;
            //exteriorRingEnum.Reset();
            IRing ring = exteriorRingEnum.Next() as IRing;

            while (ring != null)
            {
                exteriorRingList.Add(ring);

                ring = exteriorRingEnum.Next() as IRing;
            }

            return(exteriorRingList.ToArray());
        }
Example #22
0
        public void explode(string timeStep)
        {
            try
            {
                //string newFileName = "explode" + timeStepPath;
                IFeatureClass ifc = getShapeFile("TimeStep" + timeStep);


                // Copy each feature from the original feature class to the new feature class
                IFeatureCursor      loopCursor = ifc.Search(null, false);
                IFeatureCursor      insertCurr = ifc.Insert(false);
                IFeatureBuffer      insertBuff = ifc.CreateFeatureBuffer();
                IFeature            feature;
                IGeometryCollection geometryColl;

                while ((feature = loopCursor.NextFeature()) != null)
                {
                    geometryColl = feature.Shape as IGeometryCollection;
                    IPolygon4           poly4 = feature.Shape as IPolygon4;
                    IGeometryCollection gc    = poly4.ConnectedComponentBag as IGeometryCollection;
                    for (int i = 0; i < poly4.ExteriorRingCount; i++)
                    {
                        InsertFeature(insertCurr, insertBuff, feature, gc.get_Geometry(i));
                    }
                    feature.Delete();
                }

                System.Runtime.InteropServices.Marshal.ReleaseComObject(loopCursor);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(insertCurr);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(insertBuff);
                // this.updateSpatialIndex();
            }

            catch (System.Exception ex)
            {
#if (DEBUG)
                System.Windows.Forms.MessageBox.Show(ex.Message);
#endif
                eLog.Debug(ex);
            }
        }
    //----------------------------------------------------------------------------------

    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 #24
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());
        }
    //----------------------------------------------------------------------------------

    public static void SchrijfPolygonSimpel(IFeature pFeat)
    {
        IPolygon4           pPolygon = (IPolygon4)pFeat.ShapeCopy;
        IGeometryCollection GeoColl  = (IGeometryCollection)pPolygon;

        //Schrijf aantal ringen
        int aantalringen = GeoColl.GeometryCount;

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

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

            //Schrijf Ring
            IGeometry Ring = GeoColl.get_Geometry(i);
            SchrijfRing(Ring);
        }
    }
        //static int intCount = 0;

        /// <summary>
        /// 通过面要素(IPolygon4)获取点数组
        /// </summary>
        /// <param name="ipg">面要素</param>
        /// <returns>点数组</returns>
        /// <remarks>currently, we assume that there is only one exterior ring for ipg</remarks>
        public static IEnumerable <CPoint> GetIpgExteriorCptLt(IPolygon4 ipg)
        {
            //ipg.Close();


            IRing2 pExteriorRing = (ipg.ExteriorRingBag as IGeometryCollection).get_Geometry(0) as IRing2;
            var    cptlt         = GetCptEbByICol(pExteriorRing as IPointCollection4).ToList();

            if (ipg.ExteriorRingCount != 1)
            {
                var x1 = cptlt[0].X;
                var y1 = cptlt[0].Y;
                //var x = pCol.Point[0].X;
                //var y = pCol.Point[0].Y;
                throw new ArgumentException(
                          "I have not considered such a complicated case! A hole contains other holes! ");
            }



            return(cptlt);
        }
Example #27
0
        private void splitFeature(IPolygon4 subPoly, ref HashSet <IPolygon4>[] polys)
        {
            IRaster clipRs = rsUtil.createRaster(rsUtil.clipRasterFunction(inputRaster, subPoly, esriRasterClippingType.esriRasterClippingOutside));

            esriUtil.Statistics.dataPrepClusterBinary dpClus = new Statistics.dataPrepClusterBinary(clipRs, specificity, 100000, 0.001);
            IFunctionRasterDataset clusRs     = rsUtil.calcClustFunctionBinary(inputRaster, dpClus);
            IFunctionRasterDataset clipRs2    = rsUtil.clipRasterFunction(clusRs, subPoly, esriRasterClippingType.esriRasterClippingOutside);
            IRasterDomainExtractor domExtract = new RasterDomainExtractorClass();

            for (int i = 0; i < specificity; i++)
            {
                IFunctionRasterDataset bRs  = rsUtil.calcEqualFunction(clipRs2, i);
                IRaster             mRs     = rsUtil.createRaster(rsUtil.setNullValue(bRs, 0));
                IPolygon4           poly    = (IPolygon4)domExtract.ExtractDomain(mRs, false);
                IGeometryBag        geoBag  = poly.ConnectedComponentBag;
                IGeometryCollection geoColl = (IGeometryCollection)geoBag;
                for (int j = 0; j < geoColl.GeometryCount; j++)
                {
                    IPolygon4 sp          = (IPolygon4)geoColl.get_Geometry(j);
                    double    subPolyArea = ((IArea)sp).Area;
                    //double subPolyLength = subPoly.Length;
                    if (subPolyArea > maxArea)
                    {
                        splitFeature(sp, ref polys); // should split polygons. smaller than acceptable go into polys[0] ok go into polys[1]
                    }
                    else if (subPolyArea < minArea)
                    {
                        polys[0].Add(sp);
                    }
                    else
                    {
                        polys[1].Add(sp);
                    }
                    //segid++;
                }
            }
        }
Example #28
0
        /// <summary>
        /// Identifies each exterior ring as separate part, containing all its interior rings
        /// </summary>
        /// <param name="polygon"></param>
        /// <returns></returns>
        private static IEnumerable <GeometryPart> GetPolygonExteriorRingParts(
            [NotNull] IPolygon4 polygon)
        {
            // for all interior rings, assign to exterior ring's part
            // all exterior rings, add them to result if not yet added
            var partsByExteriorRing = new Dictionary <IRing, GeometryPart>();

            var geometryCollection = (IGeometryCollection)polygon;

            for (var i = 0; i < geometryCollection.GeometryCount; i++)
            {
                var ring = (IRing)geometryCollection.Geometry[i];

                if (ring.IsExterior)
                {
                    partsByExteriorRing.Add(ring, new GeometryPart(ring));
                }
                else
                {
                    IRing exteriorRing = polygon.FindExteriorRing(ring);

                    Assert.NotNull("No exterior ring found for inner ring");

                    GeometryPart part;
                    if (!partsByExteriorRing.TryGetValue(exteriorRing, out part))
                    {
                        part = new GeometryPart(exteriorRing);
                        partsByExteriorRing.Add(exteriorRing, part);
                    }

                    part.AddInnerRingGeometry(ring);
                }
            }

            return(partsByExteriorRing.Values);
        }
Example #29
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 #30
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;
            }
        }
 private void splitFeature(IPolygon4 subPoly, ref HashSet<IPolygon4>[] polys)
 {
     IRaster clipRs = rsUtil.createRaster(rsUtil.clipRasterFunction(inputRaster, subPoly, esriRasterClippingType.esriRasterClippingOutside));
     esriUtil.Statistics.dataPrepClusterBinary dpClus = new Statistics.dataPrepClusterBinary(clipRs, specificity,100000,0.001);
     IFunctionRasterDataset clusRs = rsUtil.calcClustFunctionBinary(inputRaster, dpClus);
     IFunctionRasterDataset clipRs2 = rsUtil.clipRasterFunction(clusRs, subPoly, esriRasterClippingType.esriRasterClippingOutside);
     IRasterDomainExtractor domExtract = new RasterDomainExtractorClass();
     for (int i = 0; i < specificity; i++)
     {
         IFunctionRasterDataset bRs = rsUtil.calcEqualFunction(clipRs2, i);
         IRaster mRs = rsUtil.createRaster(rsUtil.setNullValue(bRs, 0));
         IPolygon4 poly = (IPolygon4)domExtract.ExtractDomain(mRs, false);
         IGeometryBag geoBag = poly.ConnectedComponentBag;
         IGeometryCollection geoColl = (IGeometryCollection)geoBag;
         for (int j = 0; j < geoColl.GeometryCount; j++)
         {
             IPolygon4 sp = (IPolygon4)geoColl.get_Geometry(j);
             double subPolyArea = ((IArea)sp).Area;
             //double subPolyLength = subPoly.Length;
             if (subPolyArea > maxArea)
             {
                 splitFeature(sp, ref polys); // should split polygons. smaller than acceptable go into polys[0] ok go into polys[1]
             }
             else if (subPolyArea < minArea)
             {
                 polys[0].Add(sp);
             }
             else
             {
                 polys[1].Add(sp);
             }
             //segid++;
         }
     }
 }
Example #32
0
        /// <summary>
        /// 将Envelope转换为多边形
        /// </summary>
        /// <param name="layerExtent">Envelope</param>
        /// <param name="pPolygon">结果多边形</param>
        /// <returns>操作结果</returns>
        public static bool ExchangeToPolygon(IEnvelope layerExtent, ref IPolygon4 pPolygon)
        {
            try
            {
                object Missing = Type.Missing;
                IPoint pPoint = new PointClass();
                IPointCollection pPointCol = new PolygonClass();
                pPoint.PutCoords(layerExtent.XMin, layerExtent.YMax);
                pPointCol.AddPoint(pPoint, ref Missing, ref Missing);
                pPoint.PutCoords(layerExtent.XMax, layerExtent.YMax);
                pPointCol.AddPoint(pPoint, ref Missing, ref Missing);
                pPoint.PutCoords(layerExtent.XMax, layerExtent.YMin);
                pPointCol.AddPoint(pPoint, ref Missing, ref Missing);
                pPoint.PutCoords(layerExtent.XMin, layerExtent.YMin);
                pPointCol.AddPoint(pPoint, ref Missing, ref Missing);
                pPoint.PutCoords(layerExtent.XMin, layerExtent.YMax);
                pPointCol.AddPoint(pPoint, ref Missing, ref Missing);
                pPolygon = pPointCol as IPolygon4;
                return true;
            }
            catch(Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                return false;
            }
        }