Ejemplo n.º 1
0
        public IList <IPolygon> Buffer([NotNull] IGeometryBag inputBag,
                                       [NotNull] IEnumerable <double> distances)
        {
            Assert.ArgumentNotNull(inputBag, nameof(inputBag));
            Assert.ArgumentNotNull(distances, nameof(distances));

            if (inputBag.IsEmpty || HasOnlyEmptyElements((IEnumGeometry)inputBag))
            {
                return(new List <IPolygon>(0));
            }

            // NOTE: ConstructBuffersByDistances2() does NOT assign the spatial reference
            //		 to the output collection. ConstructBuffers() does.
            IGeometryCollection outputCollection = PrepareTemplateBag(inputBag.SpatialReference);

            try
            {
                _construction.ConstructBuffersByDistances2((IEnumGeometry)inputBag,
                                                           GetDoubleArray(distances),
                                                           outputCollection);

                return(GetOutput(outputCollection));
            }
            finally
            {
                ResetTemplateBag();
            }
        }
Ejemplo n.º 2
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());
        }
Ejemplo n.º 3
0
        public void CanCreateBagWithCopies()
        {
            ISpatialReference sref =
                SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95);
            IGeometry pt1 = GeometryFactory.CreatePoint(100, 200, 0);
            IGeometry pt2 = GeometryFactory.CreatePoint(100, 200, 0);

            pt1.SpatialReference = sref;

            IGeometryBag bag = GeometryFactory.CreateBag(pt1, pt2);

            var collection = (IGeometryCollection)bag;

            Assert.AreEqual(2, collection.GeometryCount);
            IGeometry bagPt1 = collection.get_Geometry(0);
            IGeometry bagPt2 = collection.get_Geometry(1);

            // expect copies in the bag
            Assert.AreNotEqual(pt1, bagPt1);
            Assert.AreNotEqual(pt2, bagPt2);

            Assert.IsTrue(
                SpatialReferenceUtils.AreEqual(sref, bag.SpatialReference, true, true));
            Assert.IsTrue(
                SpatialReferenceUtils.AreEqual(sref, bagPt1.SpatialReference, true,
                                               true));
            Assert.IsTrue(
                SpatialReferenceUtils.AreEqual(sref, bagPt2.SpatialReference, true,
                                               true));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 为GeometryBag生成空间索引(提高查询效率)
        /// </summary>
        /// <param name="geometryBag"></param>
        public static void CreateSpatialIndex(this IGeometryBag geometryBag)
        {
            ISpatialIndex spatialIndex = (ISpatialIndex)geometryBag;

            spatialIndex.AllowIndexing = true;
            spatialIndex.Invalidate();
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        private static string ConvertInteriorRingsToGeoJson(IGeometryBag interiorRingGeometryBag)
        {
            var output = new StringBuilder();
            var interiorRingGeometryCollection = interiorRingGeometryBag as IGeometryCollection;

            if (interiorRingGeometryCollection != null && interiorRingGeometryCollection.GeometryCount > 0)
            {
                output.Append(",");
            }
            else
            {
                return(string.Empty);
            }

            for (var i = 0; i < interiorRingGeometryCollection.GeometryCount; i++)
            {
                if (i != 0)
                {
                    output.Append(", ");
                }

                output.Append("[[");
                var interiorRingGeometry = interiorRingGeometryCollection.Geometry[i];
                output.Append(ConvertPointCollectionToGeoJson(interiorRingGeometry));
                output.Append("]]");
            }

            return(output.ToString());
        }
Ejemplo n.º 8
0
        public IGeometryBag ConstructPolygonByLine(IGeometryBag igeometryBag_0)
        {
            int                 i;
            IPolygon            polygon;
            IGeometryCollection geometryBagClass = new GeometryBag() as IGeometryCollection;
            object              value            = Missing.Value;
            IArray              array            = this.SplitLine(igeometryBag_0);

            int[]  numArray   = new int[array.Count];
            IArray arrayClass = new Array();

            for (i = 0; i < array.Count; i++)
            {
                numArray[i] = 0;
            }
            IGeometry element  = null;
            IGeometry geometry = null;

            for (i = 0; i < array.Count; i++)
            {
                element = array.Element[i] as IGeometry;
                IPolyline polyline = (IPolyline)element;
                geometry = element;
                if (this.method_3(array, polyline.FromPoint) != 1 && this.method_3(array, polyline.ToPoint) != 1)
                {
                    if (!polyline.IsClosed)
                    {
                        if ((numArray[i] & 2) == 0)
                        {
                            numArray[i] = numArray[i] | 2;
                            polygon     = this.BulidPoly(array, numArray, geometry, false);
                            if (polygon != null)
                            {
                                geometryBagClass.AddGeometry(polygon, ref value, ref value);
                            }
                        }
                        if ((numArray[i] & 1) == 0)
                        {
                            numArray[i] = numArray[i] | 1;
                            polygon     = this.BulidPoly(array, numArray, geometry, true);
                            if (polygon != null)
                            {
                                geometryBagClass.AddGeometry(polygon, ref value, ref value);
                            }
                        }
                    }
                    else
                    {
                        ISegmentCollection polygonClass = new Polygon() as ISegmentCollection;
                        polygonClass.AddSegmentCollection((ISegmentCollection)polyline);
                        polygon = (IPolygon)polygonClass;
                        ((ITopologicalOperator)polygon).Simplify();
                        geometryBagClass.AddGeometry(polygon, ref value, ref value);
                    }
                }
            }
            return((IGeometryBag)geometryBagClass);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        private ILayer GetLayerByTreeNode(TreeNode treeNode)
        {
            ILayer layer = null;

            if (treeNode.Tag != null)
            {
                if (treeNode.Tag is IFeatureClass && treeNode.Checked)
                {
                    try
                    {
                        IFeatureClass featCls = (IFeatureClass)treeNode.Tag;
                        layer = new FeatureLayerClass();
                        (layer as IFeatureLayer).FeatureClass = featCls;
                        layer.Name = featCls.AliasName;

                        if (m_geoBag == null)
                        {
                            m_geoBag = new GeometryBagClass();
                        }

                        (m_geoBag as IGeometryCollection).AddGeometry((featCls as IGeoDataset).Extent);
                    }
                    catch
                    {
                        layer = null;
                    }
                }
                else if (treeNode.Tag is IFeatureDataset)
                {
                    foreach (TreeNode childNode in treeNode.Nodes)
                    {
                        ILayer subLayer = GetLayerByTreeNode(childNode);
                        if (subLayer != null)
                        {
                            try
                            {
                                if (layer == null)
                                {
                                    layer      = new GroupLayerClass();
                                    layer.Name = (treeNode.Tag as IFeatureDataset).Name;
                                }

                                (layer as IGroupLayer).Add(subLayer);
                            }
                            catch
                            {
                            }
                        }
                    }
                }
            }

            return(layer);
        }
Ejemplo n.º 11
0
        private static IEnumerable <IPolygon> GetSmallestDisjointPolygons(
            [NotNull] IPolygon polygon)
        {
            IGeometryBag connectedComponents = ((IPolygon4)polygon).ConnectedComponentBag;

            List <IPolygon> polygons =
                GeometryUtils.GetParts((IGeometryCollection)connectedComponents)
                .Cast <IPolygon>()
                .ToList();

            return(TestUtils.GetSmallestPolygons(polygons, polygons.Count - 1));
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
0
        private static IPolygon UnionPolygons([NotNull] IEnumerable <IGeometry> polygons,
                                              [CanBeNull] ISpatialReference spatialReference)
        {
            const bool   allowProjectingInput = true;
            IGeometryBag bag = GeometryFactory.CreateBag(polygons,
                                                         CloneGeometry.IfChangeNeeded,
                                                         spatialReference,
                                                         allowProjectingInput);

            var result = new PolygonClass
            {
                SpatialReference = spatialReference
            };

            result.ConstructUnion((IEnumGeometry)bag);

            return(result);
        }
Ejemplo n.º 18
0
        public override bool SplitAtPoint(IPoint ipoint_0, out IGeometryBag igeometryBag_0)
        {
            bool flag;
            bool flag1;
            int  num;
            int  num1;
            int  i;

            igeometryBag_0 = null;
            IPolycurve mPGeometry = this.m_pGeometry as IPolycurve;

            if (mPGeometry != null)
            {
                mPGeometry.SplitAtPoint(ipoint_0, true, true, out flag1, out num, out num1);
                if (flag1)
                {
                    igeometryBag_0 = new GeometryBag() as IGeometryBag;
                    IGeometryCollection geometryCollection = mPGeometry as IGeometryCollection;
                    IGeometryCollection polylineClass      = new Polyline() as IGeometryCollection;
                    object value = Missing.Value;
                    for (i = 0; i < num; i++)
                    {
                        polylineClass.AddGeometry(geometryCollection.Geometry[i], ref value, ref value);
                    }
                    (igeometryBag_0 as IGeometryCollection).AddGeometry(polylineClass as IGeometry, ref value, ref value);
                    polylineClass = new Polyline() as IGeometryCollection;
                    for (i = num; i < geometryCollection.GeometryCount; i++)
                    {
                        polylineClass.AddGeometry(geometryCollection.Geometry[i], ref value, ref value);
                    }
                    (igeometryBag_0 as IGeometryCollection).AddGeometry(polylineClass as IGeometry, ref value, ref value);
                    flag = true;
                }
                else
                {
                    flag = false;
                }
            }
            else
            {
                flag = false;
            }
            return(flag);
        }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
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());
        }
Ejemplo n.º 21
0
    //----------------------------------------------------------------------------------

    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);
            }
        }
    }
Ejemplo n.º 22
0
        public bool Split(IPolyline ipolyline_0, out IGeometryBag igeometryBag_0)
        {
            bool      flag;
            IGeometry geometry;
            IGeometry geometry1;

            igeometryBag_0 = null;
            if (this.m_pGeometry.GeometryType != esriGeometryType.esriGeometryPoint)
            {
                try
                {
                    ITopologicalOperator mPGeometry = this.m_pGeometry as ITopologicalOperator;
                    if (mPGeometry != null)
                    {
                        if (!mPGeometry.IsSimple)
                        {
                            mPGeometry.Simplify();
                        }
                        mPGeometry.Cut(ipolyline_0, out geometry, out geometry1);
                        object value = Missing.Value;
                        igeometryBag_0 = new GeometryBag() as IGeometryBag;
                        (igeometryBag_0 as IGeometryCollection).AddGeometry(geometry, ref value, ref value);
                        (igeometryBag_0 as IGeometryCollection).AddGeometry(geometry1, ref value, ref value);
                    }
                    else
                    {
                        flag = false;
                        return(flag);
                    }
                }
                catch
                {
                }
                flag = false;
            }
            else
            {
                flag = false;
            }
            return(flag);
        }
Ejemplo n.º 23
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());
        }
Ejemplo n.º 24
0
        private IGeometryCollection PrepareTemplateBag(
            [CanBeNull] ISpatialReference spatialReference = null)
        {
            if (_templateBag == null)
            {
                _templateBag = new GeometryBagClass();
            }
            else
            {
                _templateBag.SetEmpty();
                _templateBag.SpatialReference = null;
                ((IEnumGeometry)_templateBag).Reset();
            }

            if (spatialReference != null)
            {
                _templateBag.SpatialReference = spatialReference;
            }

            return((IGeometryCollection)_templateBag);
        }
Ejemplo n.º 25
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++;
                }
            }
        }
Ejemplo n.º 26
0
        public override bool SplitAtPoint(IPoint ipoint_0, out IGeometryBag igeometryBag_0)
        {
            bool flag;
            bool flag1;
            int  num;
            int  num1;

            igeometryBag_0 = null;
            IPolycurve mPGeometry = this.m_pGeometry as IPolycurve;

            if (mPGeometry != null)
            {
                mPGeometry.SplitAtPoint(ipoint_0, true, true, out flag1, out num, out num1);
                object value = Missing.Value;
                igeometryBag_0 = new GeometryBag() as IGeometryBag;
                (igeometryBag_0 as IGeometryCollection).AddGeometry(mPGeometry, ref value, ref value);
                flag = true;
            }
            else
            {
                flag = false;
            }
            return(flag);
        }
Ejemplo n.º 27
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);
        }
Ejemplo n.º 28
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;
            }
        }
Ejemplo n.º 29
0
        private IGeometry method_2()
        {
            double              x         = 0.0;
            double              y         = 0.0;
            double              xMax      = 0.0;
            double              yMax      = 0.0;
            IPoint              inPoint   = null;
            IPoint              point2    = null;
            IPoint              point3    = null;
            IPoint              point4    = null;
            IPointCollection    points    = null;
            IGeometry           geometry  = new RingClass();
            object              missing   = System.Type.Missing;
            IFeatureWorkspace   workspace = null;
            IFeatureClass       class2    = null;
            IFeatureCursor      cursor    = null;
            IFeature            feature   = null;
            IGeometryCollection geometrys = new GeometryBagClass();
            IGeometryBag        bag       = geometrys as IGeometryBag;

            workspace = null;
            try
            {
                if (workspace == null)
                {
                    return(geometry);
                }
                class2 = workspace.OpenFeatureClass("TKMC");
                if (class2 == null)
                {
                    return(geometry);
                }
                cursor = class2.Search(null, false);
                for (feature = cursor.NextFeature(); feature != null; feature = cursor.NextFeature())
                {
                    if (!feature.Shape.IsEmpty)
                    {
                        geometrys.AddGeometry(feature.ShapeCopy, ref missing, ref missing);
                    }
                }
                if (geometrys.GeometryCount >= 1)
                {
                    inPoint = new PointClass();
                    point2  = new PointClass();
                    point3  = new PointClass();
                    point4  = new PointClass();
                    x       = bag.Envelope.XMin;
                    y       = bag.Envelope.YMin;
                    xMax    = bag.Envelope.XMax;
                    yMax    = bag.Envelope.YMax;
                    inPoint.PutCoords(x, yMax);
                    point2.PutCoords(xMax, yMax);
                    point3.PutCoords(xMax, y);
                    point4.PutCoords(x, y);
                    points = (IPointCollection)geometry;
                    points.AddPoint(inPoint, ref missing, ref missing);
                    points.AddPoint(point2, ref missing, ref missing);
                    points.AddPoint(point3, ref missing, ref missing);
                    points.AddPoint(point4, ref missing, ref missing);
                    points.AddPoint(inPoint, ref missing, ref missing);
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
            }
            return(geometry);
        }
Ejemplo n.º 30
0
        private void calcZoneValuesFtr()
        {
            //Console.WriteLine("made it to the feature calculations");
            bool makeDic = (ZoneClassCount || ZoneTypes.Contains(rasterUtil.zoneType.VARIETY) || ZoneTypes.Contains(rasterUtil.zoneType.ENTROPY) || ZoneTypes.Contains(rasterUtil.zoneType.ASM) || ZoneTypes.Contains(rasterUtil.zoneType.MINORITY) || ZoneTypes.Contains(rasterUtil.zoneType.MODE) || ZoneTypes.Contains(rasterUtil.zoneType.MEDIAN));
            //
            //HashSet<byte> hByt = new HashSet<byte>();
            //
            ISpatialReference sr     = vRs.RasterInfo.SpatialReference;
            IEnvelope         vrsEnv = vRs.RasterInfo.Extent;
            ISpatialFilter    spFilt = new SpatialFilterClass();

            spFilt.SpatialRel    = esriSpatialRelEnum.esriSpatialRelIntersects;
            spFilt.Geometry      = vrsEnv;
            spFilt.GeometryField = ftrCls.ShapeFieldName;
            IFeatureCursor fCur      = ftrCls.Search(spFilt, true);
            int            zoneIndex = fCur.FindField(InZoneField);
            IFeature       ftr       = fCur.NextFeature();

            while (ftr != null)
            {
                IGeometry geo  = ftr.Shape;
                double    z    = System.Convert.ToDouble(ftr.get_Value(zoneIndex));
                IPolygon4 poly = (IPolygon4)geo;
                if (needToProject)
                {
                    poly.Project(sr);
                }
                IGeometryBag        geoBag  = poly.ExteriorRingBag;
                IGeometryCollection geoColl = (IGeometryCollection)geoBag;
                for (int g = 0; g < geoColl.GeometryCount; g++)
                {
                    IGeometry geo2                  = geoColl.Geometry[g];
                    IFunctionRasterDataset rs       = rsUtil.clipRasterFunction(vRs, geo2, esriRasterClippingType.esriRasterClippingOutside);
                    IEnvelope             rsEnv     = rs.RasterInfo.Extent;
                    IRasterFunctionHelper rsFHelper = new RasterFunctionHelperClass();
                    rsFHelper.Bind(rs);
                    //Console.WriteLine((rsEnv.Width / 30).ToString() + ", " + (rsEnv.Height / 30).ToString());
                    IRasterCursor rsCur = ((IRaster2)rsFHelper.Raster).CreateCursorEx(null);
                    do
                    {
                        IPixelBlock pb = rsCur.PixelBlock;
                        for (int p = 0; p < pb.Planes; p++)
                        {
                            zoneValueDic = zoneValueDicArr[p];
                            object[] zoneValue;
                            double   cnt   = 0;
                            double   maxVl = Double.MinValue;
                            double   minVl = Double.MaxValue;
                            double   s     = 0;
                            double   s2    = 0;
                            Dictionary <double, int> uDic = null;
                            if (zoneValueDic.TryGetValue(z, out zoneValue))
                            {
                                cnt   = System.Convert.ToDouble(zoneValue[0]);
                                maxVl = System.Convert.ToDouble(zoneValue[1]);
                                minVl = System.Convert.ToDouble(zoneValue[2]);
                                s     = System.Convert.ToDouble(zoneValue[3]);
                                s2    = System.Convert.ToDouble(zoneValue[4]);
                                uDic  = (Dictionary <double, int>)zoneValue[5];
                            }
                            else
                            {
                                zoneValue    = new object[6];
                                zoneValue[0] = cnt;
                                zoneValue[1] = maxVl;
                                zoneValue[2] = minVl;
                                zoneValue[3] = s;
                                zoneValue[4] = s2;
                                uDic         = null;
                                if (makeDic)
                                {
                                    uDic = new Dictionary <double, int>();
                                }
                                zoneValue[5] = uDic;
                            }
                            for (int r = 0; r < pb.Height; r++)
                            {
                                for (int c = 0; c < pb.Width; c++)
                                {
                                    object vlo = pb.GetVal(p, c, r);
                                    if (vlo == null)
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        double vl = System.Convert.ToDouble(vlo);
                                        cnt++;
                                        if (vl > maxVl)
                                        {
                                            maxVl = vl;
                                        }
                                        if (vl < minVl)
                                        {
                                            minVl = vl;
                                        }
                                        s  += vl;
                                        s2 += vl * vl;
                                        if (makeDic)
                                        {
                                            int cntVl = 0;
                                            if (uDic.TryGetValue(vl, out cntVl))
                                            {
                                                uDic[vl] = cntVl += 1;
                                            }
                                            else
                                            {
                                                uDic.Add(vl, 1);
                                            }
                                        }
                                    }
                                }
                            }
                            zoneValue[0]    = cnt;
                            zoneValue[1]    = maxVl;
                            zoneValue[2]    = minVl;
                            zoneValue[3]    = s;
                            zoneValue[4]    = s2;
                            zoneValue[5]    = uDic;
                            zoneValueDic[z] = zoneValue;
                        }
                    } while (rsCur.Next());
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(rsCur);
                }
                ftr = fCur.NextFeature();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(fCur);
        }