예제 #1
0
        public static IPolygon MakePolygonFromRing(IRing pRing, bool blMakeAreaZ /*使面积为正*/)
        {
            if (pRing == null || pRing.IsEmpty || pRing.IsClosed == false)
            {
                return(null);
            }
            IPolygon            pPolygon            = new PolygonClass();
            IGeometryCollection pGeometryCollection = pPolygon as IGeometryCollection;

            object    pBObj     = Type.Missing;
            object    pAObj     = Type.Missing;
            IGeometry pGeometry = pRing as IGeometry;

            pGeometryCollection.AddGeometry(pGeometry, ref pBObj, ref pAObj);

            if (blMakeAreaZ == false)
            {
                return(pPolygon);
            }

            IArea pArea = pPolygon as IArea;

            if (pArea.Area >= 0)
            {
                return(pPolygon);
            }

            ESRI.ArcGIS.esriSystem.IClone pClone = pRing as ESRI.ArcGIS.esriSystem.IClone;
            IRing pNewRing = pClone.Clone() as IRing;

            pNewRing.ReverseOrientation();
            pGeometry = pNewRing as IGeometry;
            pGeometryCollection.AddGeometry(pGeometry, ref pBObj, ref pAObj);
            return(pPolygon);
        }
예제 #2
0
        private static void AddToMultipatch(IMultiPatch result, IPolygon poly,
                                            bool invert, int?pointId)
        {
            IList <IRing> exteriorRings;
            var           innerRings = GeometryUtils.GetRings(poly, out exteriorRings);

            Assert.AreEqual(1, exteriorRings.Count, "Unexpected ring count");

            IRing mainRing = exteriorRings[0];

            if (pointId != null)
            {
                GeometryUtils.AssignConstantPointID((IPointCollection)mainRing,
                                                    pointId.Value);
            }

            if (invert)
            {
                mainRing.ReverseOrientation();

                foreach (IRing innerRing in innerRings)
                {
                    innerRing.ReverseOrientation();
                }
            }

            GeometryFactory.AddRingToMultiPatch(
                mainRing, result, esriMultiPatchRingType.esriMultiPatchOuterRing);

            foreach (IRing innerRing in innerRings)
            {
                if (pointId != null)
                {
                    GeometryUtils.AssignConstantPointID((IPointCollection)innerRing,
                                                        pointId.Value);
                }

                GeometryFactory.AddRingToMultiPatch(
                    innerRing, result,
                    esriMultiPatchRingType.esriMultiPatchInnerRing);
            }
        }
예제 #3
0
        public static IGeometry GetExample4()
        {
            const double CircleDegrees                   = 360.0;
            const int    CircleDivisions                 = 18;
            const double VectorComponentOffset           = 0.0000001;
            const double InnerBuildingRadius             = 3.0;
            const double OuterBuildingExteriorRingRadius = 9.0;
            const double OuterBuildingInteriorRingRadius = 6.0;
            const double BaseZ          = 0.0;
            const double InnerBuildingZ = 16.0;
            const double OuterBuildingZ = 6.0;

            //Composite: Tall Building Protruding Through Outer Ring-Shaped Building

            IMultiPatch multiPatch = new MultiPatchClass();

            IGeometryCollection multiPatchGeometryCollection = multiPatch as IGeometryCollection;

            IPoint originPoint = GeometryUtilities.ConstructPoint3D(0, 0, 0);

            IVector3D upperAxisVector3D = GeometryUtilities.ConstructVector3D(0, 0, 10);

            IVector3D lowerAxisVector3D = GeometryUtilities.ConstructVector3D(0, 0, -10);

            lowerAxisVector3D.XComponent += VectorComponentOffset;

            IVector3D normalVector3D = upperAxisVector3D.CrossProduct(lowerAxisVector3D) as IVector3D;

            double rotationAngleInRadians = GeometryUtilities.GetRadians(CircleDegrees / CircleDivisions);

            //Inner Building

            IGeometry innerBuildingBaseGeometry = new PolygonClass();

            IPointCollection innerBuildingBasePointCollection = innerBuildingBaseGeometry as IPointCollection;

            //Outer Building

            IGeometry outerBuildingBaseGeometry = new PolygonClass();

            IGeometryCollection outerBuildingBaseGeometryCollection = outerBuildingBaseGeometry as IGeometryCollection;

            IPointCollection outerBuildingBaseExteriorRingPointCollection = new RingClass();

            IPointCollection outerBuildingBaseInteriorRingPointCollection = new RingClass();

            for (int i = 0; i < CircleDivisions; i++)
            {
                normalVector3D.Rotate(-1 * rotationAngleInRadians, upperAxisVector3D);

                //Inner Building

                normalVector3D.Magnitude = InnerBuildingRadius;

                IPoint innerBuildingBaseVertexPoint = GeometryUtilities.ConstructPoint2D(originPoint.X + normalVector3D.XComponent,
                                                                                         originPoint.Y + normalVector3D.YComponent);

                innerBuildingBasePointCollection.AddPoint(innerBuildingBaseVertexPoint, ref _missing, ref _missing);

                //Outer Building

                //Exterior Ring

                normalVector3D.Magnitude = OuterBuildingExteriorRingRadius;

                IPoint outerBuildingBaseExteriorRingVertexPoint = GeometryUtilities.ConstructPoint2D(originPoint.X + normalVector3D.XComponent,
                                                                                                     originPoint.Y + normalVector3D.YComponent);

                outerBuildingBaseExteriorRingPointCollection.AddPoint(outerBuildingBaseExteriorRingVertexPoint, ref _missing, ref _missing);

                //Interior Ring

                normalVector3D.Magnitude = OuterBuildingInteriorRingRadius;

                IPoint outerBuildingBaseInteriorRingVertexPoint = GeometryUtilities.ConstructPoint2D(originPoint.X + normalVector3D.XComponent,
                                                                                                     originPoint.Y + normalVector3D.YComponent);

                outerBuildingBaseInteriorRingPointCollection.AddPoint(outerBuildingBaseInteriorRingVertexPoint, ref _missing, ref _missing);
            }

            IPolygon innerBuildingBasePolygon = innerBuildingBaseGeometry as IPolygon;

            innerBuildingBasePolygon.Close();

            IRing outerBuildingBaseExteriorRing = outerBuildingBaseExteriorRingPointCollection as IRing;

            outerBuildingBaseExteriorRing.Close();

            IRing outerBuildingBaseInteriorRing = outerBuildingBaseInteriorRingPointCollection as IRing;

            outerBuildingBaseInteriorRing.Close();
            outerBuildingBaseInteriorRing.ReverseOrientation();

            outerBuildingBaseGeometryCollection.AddGeometry(outerBuildingBaseExteriorRing as IGeometry, ref _missing, ref _missing);
            outerBuildingBaseGeometryCollection.AddGeometry(outerBuildingBaseInteriorRing as IGeometry, ref _missing, ref _missing);

            ITopologicalOperator topologicalOperator = outerBuildingBaseGeometry as ITopologicalOperator;

            topologicalOperator.Simplify();

            IConstructMultiPatch innerBuildingConstructMultiPatch = new MultiPatchClass();

            innerBuildingConstructMultiPatch.ConstructExtrudeFromTo(BaseZ, InnerBuildingZ, innerBuildingBaseGeometry);

            IGeometryCollection innerBuildingMultiPatchGeometryCollection = innerBuildingConstructMultiPatch as IGeometryCollection;

            for (int i = 0; i < innerBuildingMultiPatchGeometryCollection.GeometryCount; i++)
            {
                multiPatchGeometryCollection.AddGeometry(innerBuildingMultiPatchGeometryCollection.get_Geometry(i), ref _missing, ref _missing);
            }

            IConstructMultiPatch outerBuildingConstructMultiPatch = new MultiPatchClass();

            outerBuildingConstructMultiPatch.ConstructExtrudeFromTo(BaseZ, OuterBuildingZ, outerBuildingBaseGeometry);

            IMultiPatch outerBuildingMultiPatch = outerBuildingConstructMultiPatch as IMultiPatch;

            IGeometryCollection outerBuildingMultiPatchGeometryCollection = outerBuildingConstructMultiPatch as IGeometryCollection;

            for (int i = 0; i < outerBuildingMultiPatchGeometryCollection.GeometryCount; i++)
            {
                IGeometry outerBuildingPatchGeometry = outerBuildingMultiPatchGeometryCollection.get_Geometry(i);

                multiPatchGeometryCollection.AddGeometry(outerBuildingPatchGeometry, ref _missing, ref _missing);

                if (outerBuildingPatchGeometry.GeometryType == esriGeometryType.esriGeometryRing)
                {
                    bool isBeginningRing = false;

                    esriMultiPatchRingType multiPatchRingType = outerBuildingMultiPatch.GetRingType(outerBuildingPatchGeometry as IRing, ref isBeginningRing);

                    multiPatch.PutRingType(outerBuildingPatchGeometry as IRing, multiPatchRingType);
                }
            }

            return(multiPatchGeometryCollection as IGeometry);
        }