예제 #1
0
        //线构面
        private static IPolygon PolylineToPolygon(ref IPolyline pPolyline)
        {
            try
            {
                //创建一个新的Polygon geometry.
                IGeometryCollection pPolygonGeometryCol = new PolygonClass();

                //克隆即将要操作的Polyline
                IClone pClone = pPolyline as IClone;

                IGeometryCollection pGeoms_Polyline = pClone.Clone() as IGeometryCollection;
                object pBObj = Type.Missing;
                object pAObj = Type.Missing;
                for (int i = 0; i < pGeoms_Polyline.GeometryCount; i++)
                {
                    //通过Polyline的每个Path创建为一个新的Ring,并把Ring增加到一个新的Polygon
                    ISegmentCollection pSegs_Ring = new RingClass();
                    pSegs_Ring.AddSegmentCollection(pGeoms_Polyline.get_Geometry(i) as ISegmentCollection);
                    pPolygonGeometryCol.AddGeometry(pSegs_Ring as IGeometry, ref pBObj, ref pAObj);
                }
                //生成的Polygon旋转的顺序可能不正确,为确保正确调用SimplifyPreserveFromTo
                IPolygon pNewPolygon = new PolygonClass();
                pNewPolygon = pPolygonGeometryCol as IPolygon;
                pNewPolygon.SimplifyPreserveFromTo();
                return(pNewPolygon);
            }
            catch
            {
                return(null);
            }
        }
        public static IGeometry GetExample1()
        {
            //RingGroup: Multiple Rings

            IGeometryCollection multiPatchGeometryCollection = new MultiPatchClass();

            //Ring 1

            IPointCollection ring1PointCollection = new RingClass();
            ring1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(1, 1, 0), ref _missing, ref _missing);
            ring1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(1, 4, 0), ref _missing, ref _missing);
            ring1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(4, 4, 0), ref _missing, ref _missing);
            ring1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(4, 1, 0), ref _missing, ref _missing);

            IRing ring1 = ring1PointCollection as IRing;
            ring1.Close();

            multiPatchGeometryCollection.AddGeometry(ring1 as IGeometry, ref _missing, ref _missing);

            //Ring 2

            IPointCollection ring2PointCollection = new RingClass();
            ring2PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(1, -1, 0), ref _missing, ref _missing);
            ring2PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(4, -1, 0), ref _missing, ref _missing);
            ring2PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(4, -4, 0), ref _missing, ref _missing);
            ring2PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(1, -4, 0), ref _missing, ref _missing);

            IRing ring2 = ring2PointCollection as IRing;
            ring2.Close();

            multiPatchGeometryCollection.AddGeometry(ring2 as IGeometry, ref _missing, ref _missing);

            //Ring 3

            IPointCollection ring3PointCollection = new RingClass();
            ring3PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-1, 1, 0), ref _missing, ref _missing);
            ring3PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-4, 1, 0), ref _missing, ref _missing);
            ring3PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-4, 4, 0), ref _missing, ref _missing);
            ring3PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-1, 4, 0), ref _missing, ref _missing);

            IRing ring3 = ring3PointCollection as IRing;
            ring3.Close();

            multiPatchGeometryCollection.AddGeometry(ring3 as IGeometry, ref _missing, ref _missing);

            //Ring 4

            IPointCollection ring4PointCollection = new RingClass();
            ring4PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-1, -1, 0), ref _missing, ref _missing);
            ring4PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-1, -4, 0), ref _missing, ref _missing);
            ring4PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-4, -4, 0), ref _missing, ref _missing);
            ring4PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-4, -1, 0), ref _missing, ref _missing);

            IRing ring4 = ring4PointCollection as IRing;
            ring4.Close();

            multiPatchGeometryCollection.AddGeometry(ring4 as IGeometry, ref _missing, ref _missing);

            return multiPatchGeometryCollection as IGeometry;
        }
예제 #3
0
        /// <summary>
        /// 将字符串格式转化为Geometry
        /// </summary>
        /// <param name="geom">    客户端传递多边形格式 1) x1,y1;x2,y2;x3,y3.......xn,yn;x1,y1;保证起始闭合 为无环
        ///                                            2) x1,y1,flag3;x2,y2,flag3;x3,y3,flag3.......xn,yn,,flagn;
        /// </param>
        /// <returns></returns>
        public static IPolygon BuildPolygon(string geom)
        {
            if (string.IsNullOrEmpty(geom) == true)
            {
                throw new Exception(sErroCoordinatesIsNull);
            }

            string[] points = geom.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (points != null && points.Length > 2)
            {
                int pointCount = points.Length;
                IPolygon polygon = null;
                IPoint point = null;
                object missing = Type.Missing;
                IGeometryCollection pGeoColl = new PolygonClass() as IGeometryCollection;
                IPointCollection pPointCol = new RingClass();
                for (int i = 0; i < pointCount; i++)
                {
                    string[] pts = points[i].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    point = new PointClass();
                    double x = 0.0;
                    double y = 0.0;
                    int flag = 0;
                    bool bX = double.TryParse(pts[0], out x);
                    bool bY = double.TryParse(pts[1], out y);
                    bool bFlag = int.TryParse(pts[2], out flag);
                    if (bX && bY && bFlag)
                    {
                        pPointCol.AddPoint(point, ref  missing, ref missing);
                        if (flag == -1 || i == (pointCount - 1))
                        {
                            pGeoColl.AddGeometry(pPointCol as IRing, ref missing, ref missing);
                            pPointCol = null;
                            break;
                        }
                        else if (flag == -2)
                        {
                            pGeoColl.AddGeometry(pPointCol as IRing, ref missing, ref missing);
                            pPointCol = new RingClass();
                            continue;
                        }
                    }
                    else
                    {
                        throw new Exception(sErroCoordinatesValueIllegal);
                    }
                }
                if (pPointCol.PointCount > 0)
                {
                    pGeoColl.AddGeometry(pPointCol as IRing, ref missing, ref missing);
                }
                polygon = pGeoColl as IPolygon;
                SimplifyGeometry(polygon);
                return polygon;
            }
            else
            {
                throw new Exception(sErroCoordinatesValueIllegal);
            }
        }
        //根据读取出来的坐标,创建新要素
        private void CreateFeatures(IFeatureClass targetClass, List <List <Vertex> > polygons, string TBBHFieldName)
        {
            //编辑器
            IWorkspaceEdit m_WorkspaceEdit = (targetClass as IDataset).Workspace as IWorkspaceEdit;

            m_WorkspaceEdit.StartEditing(true);
            m_WorkspaceEdit.StartEditOperation();

            //一个一个多边形地处理,对应一个要素
            foreach (List <Vertex> polygon in polygons)
            {
                IFeature newFeature = targetClass.CreateFeature();
                Ring     ring       = new RingClass();
                object   missing    = Type.Missing;
                //把每个顶点添加到环
                foreach (Vertex vertex in polygon)
                {
                    IPoint pt = new PointClass();
                    double X  = vertex.X;
                    double Y  = vertex.Y;
                    pt.PutCoords(X, Y);
                    ring.AddPoint(pt, ref missing, ref missing);
                }
                //投影
                IGeometry   geometry    = ring as IGeometry;
                IGeoDataset pGeoDataset = targetClass as IGeoDataset;
                if (pGeoDataset.SpatialReference != null)
                {
                    geometry.Project(pGeoDataset.SpatialReference);
                }
                else
                {
                    geometry.Project(pMapControl.SpatialReference);
                }
                //环构成多边形
                IGeometryCollection newPolygon = new PolygonClass();
                newPolygon.AddGeometry(geometry, ref missing, ref missing);
                IPolygon newPolygon2 = newPolygon as IPolygon;
                newPolygon2.SimplifyPreserveFromTo();
                newFeature.Shape = newPolygon2 as IGeometry;
                //加上TBBH属性
                int fieldIndex = newFeature.Fields.FindField(TBBHFieldName);
                newFeature.set_Value(fieldIndex, polygon[0].TBBH);//取任意一个顶点的tbbh
                newFeature.Store();
            }
            //保存
            m_WorkspaceEdit.StopEditOperation();
            m_WorkspaceEdit.StopEditing(true);
            IFeatureLayer pFeatureLayer = new FeatureLayerClass();

            pFeatureLayer.FeatureClass = targetClass;
        }
예제 #5
0
 private IGeometry MakePolygonFromPointsList(List<IPoint> ptsList)
 {
     Ring ring = new RingClass();
     object missing = Type.Missing;
     for (int i = 0; i < ptsList.Count; i++)
     {
         ring.AddPoint(ptsList[i]);
     }
     IGeometryCollection pointPolygon = new PolygonClass();
     pointPolygon.AddGeometry(ring as IGeometry, ref missing, ref missing);
     IPolygon polygon = pointPolygon as IPolygon;
     polygon.SimplifyPreserveFromTo();
     return polygon;
 }
        public static IGeometry GetExample1()
        {
            //Ring: Upright Rectangle

            IGeometryCollection multiPatchGeometryCollection = new MultiPatchClass();

            IPointCollection ringPointCollection = new RingClass();

            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-7.5, 0, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-7.5, 0, 7.5), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(7.5, 0, 7.5), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(7.5, 0, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-7.5, 0, 0), ref _missing, ref _missing);

            multiPatchGeometryCollection.AddGeometry(ringPointCollection as IGeometry, ref _missing, ref _missing);

            return multiPatchGeometryCollection as IGeometry;
        }
예제 #7
0
 private IGeometry EllipticArcTransPolygon(IEllipticArc pEll)
 {
     try
     {
         object             missing      = Type.Missing;
         ISegmentCollection pSegmentColl = new RingClass();
         pSegmentColl.AddSegment((ISegment)pEll, ref missing, ref missing);
         IRing pRing = (IRing)pSegmentColl;
         pRing.Close();                                                    //得到闭合的环
         IGeometryCollection pGeometryCollection = new PolygonClass();
         pGeometryCollection.AddGeometry(pRing, ref missing, ref missing); //环转面
         IPolygon pPolygon = (IPolygon)pGeometryCollection;
         return(pPolygon);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public static IGeometry GetExample3()
        {
            //Ring: Octagon With Non-Coplanar Points

            IGeometryCollection multiPatchGeometryCollection = new MultiPatchClass();

            IPointCollection ringPointCollection = new RingClass();

            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-7.5, 7.5, 5), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(0, 8.5, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(7.5, 7.5, 5), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(8.5, 0, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(7.5, -7.5, 5), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(0, -8.5, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-7.5, -7.5, 5), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-8.5, 0, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-7.5, 7.5, 5), ref _missing, ref _missing);

            multiPatchGeometryCollection.AddGeometry(ringPointCollection as IGeometry, ref _missing, ref _missing);

            return multiPatchGeometryCollection as IGeometry;
        }
예제 #9
0
        public List<IGeometry> getHouseGeomList()
        {
            leftTopPt = new PointClass();
            leftTopPt.PutCoords(leftTopX, leftTopY);
            rightTopPt = new PointClass();
            rightTopPt.PutCoords(leftTopX+ houseWidth, leftTopY);
            leftBottomPt = new PointClass();
            leftBottomPt.PutCoords(leftTopX, leftTopY - houseHeight);
            rightBottomPt = new PointClass();
            rightBottomPt.PutCoords(leftTopX + houseWidth, leftTopY - houseHeight);

            //靠宽度, 深度定下四个点. 画出房子那一圈.
            Ring ring = new RingClass();
            ring.AddPoint(leftTopPt);
            ring.AddPoint(rightTopPt);
            ring.AddPoint(rightBottomPt);
            ring.AddPoint(leftBottomPt);
            IPolygon housePoly = GeneratePolygonFromRing(ring); //房子图形.

            //开始画外圈, 外圈左右前多2M, 后需要进行计算. 值为楼层数* 层高* 1.2
            double outerDist = houseFloor * houseFloorHeight * 1.2;
            leftTopPt.PutCoords(leftTopX - 2, leftTopY + outerDist);
            rightTopPt.PutCoords(leftTopX + houseWidth + 2, leftTopY - outerDist);
            leftBottomPt.PutCoords(leftTopX - 2, leftTopY - houseHeight - 2);
            rightBottomPt.PutCoords(leftTopX + houseWidth + 2, leftTopY - houseHeight - 2);

            ring = new RingClass();
            ring.AddPoint(leftTopPt);
            ring.AddPoint(rightTopPt);
            ring.AddPoint(rightBottomPt);
            ring.AddPoint(leftBottomPt);
            IPolygon outerPoly = GeneratePolygonFromRing(ring);

            //然后依次左上, 右上, 左下, 右下, 朝南, 5个圈.
            double x = outerPoly.Envelope.UpperLeft.X;
            double y = outerPoly.Envelope.UpperLeft.Y;
            leftTopPt.PutCoords(x - cornerSize, y + cornerSize);
            rightTopPt.PutCoords(x + cornerSize, y + cornerSize);
            leftBottomPt.PutCoords(x - cornerSize, y - cornerSize);
            rightBottomPt.PutCoords(x + cornerSize, y - cornerSize);
            ring = new RingClass();
            ring.AddPoint(leftTopPt);
            ring.AddPoint(rightTopPt);
            ring.AddPoint(rightBottomPt);
            ring.AddPoint(leftBottomPt);
            IPolygon leftTopPoly = GeneratePolygonFromRing(ring);

            x = outerPoly.Envelope.UpperRight.X;
            y = outerPoly.Envelope.UpperRight.Y;
            leftTopPt.PutCoords(x - cornerSize, y + cornerSize);
            rightTopPt.PutCoords(x + cornerSize, y + cornerSize);
            leftBottomPt.PutCoords(x - cornerSize, y - cornerSize);
            rightBottomPt.PutCoords(x + cornerSize, y - cornerSize);
            ring = new RingClass();
            ring.AddPoint(leftTopPt);
            ring.AddPoint(rightTopPt);
            ring.AddPoint(rightBottomPt);
            ring.AddPoint(leftBottomPt);
            IPolygon rightTopPoly = GeneratePolygonFromRing(ring);

            x = outerPoly.Envelope.LowerLeft.X;
            y = outerPoly.Envelope.LowerLeft.Y;
            leftTopPt.PutCoords(x - cornerSize, y + cornerSize);
            rightTopPt.PutCoords(x + cornerSize, y + cornerSize);
            leftBottomPt.PutCoords(x - cornerSize, y - cornerSize);
            rightBottomPt.PutCoords(x + cornerSize, y - cornerSize);
            ring = new RingClass();
            ring.AddPoint(leftTopPt);
            ring.AddPoint(rightTopPt);
            ring.AddPoint(rightBottomPt);
            ring.AddPoint(leftBottomPt);
            IPolygon leftBottomPoly = GeneratePolygonFromRing(ring);

            x = outerPoly.Envelope.LowerRight.X;
            x = outerPoly.Envelope.LowerRight.Y;
            leftTopPt.PutCoords(x - cornerSize, y + cornerSize);
            rightTopPt.PutCoords(x + cornerSize, y + cornerSize);
            leftBottomPt.PutCoords(x - cornerSize, y - cornerSize);
            rightBottomPt.PutCoords(x + cornerSize, y - cornerSize);
            ring = new RingClass();
            ring.AddPoint(leftTopPt);
            ring.AddPoint(rightTopPt);
            ring.AddPoint(rightBottomPt);
            ring.AddPoint(leftBottomPt);
            IPolygon rightBottomPoly = GeneratePolygonFromRing(ring);

            x = (outerPoly.Envelope.LowerLeft.X + outerPoly.Envelope.LowerRight.X) / 2;
            y = outerPoly.Envelope.LowerLeft.Y;
            leftTopPt.PutCoords(x - cornerSize, y + cornerSize);
            rightTopPt.PutCoords(x + cornerSize, y + cornerSize);
            leftBottomPt.PutCoords(x - cornerSize, y - cornerSize);
            rightBottomPt.PutCoords(x + cornerSize, y - cornerSize);
            ring = new RingClass();
            ring.AddPoint(leftTopPt);
            ring.AddPoint(rightTopPt);
            ring.AddPoint(rightBottomPt);
            ring.AddPoint(leftBottomPt);
            IPolygon southPoly = GeneratePolygonFromRing(ring);

            //最后按照, 内, 外, 左上, 右上, 左下, 右下, 朝南放入list.
            List<IGeometry> houseGeomList = new List<IGeometry>();
            houseGeomList.Add(housePoly);
            houseGeomList.Add(outerPoly);
            houseGeomList.Add(leftTopPoly);
            houseGeomList.Add(rightTopPoly);
            houseGeomList.Add(leftBottomPoly);
            houseGeomList.Add(rightBottomPoly);
            houseGeomList.Add(southPoly);

            return houseGeomList;
        }
예제 #10
0
        static void CreateGrid(TileInfo tiles, int level, IFeatureWorkspace destination, String name)
        {
            ISpatialReferenceFactory2 sEnv = new SpatialReferenceEnvironment() as ISpatialReferenceFactory2;
            ISpatialReference sr = sEnv.CreateSpatialReference((int)tiles.spatialReference);
            sr.SetMDomain(-137434824702, 0);
            IFeatureClass fc = CreateFeatureClass(destination, name, sr);
            LOD lod = tiles.lods[level];
            double width = tiles.width * lod.resolution;
            double height = tiles.height * lod.resolution;
            double y = tiles.originY;
            long row = 0;
            double maxX = -(tiles.originX + width);
            double minY = -(tiles.originY - height);
            while (y > minY)
            {
                double x = tiles.originX;
                long col = 0;
                while (x < maxX)
                {
                    RingClass ring = new RingClass();
                    IPoint tl = new PointClass();
                    tl.PutCoords(x, y);
                    tl.M = -(((col & 0xFFFF) << 16) + (row & 0xFFFF));
                    ring.AddPoint(tl);
                    IPoint tr = new PointClass();
                    tr.PutCoords(x + width, y);
                    tr.M = -((((col + 1) & 0xFFFF) << 16) + (row & 0xFFFF));
                    ring.AddPoint(tr);
                    IPoint br = new PointClass();
                    br.PutCoords(x + width, y - width);
                    br.M = -((((col + 1) & 0xFFFF) << 16) + ((row + 1) & 0xFFFF));
                    ring.AddPoint(br);
                    IPoint bl = new PointClass();
                    bl.PutCoords(x, y - width);
                    bl.M = -(((col & 0xFFFF) << 16) + ((row + 1) & 0xFFFF));
                    ring.AddPoint(bl);

                    ring.AddPoint(tl);

                    ring.Close();
                    PolygonClass polygon = new PolygonClass();
                    polygon.AddGeometry(ring);
                    IFeature polyFeature = fc.CreateFeature();
                    polyFeature.Shape = polygon;
                    polyFeature.Store();
                    x += width;
                    col += 1;
                }
                row += 1;
                y -= height;
            }
            IFeatureClassDescriptor fd = new FeatureClassDescriptorClass();
            fd.Create(fc, null, "OBJECTID");
        }
        public static IGeometry GetExample4()
        {
            const double FromZ = 0;
            const double ToZ = 8.5;

            //Extrusion: 2D Polygon Composed Of Multiple Square Shaped Rings, Extruded To Generate Multiple 
            //           3D Buildings Via ConstructExtrudeFromTo()

            IPolygon polygon = new PolygonClass();

            IGeometryCollection geometryCollection = polygon as IGeometryCollection;

            //Ring 1

            IPointCollection ring1PointCollection = new RingClass();
            ring1PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(1, 1), ref _missing, ref _missing);
            ring1PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(1, 4), ref _missing, ref _missing);
            ring1PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(4, 4), ref _missing, ref _missing);
            ring1PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(4, 1), ref _missing, ref _missing);

            IRing ring1 = ring1PointCollection as IRing;
            ring1.Close();

            geometryCollection.AddGeometry(ring1 as IGeometry, ref _missing, ref _missing);

            //Ring 2

            IPointCollection ring2PointCollection = new RingClass();
            ring2PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(1, -1), ref _missing, ref _missing);
            ring2PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(4, -1), ref _missing, ref _missing);
            ring2PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(4, -4), ref _missing, ref _missing);
            ring2PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(1, -4), ref _missing, ref _missing);

            IRing ring2 = ring2PointCollection as IRing;
            ring2.Close();

            geometryCollection.AddGeometry(ring2 as IGeometry, ref _missing, ref _missing);

            //Ring 3

            IPointCollection ring3PointCollection = new RingClass();
            ring3PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-1, 1), ref _missing, ref _missing);
            ring3PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-4, 1), ref _missing, ref _missing);
            ring3PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-4, 4), ref _missing, ref _missing);
            ring3PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-1, 4), ref _missing, ref _missing);

            IRing ring3 = ring3PointCollection as IRing;
            ring3.Close();

            geometryCollection.AddGeometry(ring3 as IGeometry, ref _missing, ref _missing);

            //Ring 4

            IPointCollection ring4PointCollection = new RingClass();
            ring4PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-1, -1), ref _missing, ref _missing);
            ring4PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-1, -4), ref _missing, ref _missing);
            ring4PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-4, -4), ref _missing, ref _missing);
            ring4PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-4, -1), ref _missing, ref _missing);

            IRing ring4 = ring4PointCollection as IRing;
            ring4.Close();

            geometryCollection.AddGeometry(ring4 as IGeometry, ref _missing, ref _missing);

            IGeometry polygonGeometry = polygon as IGeometry;

            ITopologicalOperator topologicalOperator = polygonGeometry as ITopologicalOperator;
            topologicalOperator.Simplify();

            IConstructMultiPatch constructMultiPatch = new MultiPatchClass();
            constructMultiPatch.ConstructExtrudeFromTo(FromZ, ToZ, polygonGeometry);

            return constructMultiPatch as IGeometry;
        }
예제 #12
0
        static void CopyAndLabel(IFeatureClass inFC, IFeatureWorkspace destination, String name)
        {
            IFieldsEdit outFields = new FieldsClass();
            ISpatialReference outSR = null;
            for (int i = 0; i < inFC.Fields.FieldCount; i += 1) {
                IField field = inFC.Fields.get_Field(i);
                if (field.Type == esriFieldType.esriFieldTypeGeometry) {
                    outSR = field.GeometryDef.SpatialReference;
                } else {
                    outFields.AddField(field);
                }
            }
            outSR.SetMDomain(-137434824702, 137434824702);

            IGeometryDefEdit geom = new GeometryDefClass();
            geom.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
            geom.SpatialReference_2 = outSR;
            geom.HasM_2 = true;
            geom.HasZ_2 = false;

            IFieldEdit geomField = new FieldClass();
            geomField.Name_2 = "SHAPE";
            geomField.AliasName_2 = "SHAPE";
            geomField.Type_2 = esriFieldType.esriFieldTypeGeometry;
            geomField.GeometryDef_2 = geom;
            outFields.AddField(geomField);

            IFeatureClass outFC = destination.CreateFeatureClass(name, outFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
            // Start numbering from 1, because index 0 is used by clipping cell
            int vIndex = 1;
            IFeatureCursor featureCursor = inFC.Search(null, true);
            IFeature inFeature;
            while ((inFeature = featureCursor.NextFeature()) != null) {
                IFeature outFeature = outFC.CreateFeature();
                for (int i = 0; i < outFields.FieldCount; i += 1) {
                    IField field = outFields.Field[i];
                    if (field.Editable && (field.Type != esriFieldType.esriFieldTypeGeometry)) {
                        outFeature.set_Value(i, inFeature.get_Value(i));
                    }
                }
                IPolygon4 inShape = inFeature.Shape as IPolygon4;
                PolygonClass outShape = new PolygonClass();

                IGeometryBag extRingBag = inShape.ExteriorRingBag;
                IGeometryCollection extRings = extRingBag as IGeometryCollection;
                for (int i = 0; i < extRings.GeometryCount; i += 1) {
                    IGeometry inExtRingGeom = extRings.get_Geometry(i);
                    IPointCollection inExtRing = inExtRingGeom as IPointCollection;
                    RingClass outExtRing = new RingClass();
                    for (int j = 0; j < inExtRing.PointCount; j += 1) {
                        IPoint point = inExtRing.get_Point(j);
                        point.M = vIndex;
                        vIndex += 2;
                        outExtRing.AddPoint(point);
                    }
                    outShape.AddGeometry(outExtRing);
                    IGeometryBag intRingBag = inShape.get_InteriorRingBag(inExtRingGeom as IRing);
                    IGeometryCollection intRings = intRingBag as IGeometryCollection;
                    for (int j = 0; j < intRings.GeometryCount; j += 1) {
                        IGeometry intRingGeom = intRings.get_Geometry(j);
                        IPointCollection inIntRing = intRingGeom as IPointCollection;
                        RingClass outIntRing = new RingClass();
                        for (int k = 0; k < inIntRing.PointCount; k += 1) {
                            IPoint point = inExtRing.get_Point(k);
                            point.M = vIndex;
                            vIndex += 2;
                            outIntRing.AddPoint(point);
                        }
                        outShape.AddGeometry(outIntRing);
                    }
                }
                outFeature.Shape = outShape;
                outFeature.Store();
            }
        }
예제 #13
0
 /// <summary>
 /// ��ת��
 /// </summary>
 /// <params name="pPolyline"></params>
 /// <returns></returns>
 public static IPolygon PolylineToPolygon(IPolyline pPolyline)
 {
     IPolygon pPolygon = null;
     IGeometryCollection pGeometryCollection = new PolygonClass();
     if (pPolyline != null && pPolyline.IsEmpty == false)
     {
         IGeometryCollection pPolylineGeoCol = pPolyline as IGeometryCollection;
         ISegmentCollection pSegCol = new RingClass();
         ISegment pSegment = null;
         object missing = Type.Missing;
         for (int i = 0; i < pPolylineGeoCol.GeometryCount; i++)
         {
             ISegmentCollection pPolylineSegCol = pPolylineGeoCol.get_Geometry(i) as ISegmentCollection;
             for (int j = 0; j < pPolylineSegCol.SegmentCount; j++)
             {
                 pSegment = pPolylineSegCol.get_Segment(j);
                 pSegCol.AddSegment(pSegment, ref missing, ref missing);
             }
             pGeometryCollection.AddGeometry(pSegCol as IGeometry, ref missing, ref missing);
         }
     }
     pPolygon = pGeometryCollection as IPolygon;
     if (pPolygon.IsClosed == false)
         pPolygon.Close();
     pPolygon.SpatialReference = DataEditCommon.g_pMyMapCtrl.SpatialReference;
     return pPolygon;
 }
예제 #14
0
        private void Coordinate_Load(object sender, EventArgs e)
        {
            //定义点集环形
            Ring ring1 = new RingClass();
            object missing = Type.Missing;
            //新建一个datatable用于保存读入的数据
            DataTable dt = new DataTable();
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Multiselect = false;    //单选
            ofd.Title = "选择坐标文件";
            ofd.Filter = "txt文件|*.txt";
            // ofd.InitialDirectory = Environment.SpecialFolder.Desktop.ToString();
            ofd.InitialDirectory = SystemSet.Base_Map + "\\处理数据库\\坐标数据";

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                //IGeometryCollection pointPolygon = new PolygonClass();
                FileInfo fi = new FileInfo(ofd.FileName);
                try
                {
                    paths1 = ofd.FileName;
                    lengh = paths1.Length - ofd.InitialDirectory.Length;
                    String paths = ofd.FileName;

                    int i = 0;
                    //给datatable添加5个列
                    dt.Columns.Add("编号", typeof(int));
                    dt.Columns.Add("坐标X", typeof(double));
                    dt.Columns.Add("坐标Y", typeof(double));
                    dt.Columns.Add("高程Z", typeof(double));
                    dt.Columns.Add("日期", typeof(string));
                    //读入文件
                    StreamReader sr = new StreamReader(paths, Encoding.Default);

                    //循环读取所有行
                    while (!sr.EndOfStream)//(line = sr.ReadLine()) != null)
                    {
                        i++;
                        //将每行数据,用-分割成2段
                        //sr.ReadLine().TrimStart();//消除前面空格
                        //sr.ReadLine().TrimEnd();//消除尾部空格
                        string[] data = sr.ReadLine().Split(',', ' ');
                        //新建一行,并将读出的数据分段,分别存入5个对应的列中
                        DataRow dr = dt.NewRow();
                        dr[0] = i;
                        dr[1] = data[0];
                        dr[2] = data[1];
                        dr[3] = 0;
                        dr[4] = DateTime.Now.ToLongDateString().ToString();
                        //将这行数据加入到datatable中
                        dt.Rows.Add(dr);
                        //点上生成面
                        IPoint ppp = new PointClass();
                        ppp.PutCoords((double)dr[1], (double)dr[2]);
                        ring1.AddPoint(ppp, ref missing, ref missing);
                        //调用画点工具
                        GISHandler.GISTools.CreatPoint(this.mapControl, (double)dr[1], (double)dr[2], i);
                    }
                }
                catch
                {
                    MessageBox.Show("坐标文件内容错误!请检查格式是否为:x,y或者x y");
                    return;
                }
                IGeometryCollection pointPolygon = new PolygonClass();
                pointPolygon.AddGeometry(ring1 as IGeometry, ref missing, ref missing);
                IPolygon polyGonGeo = pointPolygon as IPolygon;
                ply = polyGonGeo;
                polyGonGeo.SimplifyPreserveFromTo();
                //object miss = Type.Missing;
                //this.mapControl.DrawShape(polyGonGeo, ref miss);

            }
            else
                this.Close();
            gridControl1.DataSource = dt;
            dataGridView1.DataSource = dt;
            gridView1.OptionsView.ShowGroupPanel = false;
        }
        public static IGeometry GetExample2()
        {
            //RingGroup: Multiple Exterior Rings With Corresponding Interior Rings

            IGeometryCollection multiPatchGeometryCollection = new MultiPatchClass();

            IMultiPatch multiPatch = multiPatchGeometryCollection as IMultiPatch;

            //Exterior Ring 1

            IPointCollection exteriorRing1PointCollection = new RingClass();
            exteriorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(1, 1, 0), ref _missing, ref _missing);
            exteriorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(1, 4, 0), ref _missing, ref _missing);
            exteriorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(4, 4, 0), ref _missing, ref _missing);
            exteriorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(4, 1, 0), ref _missing, ref _missing);

            IRing exteriorRing1 = exteriorRing1PointCollection as IRing;
            exteriorRing1.Close();

            multiPatchGeometryCollection.AddGeometry(exteriorRing1 as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(exteriorRing1, esriMultiPatchRingType.esriMultiPatchOuterRing);

            //Interior Ring 1

            IPointCollection interiorRing1PointCollection = new RingClass();
            interiorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(3.5, 1.5, 0), ref _missing, ref _missing);
            interiorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(3.5, 3.5, 0), ref _missing, ref _missing);
            interiorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(1.5, 3.5, 0), ref _missing, ref _missing);
            interiorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(1.5, 1.5, 0), ref _missing, ref _missing);

            IRing interiorRing1 = interiorRing1PointCollection as IRing;
            interiorRing1.Close();

            multiPatchGeometryCollection.AddGeometry(interiorRing1 as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(interiorRing1, esriMultiPatchRingType.esriMultiPatchInnerRing);

            //Exterior Ring 2

            IPointCollection exteriorRing2PointCollection = new RingClass();
            exteriorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(1, -1, 0), ref _missing, ref _missing);
            exteriorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(4, -1, 0), ref _missing, ref _missing);
            exteriorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(4, -4, 0), ref _missing, ref _missing);
            exteriorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(1, -4, 0), ref _missing, ref _missing);

            IRing exteriorRing2 = exteriorRing2PointCollection as IRing;
            exteriorRing2.Close();

            multiPatchGeometryCollection.AddGeometry(exteriorRing2 as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(exteriorRing2, esriMultiPatchRingType.esriMultiPatchOuterRing);

            //Interior Ring 2

            IPointCollection interiorRing2PointCollection = new RingClass();
            interiorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(1.5, -1.5, 0), ref _missing, ref _missing);
            interiorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(3.5, -1.5, 0), ref _missing, ref _missing);
            interiorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(3.5, -3.5, 0), ref _missing, ref _missing);
            interiorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(1.5, -3.5, 0), ref _missing, ref _missing);

            IRing interiorRing2 = interiorRing2PointCollection as IRing;
            interiorRing2.Close();

            multiPatchGeometryCollection.AddGeometry(interiorRing2 as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(interiorRing2, esriMultiPatchRingType.esriMultiPatchInnerRing);

            //Exterior Ring 3

            IPointCollection exteriorRing3PointCollection = new RingClass();
            exteriorRing3PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-1, 1, 0), ref _missing, ref _missing);
            exteriorRing3PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-4, 1, 0), ref _missing, ref _missing);
            exteriorRing3PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-4, 4, 0), ref _missing, ref _missing);
            exteriorRing3PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-1, 4, 0), ref _missing, ref _missing);

            IRing exteriorRing3 = exteriorRing3PointCollection as IRing;
            exteriorRing3.Close();

            multiPatchGeometryCollection.AddGeometry(exteriorRing3 as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(exteriorRing3, esriMultiPatchRingType.esriMultiPatchOuterRing);

            //Interior Ring 3

            IPointCollection interiorRing3PointCollection = new RingClass();
            interiorRing3PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-1.5, 1.5, 0), ref _missing, ref _missing);
            interiorRing3PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-3.5, 1.5, 0), ref _missing, ref _missing);
            interiorRing3PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-3.5, 3.5, 0), ref _missing, ref _missing);
            interiorRing3PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-1.5, 3.5, 0), ref _missing, ref _missing);

            IRing interiorRing3 = interiorRing3PointCollection as IRing;
            interiorRing3.Close();

            multiPatchGeometryCollection.AddGeometry(interiorRing3 as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(interiorRing3, esriMultiPatchRingType.esriMultiPatchInnerRing);

            //Exterior Ring 4

            IPointCollection exteriorRing4PointCollection = new RingClass();
            exteriorRing4PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-1, -1, 0), ref _missing, ref _missing);
            exteriorRing4PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-1, -4, 0), ref _missing, ref _missing);
            exteriorRing4PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-4, -4, 0), ref _missing, ref _missing);
            exteriorRing4PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-4, -1, 0), ref _missing, ref _missing);

            IRing exteriorRing4 = exteriorRing4PointCollection as IRing;
            exteriorRing4.Close();

            multiPatchGeometryCollection.AddGeometry(exteriorRing4 as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(exteriorRing4, esriMultiPatchRingType.esriMultiPatchOuterRing);

            //Interior Ring 4

            IPointCollection interiorRing4PointCollection = new RingClass();
            interiorRing4PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-1.5, -1.5, 0), ref _missing, ref _missing);
            interiorRing4PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-1.5, -3.5, 0), ref _missing, ref _missing);
            interiorRing4PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-3.5, -3.5, 0), ref _missing, ref _missing);
            interiorRing4PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-3.5, -1.5, 0), ref _missing, ref _missing);

            IRing interiorRing4 = interiorRing4PointCollection as IRing;
            interiorRing4.Close();

            multiPatchGeometryCollection.AddGeometry(interiorRing4 as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(interiorRing4, esriMultiPatchRingType.esriMultiPatchInnerRing);

            return multiPatchGeometryCollection as IGeometry;
        }
        public static IGeometry GetExample5()
        {
            const int XRange = 16;
            const int YRange = 16;
            const int InteriorRingCount = 25;
            const double HoleRange = 0.5;

            //RingGroup: Square Lying In XY Plane With Single Exterior Ring And Multiple Interior Rings

            IGeometryCollection multiPatchGeometryCollection = new MultiPatchClass();

            IMultiPatch multiPatch = multiPatchGeometryCollection as IMultiPatch;

            //Exterior Ring

            IPointCollection exteriorRingPointCollection = new RingClass();
            exteriorRingPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(0.5 * (XRange + 2), -0.5 * (YRange + 2), 0), ref _missing, ref _missing);
            exteriorRingPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-0.5 * (XRange + 2), -0.5 * (YRange + 2), 0), ref _missing, ref _missing);
            exteriorRingPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-0.5 * (XRange + 2), 0.5 * (YRange + 2), 0), ref _missing, ref _missing);
            exteriorRingPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(0.5 * (XRange + 2), 0.5 * (YRange + 2), 0), ref _missing, ref _missing);

            IRing exteriorRing = exteriorRingPointCollection as IRing;
            exteriorRing.Close();

            multiPatchGeometryCollection.AddGeometry(exteriorRing as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(exteriorRing, esriMultiPatchRingType.esriMultiPatchOuterRing);

            //Interior Rings

            Random random = new Random();

            for (int i = 0; i < InteriorRingCount; i++)
            {
                double interiorRingOriginX = XRange * (random.NextDouble() - 0.5);
                double interiorRingOriginY = YRange * (random.NextDouble() - 0.5);

                IPointCollection interiorRingPointCollection = new RingClass();
                interiorRingPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(interiorRingOriginX - 0.5 * HoleRange, interiorRingOriginY - 0.5 * HoleRange, 0), ref _missing, ref _missing);
                interiorRingPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(interiorRingOriginX + 0.5 * HoleRange, interiorRingOriginY - 0.5 * HoleRange, 0), ref _missing, ref _missing);
                interiorRingPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(interiorRingOriginX + 0.5 * HoleRange, interiorRingOriginY + 0.5 * HoleRange, 0), ref _missing, ref _missing);
                interiorRingPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(interiorRingOriginX - 0.5 * HoleRange, interiorRingOriginY + 0.5 * HoleRange, 0), ref _missing, ref _missing);

                IRing interiorRing = interiorRingPointCollection as IRing;
                interiorRing.Close();

                multiPatchGeometryCollection.AddGeometry(interiorRing as IGeometry, ref _missing, ref _missing);

                multiPatch.PutRingType(interiorRing, esriMultiPatchRingType.esriMultiPatchInnerRing);
            }

            return multiPatchGeometryCollection as IGeometry;
        }
        public static IGeometry GetExample4()
        {
            //RingGroup: Upright Square Composed Of Multiple Exterior Rings And Multiple Interior Rings

            IGeometryCollection multiPatchGeometryCollection = new MultiPatchClass();

            IMultiPatch multiPatch = multiPatchGeometryCollection as IMultiPatch;

            //Exterior Ring 1

            IPointCollection exteriorRing1PointCollection = new RingClass();
            exteriorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, 0, -5), ref _missing, ref _missing);
            exteriorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-5, 0, -5), ref _missing, ref _missing);
            exteriorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-5, 0, 5), ref _missing, ref _missing);
            exteriorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, 0, 5), ref _missing, ref _missing);

            IRing exteriorRing1 = exteriorRing1PointCollection as IRing;
            exteriorRing1.Close();

            multiPatchGeometryCollection.AddGeometry(exteriorRing1 as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(exteriorRing1, esriMultiPatchRingType.esriMultiPatchOuterRing);

            //Interior Ring 1

            IPointCollection interiorRing1PointCollection = new RingClass();
            interiorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-4, 0, -4), ref _missing, ref _missing);
            interiorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(4, 0, -4), ref _missing, ref _missing);
            interiorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(4, 0, 4), ref _missing, ref _missing);
            interiorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-4, 0, 4), ref _missing, ref _missing);

            IRing interiorRing1 = interiorRing1PointCollection as IRing;
            interiorRing1.Close();

            multiPatchGeometryCollection.AddGeometry(interiorRing1 as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(interiorRing1, esriMultiPatchRingType.esriMultiPatchInnerRing);

            //Exterior Ring 2 

            IPointCollection exteriorRing2PointCollection = new RingClass();
            exteriorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(3, 0, -3), ref _missing, ref _missing);
            exteriorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-3, 0, -3), ref _missing, ref _missing);
            exteriorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-3, 0, 3), ref _missing, ref _missing);
            exteriorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(3, 0, 3), ref _missing, ref _missing);

            IRing exteriorRing2 = exteriorRing2PointCollection as IRing;
            exteriorRing2.Close();

            multiPatchGeometryCollection.AddGeometry(exteriorRing2 as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(exteriorRing2, esriMultiPatchRingType.esriMultiPatchOuterRing);

            //Interior Ring 2

            IPointCollection interiorRing2PointCollection = new RingClass();
            interiorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-2, 0, -2), ref _missing, ref _missing);
            interiorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(2, 0, -2), ref _missing, ref _missing);
            interiorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(2, 0, 2), ref _missing, ref _missing);
            interiorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-2, 0, 2), ref _missing, ref _missing);

            IRing interiorRing2 = interiorRing2PointCollection as IRing;
            interiorRing2.Close();

            multiPatchGeometryCollection.AddGeometry(interiorRing2 as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(interiorRing2, esriMultiPatchRingType.esriMultiPatchInnerRing);

            //Exterior Ring 3 

            IPointCollection exteriorRing3PointCollection = new RingClass();
            exteriorRing3PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(1, 0, -1), ref _missing, ref _missing);
            exteriorRing3PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-1, 0, -1), ref _missing, ref _missing);
            exteriorRing3PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-1, 0, 1), ref _missing, ref _missing);
            exteriorRing3PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(1, 0, 1), ref _missing, ref _missing);

            IRing exteriorRing3 = exteriorRing3PointCollection as IRing;
            exteriorRing3.Close();

            multiPatchGeometryCollection.AddGeometry(exteriorRing3 as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(exteriorRing3, esriMultiPatchRingType.esriMultiPatchOuterRing);

            return multiPatchGeometryCollection as IGeometry;
        }
        public static IGeometry GetExample3()
        {
            //RingGroup: Upright Square With Hole

            IGeometryCollection multiPatchGeometryCollection = new MultiPatchClass();

            IMultiPatch multiPatch = multiPatchGeometryCollection as IMultiPatch;

            //Exterior Ring 1

            IPointCollection exteriorRing1PointCollection = new RingClass();
            exteriorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, 0, -5), ref _missing, ref _missing);
            exteriorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-5, 0, -5), ref _missing, ref _missing);
            exteriorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-5, 0, 5), ref _missing, ref _missing);
            exteriorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, 0, 5), ref _missing, ref _missing);

            IRing exteriorRing1 = exteriorRing1PointCollection as IRing;
            exteriorRing1.Close();

            multiPatchGeometryCollection.AddGeometry(exteriorRing1 as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(exteriorRing1, esriMultiPatchRingType.esriMultiPatchOuterRing);

            //Interior Ring 1

            IPointCollection interiorRing1PointCollection = new RingClass();
            interiorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-4, 0, -4), ref _missing, ref _missing);
            interiorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(4, 0, -4), ref _missing, ref _missing);
            interiorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(4, 0, 4), ref _missing, ref _missing);
            interiorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-4, 0, 4), ref _missing, ref _missing);

            IRing interiorRing1 = interiorRing1PointCollection as IRing;
            interiorRing1.Close();

            multiPatchGeometryCollection.AddGeometry(interiorRing1 as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(interiorRing1, esriMultiPatchRingType.esriMultiPatchInnerRing);

            return multiPatchGeometryCollection as IGeometry;
        }
예제 #19
0
파일: GisUtil.cs 프로젝트: Leooonard/CGXM
        public static IPolygon PreProcessArea(IGeometry geom)
        {
            /*
                预处理地区, 从地区中心挖出一块土地.
             *  返回被挖出的地块. 
             */
            object missing = Type.Missing;
            IPoint envelopLeftTopPt = geom.Envelope.UpperLeft;
            IPoint envelopRightTopPt = geom.Envelope.UpperRight;
            IPoint envelopLeftBottomPt = geom.Envelope.LowerLeft;
            IPoint envelopRightBottomPt = geom.Envelope.LowerRight;
            double initialDist = 5; //第一次各边向内移动5M;
            double dist = 1; //之后每次尝试向内移动1M;

            envelopLeftTopPt.X += initialDist;
            envelopLeftTopPt.Y -= initialDist;
            envelopRightTopPt.X -= initialDist;
            envelopRightTopPt.Y -= initialDist;
            envelopLeftBottomPt.X += initialDist;
            envelopLeftBottomPt.Y += initialDist;
            envelopRightBottomPt.X -= initialDist;
            envelopRightBottomPt.Y += initialDist;

            Ring ring = new RingClass();
            ring.AddPoint(envelopLeftTopPt);
            ring.AddPoint(envelopRightTopPt);
            ring.AddPoint(envelopRightBottomPt);
            ring.AddPoint(envelopLeftBottomPt);

            IPolygon areaPolygon = MakePolygonFromRing(ring);
            IRelationalOperator reOp = geom as IRelationalOperator;

            while (!reOp.Contains(areaPolygon))
            {
                envelopLeftTopPt.X += dist;
                envelopLeftTopPt.Y -= dist;
                envelopRightTopPt.X -= dist;
                envelopRightTopPt.Y -= dist;
                envelopLeftBottomPt.X += dist;
                envelopLeftBottomPt.Y += dist;
                envelopRightBottomPt.X -= dist;
                envelopRightBottomPt.Y += dist;

                ring = new RingClass();
                ring.AddPoint(envelopLeftTopPt);
                ring.AddPoint(envelopRightTopPt);
                ring.AddPoint(envelopRightBottomPt);
                ring.AddPoint(envelopLeftBottomPt);

                areaPolygon = MakePolygonFromRing(ring);
            }

            envelopLeftTopPt.X += initialDist;
            envelopLeftTopPt.Y -= initialDist;
            envelopRightTopPt.X -= initialDist;
            envelopRightTopPt.Y -= initialDist;
            envelopLeftBottomPt.X += initialDist;
            envelopLeftBottomPt.Y += initialDist;
            envelopRightBottomPt.X -= initialDist;
            envelopRightBottomPt.Y += initialDist;

            ring = new RingClass();
            ring.AddPoint(envelopLeftTopPt);
            ring.AddPoint(envelopRightTopPt);
            ring.AddPoint(envelopRightBottomPt);
            ring.AddPoint(envelopLeftBottomPt);

            areaPolygon = MakePolygonFromRing(ring);

            return areaPolygon;
        }
        public static IGeometry GetExample4()
        {
            //Ring: Maze Lying On XY Plane

            IGeometryCollection multiPatchGeometryCollection = new MultiPatchClass();

            IPointCollection ringPointCollection = new RingClass();

            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-10, 10, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(10, 10, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(10, -10, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-10, -10, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-10, 6, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(6, 6, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(6, -6, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-6, -6, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-6, 2, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-6, 2, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(0, 2, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(0, 0, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-4, 0, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-4, -4, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(4, -4, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(4, 4, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-8, 4, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-8, -8, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(8, -8, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(8, 8, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-10, 8, 0), ref _missing, ref _missing);
            ringPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-10, 10, 0), ref _missing, ref _missing);

            multiPatchGeometryCollection.AddGeometry(ringPointCollection as IGeometry, ref _missing, ref _missing);

            return multiPatchGeometryCollection as IGeometry;
        }
        private IPolygon GetMGRSPolygon(IPoint point)
        {
            CoordinateMGRS mgrs;

            IPointCollection pc = new RingClass();

            // bottom left
            CoordinateMGRS.TryParse(InputCoordinate, out mgrs);

            // don't create a polygon for 1m resolution
            if (mgrs.Easting.ToString().Length > 4 && mgrs.Northing.ToString().Length > 4)
                return null;

            var tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = GetSR();
            var anotherMGRSstring = mgrs.ToString("", new CoordinateMGRSFormatter());
            tempPoint.PutCoordsFromMGRS(anotherMGRSstring, esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);
            
            // top left
            var tempMGRS = new CoordinateMGRS(mgrs.GZD, mgrs.GS, mgrs.Easting, mgrs.Northing);
            var tempEasting = mgrs.Easting.ToString().PadRight(5,'0');
            tempMGRS.Easting = Convert.ToInt32(tempEasting);
            var tempNorthing = mgrs.Northing.ToString().PadRight(5,'9');
            tempMGRS.Northing = Convert.ToInt32(tempNorthing.Replace('0','9'));

            tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = GetSR();
            anotherMGRSstring = tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter());
            tempPoint.PutCoordsFromMGRS(anotherMGRSstring, esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // top right
            tempEasting = mgrs.Easting.ToString().PadRight(5,'9');
            tempMGRS.Easting = Convert.ToInt32(tempEasting.Replace('0', '9'));
            tempNorthing = mgrs.Northing.ToString().PadRight(5,'9');
            tempMGRS.Northing = Convert.ToInt32(tempNorthing.Replace('0', '9'));

            tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = GetSR();
            tempPoint.PutCoordsFromMGRS(tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter()), esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // bottom right
            tempEasting = mgrs.Easting.ToString().PadRight(5,'9');
            tempMGRS.Easting = Convert.ToInt32(tempEasting.Replace('0', '9'));
            tempNorthing = mgrs.Northing.ToString().PadRight(5,'0');
            tempMGRS.Northing = Convert.ToInt32(tempNorthing);

            tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = GetSR();
            tempPoint.PutCoordsFromMGRS(tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter()), esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // create polygon
            var poly = new PolygonClass();
            poly.SpatialReference = GetSR();
            poly.AddPointCollection(pc);
            poly.Close();

            return poly;
        }
예제 #22
0
        /// <summary>
        /// ������ʵ��
        /// </summary>
        /// <param name="pITable">���ݱ����</param>
        /// <param name="entinyNode">VCT�ռ�ʵ��ڵ�</param>
        public override void CreateFeature(ITable pITable, EntityNode entinyNode)
        {
            PolygonNode pPolygonNode = entinyNode as PolygonNode;
            if (pPolygonNode != null)
            {
                IFeatureClass pFeatureCls = pITable as IFeatureClass;
                this.Feature = pFeatureCls.CreateFeature();

                ///��ʶ�븳ֵ
                int dBSMIndex = -1;
                dBSMIndex = this.Feature.Fields.FindField(m_strEntityIDFiled);
                if (dBSMIndex != -1)
                    this.Feature.set_Value(dBSMIndex, pPolygonNode.EntityID);

                ///Ҫ�ش��븳ֵ
                int dSYDMIndex = -1;
                dSYDMIndex = this.Feature.Fields.FindField(m_strYSDMField);
                if (dSYDMIndex != -1)
                    this.Feature.set_Value(dSYDMIndex, pPolygonNode.FeatureCode);

                //�������������͹���
                bool bGetGeometry = false;///ָʾ�Ƿ��ȡͼ������

                ///�����ñ��ȡ�������InDireCoordinatePolygon��ʾ������깹��
                if (Metadata.MetaDataFile.GraphConfig.GetGraphMark("POLYGONFEATURETYPE", pPolygonNode.PolygonType.ToString()) == "InDireCoordinatePolygon")
                {
                    IGeometryCollection pGeoCollection = new PolygonClass();
                    IPointCollection pPtCollection = new RingClass();

                    ///���ü�ӹ���ķ�ʽLineStructPolygon��ʾ�����߹���
                    if (Metadata.MetaDataFile.GraphConfig.GetGraphMark("POLYGONTYPE", pPolygonNode.ComposeType.ToString()) == "LineStructPolygon")
                    {
                        for (int i = 0; i < pPolygonNode.LineNodes.Count; i++)
                        {
                            LineNodeEx pLineNodeEx = pPolygonNode.LineNodes[i];
                            if (pLineNodeEx == null)
                                continue;

                            ///��ʶ��Ϊ0��ʾ����ָ��ʶ
                            if (pLineNodeEx.EntityID != 0)
                            {
                                IPoint pPrePoint=null;
                                if (pPtCollection.PointCount > 0)
                                    pPrePoint = pPtCollection.get_Point(pPtCollection.PointCount-1);
                                IPointCollection pPointCollection=GetPointCollection(pLineNodeEx, pPrePoint);
                                if (pPointCollection != null)
                                    pPtCollection.AddPointCollection(pPointCollection);
                                if (i == pPolygonNode.LineNodes.Count - 1)
                                {
                                    IRing pRing = pPtCollection as IRing;
                                    pRing.Close();///�պϵ�ǰ��
                                    object oTypeMissing = Type.Missing;
                                    pGeoCollection.AddGeometry(pRing as IGeometry, ref oTypeMissing, ref oTypeMissing);
                                    bGetGeometry = true;
                                    pPtCollection = new RingClass();///��յ㼯����
                                }
                            }
                            else///������ʶ��Ϊ0ʱ�պ�ͼ��
                            {
                                IRing pRing = pPtCollection as IRing;
                                pRing.Close();///�պϵ�ǰ��
                                object oTypeMissing = Type.Missing;
                                pGeoCollection.AddGeometry(pRing as IGeometry, ref oTypeMissing, ref oTypeMissing);
                                bGetGeometry = true;
                                pPtCollection = new RingClass();///��յ㼯����
                            }
                        }
                        if (bGetGeometry)
                        {
                            (this.Feature as IFeature).Shape = pGeoCollection as IGeometry;
                        }
                    }
                }
                else if (pPolygonNode.PolygonType == 1)
                {

                }

                this.Feature.Store();
            }
        }
        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;            
        }
        private void createpolygon(IPointCollection ippoints)
        {
            ISegmentCollection ppath = new PathClass();
            IGeometryCollection ppolyline = new PolylineClass();
            if (ippoints.PointCount >= 3)
            {
                int i;
                object o = Type.Missing;
                if (ippoints.PointCount >= 4)
                {
                    ippoints.RemovePoints(ippoints.PointCount - 2, 1);
                }
                ippoints.AddPoint(ippoints.get_Point(0));
                for (i = 0; i < ippoints.PointCount - 1; i++)
                {
                    ILine pline = new LineClass();
                    pline.PutCoords(ippoints.get_Point(i), ippoints.get_Point(i + 1));
                    ISegment psegment = pline as ISegment;

                    ppath.AddSegment(psegment, ref o, ref o);
                    ppolyline.AddGeometry(ppath as IGeometry, ref o, ref o);
                }
                ipPolyResult = ppolyline as IPolyline;
                ISegmentCollection pRing = new RingClass();
                IGeometryCollection pGeometryColl = new PolygonClass();
                for (int j = 0; j < ppolyline.GeometryCount; j++)
                {
                    pRing.AddSegmentCollection(ppolyline.get_Geometry(j) as ISegmentCollection);
                    pGeometryColl.AddGeometry(pRing as IGeometry, ref o, ref o);
                }
                ipolygon = pGeometryColl as IPolygon;
            }
        }
예제 #25
0
 public IPolygon GetBoundaryAsPolygon(IRasterProps props)
 {
     double left = props.Extent.XMin;
     double top = props.Extent.YMax;
     IPnt cellSize = props.MeanCellSize();
     PolygonClass result = new PolygonClass();
     object missing = Type.Missing;
     for (int x = 0; x <= m_Width; x += 1) {
         for (int y = 0; y <= m_Height; y += 1) {
             if ((!CellVisited(x, y)) && IsFilled(x, y) && (!IsFilled(x - 1, y))) {
                 List<IntPoint> bmRing = GetCurve(x, y);
                 RingClass ring = new RingClass();
                 foreach (IntPoint bmPt in bmRing) {
                     PointClass point = new PointClass();
                     point.PutCoords(left + bmPt.X * cellSize.X,
                                     top - bmPt.Y * cellSize.Y);
                     ring.AddPoint(point, ref missing, ref missing);
                 }
                 result.AddGeometry(ring, ref missing, ref missing);
             }
         }
     }
     return result;
 }
예제 #26
0
        private IElement DrawCircle(double radius, double x, double y)
        {
            IPoint centralPoint = new PointClass();
            centralPoint.PutCoords(x, y);
            // 创建园
            ICircularArc circularArc = new CircularArcClass();
            IConstructCircularArc construtionCircularArc = circularArc as IConstructCircularArc;
            construtionCircularArc.ConstructCircle(centralPoint, radius, true);

            ISegment pSegment1 = circularArc as ISegment;
            //通过ISegmentCollection构建Ring对象
            ISegmentCollection pSegCollection = new RingClass();
            object o = Type.Missing;
            //添加Segement对象即圆
            pSegCollection.AddSegment(pSegment1, ref o, ref o);

            //QI到IRing接口封闭Ring对象,使其有效
            IRing pRing = pSegCollection as IRing;
            pRing.Close();
            //通过Ring对象使用IGeometryCollection构建Polygon对象
            IGeometryCollection pGeometryColl = new PolygonClass();
            pGeometryColl.AddGeometry(pRing, ref o, ref o);
            //构建一个CircleElement对象
            IElement pElement = new CircleElementClass();
            pElement.Geometry = pGeometryColl as IGeometry;

            IFillShapeElement pFillShapeElement = pElement as IFillShapeElement;

            ISimpleFillSymbol pFillSymbol = new SimpleFillSymbolClass();
            //pFillSymbol.Color = pCircleColor;
            ILineSymbol pLineSymbol = new SimpleLineSymbolClass();

              //  pLineSymbol.Color = DefineColor(0, 255, 0);
            pFillSymbol.Outline = pLineSymbol;

            pFillShapeElement.Symbol = pFillSymbol;

            IFillShapeElement circleElement = pElement as IFillShapeElement;
            circleElement.Symbol = pFillSymbol;
            IGraphicsContainer pGC = this.axMapControl.ActiveView.GraphicsContainer;
            pGC.AddElement(pElement, 0);
            axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            return pElement;
        }
        public static IGeometry GetExample5()
        {
            const double FromZ = 0;
            const double ToZ = 8.5;

            //Extrusion: 2D Polygon Composed Of Multiple Square Shaped Exterior Rings And Corresponding Interior Rings,
            //           Extruded To Generate Multiple 3D Buildings With Hollow Interiors Via ConstructExtrudeFromTo()

            IPolygon polygon = new PolygonClass();

            IGeometryCollection geometryCollection = polygon as IGeometryCollection;

            //Exterior Ring 1

            IPointCollection exteriorRing1PointCollection = new RingClass();
            exteriorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(1, 1), ref _missing, ref _missing);
            exteriorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(1, 4), ref _missing, ref _missing);
            exteriorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(4, 4), ref _missing, ref _missing);
            exteriorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(4, 1), ref _missing, ref _missing);

            IRing exteriorRing1 = exteriorRing1PointCollection as IRing;
            exteriorRing1.Close();

            geometryCollection.AddGeometry(exteriorRing1 as IGeometry, ref _missing, ref _missing);

            //Interior Ring 1

            IPointCollection interiorRing1PointCollection = new RingClass();
            interiorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(1.5, 1.5), ref _missing, ref _missing);
            interiorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(1.5, 3.5), ref _missing, ref _missing);
            interiorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(3.5, 3.5), ref _missing, ref _missing);
            interiorRing1PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(3.5, 1.5), ref _missing, ref _missing);

            IRing interiorRing1 = interiorRing1PointCollection as IRing;
            interiorRing1.Close();

            geometryCollection.AddGeometry(interiorRing1 as IGeometry, ref _missing, ref _missing);

            //Exterior Ring 2

            IPointCollection exteriorRing2PointCollection = new RingClass();
            exteriorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(1, -1), ref _missing, ref _missing);
            exteriorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(4, -1), ref _missing, ref _missing);
            exteriorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(4, -4), ref _missing, ref _missing);
            exteriorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(1, -4), ref _missing, ref _missing);

            IRing exteriorRing2 = exteriorRing2PointCollection as IRing;
            exteriorRing2.Close();

            geometryCollection.AddGeometry(exteriorRing2 as IGeometry, ref _missing, ref _missing);

            //Interior Ring 2

            IPointCollection interiorRing2PointCollection = new RingClass();
            interiorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(1.5, -1.5), ref _missing, ref _missing);
            interiorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(3.5, -1.5), ref _missing, ref _missing);
            interiorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(3.5, -3.5), ref _missing, ref _missing);
            interiorRing2PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(1.5, -3.5), ref _missing, ref _missing);

            IRing interiorRing2 = interiorRing2PointCollection as IRing;
            interiorRing2.Close();

            geometryCollection.AddGeometry(interiorRing2 as IGeometry, ref _missing, ref _missing);

            //Exterior Ring 3

            IPointCollection exteriorRing3PointCollection = new RingClass();
            exteriorRing3PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-1, 1), ref _missing, ref _missing);
            exteriorRing3PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-4, 1), ref _missing, ref _missing);
            exteriorRing3PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-4, 4), ref _missing, ref _missing);
            exteriorRing3PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-1, 4), ref _missing, ref _missing);

            IRing exteriorRing3 = exteriorRing3PointCollection as IRing;
            exteriorRing3.Close();

            geometryCollection.AddGeometry(exteriorRing3 as IGeometry, ref _missing, ref _missing);

            //Interior Ring 3

            IPointCollection interiorRing3PointCollection = new RingClass();
            interiorRing3PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-1.5, 1.5), ref _missing, ref _missing);
            interiorRing3PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-3.5, 1.5), ref _missing, ref _missing);
            interiorRing3PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-3.5, 3.5), ref _missing, ref _missing);
            interiorRing3PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-1.5, 3.5), ref _missing, ref _missing);

            IRing interiorRing3 = interiorRing3PointCollection as IRing;
            interiorRing3.Close();

            geometryCollection.AddGeometry(interiorRing3 as IGeometry, ref _missing, ref _missing);
            
            //Exterior Ring 4

            IPointCollection exteriorRing4PointCollection = new RingClass();
            exteriorRing4PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-1, -1), ref _missing, ref _missing);
            exteriorRing4PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-1, -4), ref _missing, ref _missing);
            exteriorRing4PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-4, -4), ref _missing, ref _missing);
            exteriorRing4PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-4, -1), ref _missing, ref _missing);

            IRing exteriorRing4 = exteriorRing4PointCollection as IRing;
            exteriorRing4.Close();

            geometryCollection.AddGeometry(exteriorRing4 as IGeometry, ref _missing, ref _missing);

            //Interior Ring 5

            IPointCollection interiorRing4PointCollection = new RingClass();
            interiorRing4PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-1.5, -1.5), ref _missing, ref _missing);
            interiorRing4PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-1.5, -3.5), ref _missing, ref _missing);
            interiorRing4PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-3.5, -3.5), ref _missing, ref _missing);
            interiorRing4PointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-3.5, -1.5), ref _missing, ref _missing);

            IRing interiorRing4 = interiorRing4PointCollection as IRing;
            interiorRing4.Close();

            geometryCollection.AddGeometry(interiorRing4 as IGeometry, ref _missing, ref _missing);
            
            IGeometry polygonGeometry = polygon as IGeometry;

            ITopologicalOperator topologicalOperator = polygonGeometry as ITopologicalOperator;
            topologicalOperator.Simplify();

            IConstructMultiPatch constructMultiPatch = new MultiPatchClass();
            constructMultiPatch.ConstructExtrudeFromTo(FromZ, ToZ, polygonGeometry);

            return constructMultiPatch as IGeometry;
        }
예제 #28
0
        public void ShowHouse(House house, CommonHouse commonHouse)
        {
            ClearShowcase();
            IPoint upperLeftPt = new PointClass()
                , upperRightPt = new PointClass()
                , lowerLeftPt = new PointClass()
                , lowerRightPt = new PointClass()
                , lowerMidPt = new PointClass()
                , midLeftPt = new PointClass()
                , midRightPt = new PointClass();
            Ring ring = new RingClass();
            IPolygon innerPolygon = null, outerPolygon = null;
            List<IPolygon> unitPolygonList = new List<IPolygon>();
            IEnvelope extent;

            if (house.width * commonHouse.height > 0)
            {
                upperLeftPt = new PointClass();
                upperLeftPt.X = upperLeftX;
                upperLeftPt.Y = upperLeftY;
                upperRightPt = new PointClass();
                upperRightPt.X = upperLeftPt.X + house.width;
                upperRightPt.Y = upperLeftPt.Y;
                lowerLeftPt = new PointClass();
                lowerLeftPt.X = upperLeftPt.X;
                lowerLeftPt.Y = upperLeftPt.Y - commonHouse.height;
                lowerRightPt = new PointClass();
                lowerRightPt.X = lowerLeftPt.X + house.width;
                lowerRightPt.Y = lowerLeftPt.Y;
                ring = new RingClass();
                ring.AddPoint(upperLeftPt);
                ring.AddPoint(upperRightPt);
                ring.AddPoint(lowerRightPt);
                ring.AddPoint(lowerLeftPt);
                innerPolygon = GisUtil.MakePolygonFromRing(ring);

                //每单元
                double unitWidth = house.width / house.unit;
                double unitUpperLeftX = upperLeftX;
                double unitUpperLeftY = upperLeftY;
                for (int i = 0; i < house.unit; i++)
                {
                    IPoint unitUpperLeftPt = new PointClass();
                    unitUpperLeftPt.X = unitUpperLeftX;
                    unitUpperLeftPt.Y = unitUpperLeftY;
                    IPoint unitUpperRightPt = new PointClass();
                    unitUpperRightPt.X = unitUpperLeftPt.X + unitWidth;
                    unitUpperRightPt.Y = unitUpperLeftPt.Y;
                    IPoint unitLowerLeftPt = new PointClass();
                    unitLowerLeftPt.X = unitUpperLeftPt.X;
                    unitLowerLeftPt.Y = unitUpperLeftPt.Y - commonHouse.height;
                    IPoint unitLowerRightPt = new PointClass();
                    unitLowerRightPt.X = unitLowerLeftPt.X + unitWidth;
                    unitLowerRightPt.Y = unitLowerLeftPt.Y;
                    Ring unitRing = new RingClass();
                    unitRing.AddPoint(unitUpperLeftPt);
                    unitRing.AddPoint(unitUpperRightPt);
                    unitRing.AddPoint(unitLowerRightPt);
                    unitRing.AddPoint(unitLowerLeftPt);
                    IPolygon unitPolygon = GisUtil.MakePolygonFromRing(unitRing);
                    unitPolygonList.Add(unitPolygon);
                    unitUpperLeftX += unitWidth;
                }
            }

            if (house.leftGap > 0 && house.rightGap > 0 && commonHouse.frontGap > 0 && commonHouse.backGap > 0 && house.width > 0 && commonHouse.height > 0)
            {
                upperLeftPt = new PointClass();
                upperLeftPt.X = upperLeftX - house.leftGap;
                upperLeftPt.Y = upperLeftY + commonHouse.backGap;
                upperRightPt = new PointClass();
                upperRightPt.X = upperLeftPt.X + house.leftGap + house.width + house.rightGap;
                upperRightPt.Y = upperLeftPt.Y;
                lowerLeftPt = new PointClass();
                lowerLeftPt.X = upperLeftPt.X;
                lowerLeftPt.Y = upperLeftPt.Y - commonHouse.backGap - commonHouse.height - commonHouse.frontGap;
                lowerRightPt = new PointClass();
                lowerRightPt.X = lowerLeftPt.X + house.leftGap + house.width + house.rightGap;
                lowerRightPt.Y = lowerLeftPt.Y;
                ring = new RingClass();
                ring.AddPoint(upperLeftPt);
                ring.AddPoint(upperRightPt);
                ring.AddPoint(lowerRightPt);
                ring.AddPoint(lowerLeftPt);
                outerPolygon = GisUtil.MakePolygonFromRing(ring);
            }

            if (outerPolygon != null)
            {
                GisUtil.drawPolygon(outerPolygon, mapControl, outerColor);
            }
            else
            { 
                //是否要绘制一个文本?
            }
            if (innerPolygon != null)
            {
                GisUtil.drawPolygon(innerPolygon, mapControl, innerColor);
            }
            else
            { 
                //是否要绘制一个文本?
            }
            for (int i = 0; i < unitPolygonList.Count; i++)
            {
                GisUtil.drawPolygon(unitPolygonList[i], mapControl, innerColor);
            }

            //绘制文字.
            upperLeftPt = new PointClass();
            upperLeftPt.X = upperLeftX;
            upperLeftPt.Y = upperLeftY;
            upperRightPt = new PointClass();
            upperRightPt.X = upperLeftPt.X + house.width;
            upperRightPt.Y = upperLeftPt.Y;
            lowerLeftPt = new PointClass();
            lowerLeftPt.X = upperLeftPt.X;
            lowerLeftPt.Y = upperLeftPt.Y - commonHouse.height;
            lowerRightPt = new PointClass();
            lowerRightPt.X = lowerLeftPt.X + house.width;
            lowerRightPt.Y = lowerLeftPt.Y;

            if (house.leftGap > 0 && house.rightGap > 0 && commonHouse.frontGap > 0 && commonHouse.backGap > 0 && house.width > 0 && commonHouse.height > 0)
            {
                midLeftPt = new PointClass();
                midLeftPt.X = lowerLeftPt.X;
                midLeftPt.Y = (lowerLeftPt.Y + upperLeftPt.Y) / 2;
                IPoint otherEndPt = new PointClass();
                otherEndPt.X = midLeftPt.X - house.leftGap;
                otherEndPt.Y = midLeftPt.Y;
                drawLineWithText(otherEndPt, midLeftPt, "左间距:" + String.Format("{0:F}", house.leftGap) + "(米)", true);
                midRightPt = new PointClass(); //画右间距.
                midRightPt.X = lowerRightPt.X;
                midRightPt.Y = (lowerLeftPt.Y + upperLeftPt.Y) / 2;
                otherEndPt = new PointClass();
                otherEndPt.X = midRightPt.X + house.rightGap;
                otherEndPt.Y = midRightPt.Y;
                drawLineWithText(midRightPt, otherEndPt, "右间距:" + String.Format("{0:F}", house.rightGap) + "(米)", true);
                IPoint upperMidPt = new PointClass(); //画后深.
                upperMidPt.X = (lowerLeftPt.X + lowerRightPt.X) / 2;
                upperMidPt.Y = upperLeftPt.Y;
                otherEndPt = new PointClass();
                otherEndPt.X = upperMidPt.X;
                otherEndPt.Y = upperMidPt.Y + commonHouse.backGap;
                drawLineWithText(otherEndPt, upperMidPt, "后间距:" + String.Format("{0:F}", commonHouse.backGap) + "(米)", false);
                lowerMidPt = new PointClass(); //画前深.
                lowerMidPt.X = (lowerLeftPt.X + lowerRightPt.X) / 2;
                lowerMidPt.Y = lowerLeftPt.Y;
                otherEndPt = new PointClass();
                otherEndPt.X = lowerMidPt.X;
                otherEndPt.Y = lowerMidPt.Y - commonHouse.frontGap;
                drawLineWithText(lowerMidPt, otherEndPt, "前深: " + String.Format("{0:F}", commonHouse.frontGap) + "(米)", false);
            }

            upperRightPt = new PointClass();
            if (house.width > 0)
            {
                upperRightPt.X = upperLeftX + house.width + house.rightGap;
                upperRightPt.Y = upperLeftY + commonHouse.backGap;
            }
            else
            {
                upperRightPt.X = upperLeftX;
                upperRightPt.Y = upperLeftY;
            }
            double extraTextY = 0;
            IPoint extraTextPt = new PointClass();
            extraTextPt.X = upperRightPt.X + extraTextRightGap;
            extraTextPt.Y = upperRightPt.Y;
            extraTextY = extraTextPt.Y;
            if (house.width > 0)
                GisUtil.drawText("面宽: " + String.Format("{0:F}", house.width) + "(米)", extraTextPt, textColor, mapControl);
            else
                GisUtil.drawText("面宽: 未知", extraTextPt, textColor, mapControl);
            extraTextPt = new PointClass();
            extraTextPt.X = upperRightPt.X + extraTextRightGap;
            extraTextPt.Y = extraTextY + extraTextBottomGap;
            extraTextY = extraTextPt.Y;
            if (commonHouse.height > 0)
                GisUtil.drawText("进深:" + String.Format("{0:F}", commonHouse.height) + "(米)", extraTextPt, textColor, mapControl);
            else
                GisUtil.drawText("进深: 未知", extraTextPt, textColor, mapControl);
            extraTextPt = new PointClass(); //画房型名.
            extraTextPt.X = upperRightPt.X + extraTextRightGap;
            extraTextPt.Y = extraTextY + extraTextBottomGap;
            extraTextY = extraTextPt.Y;
            if (house.width > 0 && house.unit > 0)
                GisUtil.drawText("每单元面宽: " + String.Format("{0:F}", house.width / house.unit) + "(米)", extraTextPt, textColor, mapControl);
            else
                GisUtil.drawText("每单元面宽: 未知", extraTextPt, textColor, mapControl);
            extraTextPt = new PointClass(); //画房型名.
            extraTextPt.X = upperRightPt.X + extraTextRightGap;
            extraTextPt.Y = extraTextY + extraTextBottomGap;
            extraTextY = extraTextPt.Y;
            if (commonHouse.height > 0 && house.unit > 0)
                GisUtil.drawText("每单元进深: " + String.Format("{0:F}", commonHouse.height / house.unit) + "(米)", extraTextPt, textColor, mapControl);
            else
                GisUtil.drawText("每单元进深: 未知", extraTextPt, textColor, mapControl);
            extraTextPt = new PointClass(); //画房型名.
            extraTextPt.X = upperRightPt.X + extraTextRightGap;
            extraTextPt.Y = extraTextY + extraTextBottomGap;
            extraTextY = extraTextPt.Y;
            GisUtil.drawText("房型名: " + house.name, extraTextPt, textColor, mapControl);
            extraTextPt = new PointClass(); //画层数.
            extraTextPt.X = upperRightPt.X + extraTextRightGap;
            extraTextPt.Y = extraTextY + extraTextBottomGap;
            extraTextY = extraTextPt.Y;
            if (commonHouse.floor > 0)
                GisUtil.drawText("层数: " + commonHouse.floor.ToString() + "(层)", extraTextPt, textColor, mapControl);
            else
                GisUtil.drawText("层数: 未知", extraTextPt, textColor, mapControl);
            extraTextPt = new PointClass();
            extraTextPt.X = upperRightPt.X + extraTextRightGap;
            extraTextPt.Y = extraTextY + extraTextBottomGap;
            extraTextY = extraTextPt.Y;
            if (commonHouse.floorHeight > 0)
                GisUtil.drawText("层高: " + String.Format("{0:F}", commonHouse.floorHeight) + "(米)", extraTextPt, textColor, mapControl);
            else
                GisUtil.drawText("层高: 未知", extraTextPt, textColor, mapControl);
            extraTextPt = new PointClass();
            extraTextPt.X = upperRightPt.X + extraTextRightGap;
            extraTextPt.Y = extraTextY + extraTextBottomGap;
            extraTextY = extraTextPt.Y;
            if (house.unit > 0)
                GisUtil.drawText("单元数: " + house.unit.ToString(), extraTextPt, textColor, mapControl);
            else
                GisUtil.drawText("单元数: 未知", extraTextPt, textColor, mapControl);
            extraTextPt = new PointClass();
            extraTextPt.X = upperRightPt.X + extraTextRightGap;
            extraTextPt.Y = extraTextY + extraTextBottomGap;
            extraTextY = extraTextPt.Y;
            if (house.houseHold > 0)
                GisUtil.drawText("每单元户数: " + house.houseHold.ToString() + "(户)", extraTextPt, textColor, mapControl);
            else
                GisUtil.drawText("每单元户数: 未知", extraTextPt, textColor, mapControl);
            extraTextPt = new PointClass();
            extraTextPt.X = upperRightPt.X + extraTextRightGap;
            extraTextPt.Y = extraTextY + extraTextBottomGap;
            extraTextY = extraTextPt.Y;
            if (house.width > 0 && commonHouse.height > 0)
                GisUtil.drawText("层面积: " + String.Format("{0:F}", house.width * commonHouse.height) + "(平方米)", extraTextPt, textColor, mapControl);
            else
                GisUtil.drawText("层面积: 未知", extraTextPt, textColor, mapControl);
            extraTextPt = new PointClass();
            extraTextPt.X = upperRightPt.X + extraTextRightGap;
            extraTextPt.Y = extraTextY + extraTextBottomGap;
            extraTextY = extraTextPt.Y;
            if (house.width > 0 && commonHouse.height > 0 && commonHouse.floor > 0)
                GisUtil.drawText("总面积: " + String.Format("{0:F}", house.width * commonHouse.height * commonHouse.floor) + "(平方米)", extraTextPt, textColor, mapControl);
            else
                GisUtil.drawText("总面积: 未知", extraTextPt, textColor, mapControl);

            //移动地图视角.
            if (outerPolygon == null)
            {
                extent = upperRightPt.Envelope;
            }
            else
            {
                extent = outerPolygon.Envelope;
            }
            extent.Expand(2, 2, true);
            mapControl.Extent = extent;
        }
        /// <summary>
        /// 根据传入的左邦点数组和右邦点数组生成巷道
        /// </summary>
        /// <param name="tunnel"></param>
        /// <param name="pts"></param>
        /// <param name="editlayer"></param>
        public void DrawHuDong(TunnelEntity tunnel, WirePointInfoEntity[] pts, IFeatureLayer editlayer)
        {
            IPoint point = new PointClass();
               IPointCollection4 pointCollection = new PolygonClass();
               TunnelPointsCalculation TPC = new TunnelPointsCalculation();
               Vector3_DW[] lstLeftBtmVertices = null;
               Vector3_DW[] lstRightBtmVertices = null;
               TPC.CalcLeftAndRightVertics(pts, ref lstLeftBtmVertices,ref lstRightBtmVertices);
               for (int intI = 0; intI < lstLeftBtmVertices.Length; intI++)
               {
               point.X = lstLeftBtmVertices[intI].X;
               point.Y = lstLeftBtmVertices[intI].Y;
               point.Z = lstLeftBtmVertices[intI].Z;
               pointCollection.AddPoint(point);
               }
               for (int intI = lstRightBtmVertices.Length; intI >=0; intI--)
               {
               point.X = lstRightBtmVertices[intI].X;
               point.Y = lstRightBtmVertices[intI].Y;
               point.Z = lstRightBtmVertices[intI].Z;
               pointCollection.AddPoint(point);
               }

               IFeature f;
               IGeometryCollection polygon;
               //定义一个地物类,把要编辑的图层转化为定义的地物类
               IFeatureClass fc = editlayer.FeatureClass;
               //先定义一个编辑的工作空间,然后把转化为数据集,最后转化为编辑工作空间,
               IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit;
               //开始事务操作
               w.StartEditing(false);
               //开始编辑
               w.StartEditOperation();
               //创建一个地物

               //绘制巷道

               polygon = new PolygonClass();
               IGeometryCollection pGeoColl = pointCollection as IGeometryCollection;
               ISegmentCollection pRing = new RingClass();
               pRing.AddSegmentCollection(pGeoColl as ISegmentCollection);

               polygon.AddGeometry(pRing as IGeometry);
               IPolygon polyGonGeo = polygon as IPolygon;
               polyGonGeo.SimplifyPreserveFromTo();
               f = fc.CreateFeature();
               //polygon.PutCoords(Convert.ToDouble(ge.CoordinateX), Convert.ToDouble(ge.CoordinateY));
               //确定图形类型
               f.Shape = (IGeometry)polyGonGeo;

               //给巷道赋属性值
               int num3;
               //num3 = editlayer.FeatureClass.Fields.FindField("OBJECTID");
               //f.set_Value(num3, tunnel.TunnelID);
               num3 = editlayer.FeatureClass.Fields.FindField("MINE_NAME");
               f.set_Value(num3, tunnel.MineName);
               num3 = editlayer.FeatureClass.Fields.FindField("HORIZONTAL");
               f.set_Value(num3, tunnel.HorizontalName);
               num3 = editlayer.FeatureClass.Fields.FindField("MINING_AREA");
               f.set_Value(num3, tunnel.MiningAreaName);
               num3 = editlayer.FeatureClass.Fields.FindField("WORKING_FACE");
               f.set_Value(num3, tunnel.WorkingFaceName);
               num3 = editlayer.FeatureClass.Fields.FindField("TUNNEL_NAME");
               f.set_Value(num3, tunnel.TunnelName);
               num3 = editlayer.FeatureClass.Fields.FindField("SUPPORT_PATTERN");
               f.set_Value(num3, tunnel.TunnelSupportPattern);
               num3 = editlayer.FeatureClass.Fields.FindField("LITHOLOGY_ID");
               f.set_Value(num3, tunnel.TunnelLithologyID);
               num3 = editlayer.FeatureClass.Fields.FindField("FAULTAGETYPE");
               f.set_Value(num3, tunnel.TunnelSectionType);
               num3 = editlayer.FeatureClass.Fields.FindField("PARAM");
               f.set_Value(num3, tunnel.TunnelParam);
               num3 = editlayer.FeatureClass.Fields.FindField("DESIGNLENGTH");
               f.set_Value(num3, tunnel.TunnelDesignLength);
               //num3 = editlayer.FeatureClass.Fields.FindField("RULE_CODE");
               //f.set_Value(num3, tunnel.r);
               //保存地物
               f.Store();
              //渲染巷道样式
               ISimpleFillSymbol pFillSymbol;
               pFillSymbol = new SimpleFillSymbolClass();
               pFillSymbol.Color = getRGB(60, 100, 50);
               pFillSymbol.Outline.Color = getRGB(60, 100, 50);
               pFillSymbol.Outline.Width = 1;
               pFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
               RenderfeatureLayer(editlayer, pFillSymbol as ISymbol);
               //结束编辑
               w.StopEditOperation();
               //结束事务操作
               w.StopEditing(true);
        }
        public static IGeometry GetExample3()
        {
            //Composite: House Composed Of 7 Ring, 1 TriangleStrip, And 1 Triangles Parts

            IGeometryCollection multiPatchGeometryCollection = new MultiPatchClass();

            IMultiPatch multiPatch = multiPatchGeometryCollection as IMultiPatch;

            //Base (Exterior Ring)

            IPointCollection basePointCollection = new RingClass();
            basePointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, 4, 0), ref _missing, ref _missing);
            basePointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-5, 4, 0), ref _missing, ref _missing);
            basePointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-5, -4, 0), ref _missing, ref _missing);
            basePointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, -4, 0), ref _missing, ref _missing);
            basePointCollection.AddPoint(basePointCollection.get_Point(0), ref _missing, ref _missing);

            multiPatchGeometryCollection.AddGeometry(basePointCollection as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(basePointCollection as IRing, esriMultiPatchRingType.esriMultiPatchOuterRing);

            //Front With Cutaway For Door (Exterior Ring)

            IPointCollection frontPointCollection = new RingClass();
            frontPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, 4, 6), ref _missing, ref _missing);
            frontPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, 4, 0), ref _missing, ref _missing);
            frontPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, 1, 0), ref _missing, ref _missing);
            frontPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, 1, 4), ref _missing, ref _missing);
            frontPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, -1, 4), ref _missing, ref _missing);
            frontPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, -1, 0), ref _missing, ref _missing);
            frontPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, -4, 0), ref _missing, ref _missing);
            frontPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, -4, 6), ref _missing, ref _missing);
            frontPointCollection.AddPoint(frontPointCollection.get_Point(0), ref _missing, ref _missing);

            multiPatchGeometryCollection.AddGeometry(frontPointCollection as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(frontPointCollection as IRing, esriMultiPatchRingType.esriMultiPatchOuterRing);

            //Back (Exterior Ring)

            IPointCollection backPointCollection = new RingClass();
            backPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-5, 4, 6), ref _missing, ref _missing);
            backPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-5, -4, 6), ref _missing, ref _missing);
            backPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-5, -4, 0), ref _missing, ref _missing);
            backPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-5, 4, 0), ref _missing, ref _missing);
            backPointCollection.AddPoint(backPointCollection.get_Point(0), ref _missing, ref _missing);

            multiPatchGeometryCollection.AddGeometry(backPointCollection as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(backPointCollection as IRing, esriMultiPatchRingType.esriMultiPatchOuterRing);

            //Right Side (Ring Group)

            //Exterior Ring

            IPointCollection rightSideExteriorPointCollection = new RingClass();
            rightSideExteriorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, 4, 6), ref _missing, ref _missing);
            rightSideExteriorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-5, 4, 6), ref _missing, ref _missing);
            rightSideExteriorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-5, 4, 0), ref _missing, ref _missing);
            rightSideExteriorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, 4, 0), ref _missing, ref _missing);
            rightSideExteriorPointCollection.AddPoint(rightSideExteriorPointCollection.get_Point(0), ref _missing, ref _missing);

            multiPatchGeometryCollection.AddGeometry(rightSideExteriorPointCollection as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(rightSideExteriorPointCollection as IRing, esriMultiPatchRingType.esriMultiPatchOuterRing);

            //Interior Ring

            IPointCollection rightSideInteriorPointCollection = new RingClass();
            rightSideInteriorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(1, 4, 4), ref _missing, ref _missing);
            rightSideInteriorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(1, 4, 2), ref _missing, ref _missing);
            rightSideInteriorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-1, 4, 2), ref _missing, ref _missing);
            rightSideInteriorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-1, 4, 4), ref _missing, ref _missing);
            rightSideInteriorPointCollection.AddPoint(rightSideInteriorPointCollection.get_Point(0), ref _missing, ref _missing);

            multiPatchGeometryCollection.AddGeometry(rightSideInteriorPointCollection as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(rightSideInteriorPointCollection as IRing, esriMultiPatchRingType.esriMultiPatchInnerRing);

            //Left Side (Ring Group)

            //Exterior Ring

            IPointCollection leftSideExteriorPointCollection = new RingClass();
            leftSideExteriorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, -4, 6), ref _missing, ref _missing);
            leftSideExteriorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, -4, 0), ref _missing, ref _missing);
            leftSideExteriorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-5, -4, 0), ref _missing, ref _missing);
            leftSideExteriorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-5, -4, 6), ref _missing, ref _missing);
            leftSideExteriorPointCollection.AddPoint(leftSideExteriorPointCollection.get_Point(0), ref _missing, ref _missing);

            multiPatchGeometryCollection.AddGeometry(leftSideExteriorPointCollection as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(leftSideExteriorPointCollection as IRing, esriMultiPatchRingType.esriMultiPatchOuterRing);

            //Interior Ring

            IPointCollection leftSideInteriorPointCollection = new RingClass();
            leftSideInteriorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(1, -4, 4), ref _missing, ref _missing);
            leftSideInteriorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-1, -4, 4), ref _missing, ref _missing);
            leftSideInteriorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-1, -4, 2), ref _missing, ref _missing);
            leftSideInteriorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(1, -4, 2), ref _missing, ref _missing);
            leftSideInteriorPointCollection.AddPoint(leftSideInteriorPointCollection.get_Point(0), ref _missing, ref _missing);

            multiPatchGeometryCollection.AddGeometry(leftSideInteriorPointCollection as IGeometry, ref _missing, ref _missing);

            multiPatch.PutRingType(leftSideInteriorPointCollection as IRing, esriMultiPatchRingType.esriMultiPatchInnerRing);

            //Roof

            IPointCollection roofPointCollection = new TriangleStripClass();
            roofPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-5, 4, 6), ref _missing, ref _missing);
            roofPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, 4, 6), ref _missing, ref _missing);
            roofPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-5, 0, 9), ref _missing, ref _missing);
            roofPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, 0, 9), ref _missing, ref _missing);
            roofPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-5, -4, 6), ref _missing, ref _missing);
            roofPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, -4, 6), ref _missing, ref _missing);

            multiPatchGeometryCollection.AddGeometry(roofPointCollection as IGeometry, ref _missing, ref _missing);

            //Triangular Area Between Roof And Front/Back

            IPointCollection triangularAreaPointCollection = new TrianglesClass();

            //Area Between Roof And Front

            triangularAreaPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, 0, 9), ref _missing, ref _missing);
            triangularAreaPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, 4, 6), ref _missing, ref _missing);
            triangularAreaPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(5, -4, 6), ref _missing, ref _missing);

            //Area Between Roof And Back

            triangularAreaPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-5, 0, 9), ref _missing, ref _missing);
            triangularAreaPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-5, -4, 6), ref _missing, ref _missing);
            triangularAreaPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-5, 4, 6), ref _missing, ref _missing);

            multiPatchGeometryCollection.AddGeometry(triangularAreaPointCollection as IGeometry, ref _missing, ref _missing);

            return multiPatchGeometryCollection as IGeometry;
        }
예제 #31
0
        /// <summary>Convert a GeoJSON Polygon geometry to Arcgis Geometry </summary>
        /// <param name="JSpoint">The deserialised GeoJson Object</param>
        /// <param name="epsg">The EPSG-code of the spatial reference, -1 is unknown</param>
        /// <returns>A Arcgis Polygon goemetry</returns>
        public static IPolygon geojson2esriPolygon(datacontract.geojsonPolygon JSPolygon, int epsg = -1)
        {
            Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
            System.Object obj = Activator.CreateInstance(factoryType);
            ISpatialReferenceFactory3 spatialReferenceFactory = obj as ISpatialReferenceFactory3;

            IGeometryBridge2 pGeoBrg = new GeometryEnvironment() as IGeometryBridge2;

            IGeometryCollection esriGeometryCol = new PolygonClass();

            for (int n = 0; n < JSPolygon.coordinates.Count; n++)
            {
                List<List<double>> JSring = JSPolygon.coordinates[n];
                IPointCollection4 ring = new RingClass();
                ESRI.ArcGIS.esriSystem.WKSPoint[] aWKSPointBuffer = new ESRI.ArcGIS.esriSystem.WKSPoint[JSring.Count];
                for (int i = 0; i < JSring.Count; i++)
                {
                    double[] xy = JSring[i].ToArray();
                    aWKSPointBuffer[i].X = xy[0];
                    aWKSPointBuffer[i].Y = xy[1];
                }
                pGeoBrg.SetWKSPoints(ring , aWKSPointBuffer);
                esriGeometryCol.AddGeometry(ring as IGeometry, Type.Missing, Type.Missing);
            }

            IPolygon esriPolygon = esriGeometryCol as IPolygon;

            if (epsg != -1)
            {
                ISpatialReference srs = spatialReferenceFactory.CreateSpatialReference(epsg);
                esriPolygon.SpatialReference = srs;
            }
            return esriPolygon;
        }
        public static IGeometry GetExample2()
        {
            //Composite: Cutaway Of Building With Multiple Floors Composed Of 1 TriangleStrip And 5 Ring Parts

            IGeometryCollection multiPatchGeometryCollection = new MultiPatchClass();

            IMultiPatch multiPatch = multiPatchGeometryCollection as IMultiPatch;

            //Walls

            IPointCollection wallsPointCollection = new TriangleStripClass();

            //Start

            wallsPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(3, -3, 0), ref _missing, ref _missing);
            wallsPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(3, -3, 16), ref _missing, ref _missing);

            //Right Wall

            wallsPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(3, 3, 0), ref _missing, ref _missing);
            wallsPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(3, 3, 16), ref _missing, ref _missing);

            //Back Wall

            wallsPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-3, 3, 0), ref _missing, ref _missing);
            wallsPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-3, 3, 16), ref _missing, ref _missing);

            //Left Wall

            wallsPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-3, -3, 0), ref _missing, ref _missing);
            wallsPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-3, -3, 16), ref _missing, ref _missing);

            multiPatchGeometryCollection.AddGeometry(wallsPointCollection as IGeometry, ref _missing, ref _missing);

            //Floors

            //Base

            IPointCollection basePointCollection = new RingClass();
            basePointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(3, 3, 0), ref _missing, ref _missing);
            basePointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(3, -3, 0), ref _missing, ref _missing);
            basePointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-3, -3, 0), ref _missing, ref _missing);
            basePointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-3, 3, 0), ref _missing, ref _missing);

            IRing baseRing = basePointCollection as IRing;
            baseRing.Close();

            multiPatchGeometryCollection.AddGeometry(baseRing as IGeometry, ref _missing, ref _missing);

            //First Floor

            IPointCollection firstFloorPointCollection = new RingClass();
            firstFloorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(3, 3, 4), ref _missing, ref _missing);
            firstFloorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(3, -3, 4), ref _missing, ref _missing);
            firstFloorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-3, -3, 4), ref _missing, ref _missing);
            firstFloorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-3, 3, 4), ref _missing, ref _missing);

            IRing firstFloorRing = firstFloorPointCollection as IRing;
            firstFloorRing.Close();

            multiPatchGeometryCollection.AddGeometry(firstFloorRing as IGeometry, ref _missing, ref _missing);

            //Second Floor

            IPointCollection secondFloorPointCollection = new RingClass();
            secondFloorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(3, 3, 8), ref _missing, ref _missing);
            secondFloorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(3, -3, 8), ref _missing, ref _missing);
            secondFloorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-3, -3, 8), ref _missing, ref _missing);
            secondFloorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-3, 3, 8), ref _missing, ref _missing);

            IRing secondFloorRing = secondFloorPointCollection as IRing;
            secondFloorRing.Close();

            multiPatchGeometryCollection.AddGeometry(secondFloorRing as IGeometry, ref _missing, ref _missing);

            //Third Floor

            IPointCollection thirdFloorPointCollection = new RingClass();
            thirdFloorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(3, 3, 12), ref _missing, ref _missing);
            thirdFloorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(3, -3, 12), ref _missing, ref _missing);
            thirdFloorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-3, -3, 12), ref _missing, ref _missing);
            thirdFloorPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-3, 3, 12), ref _missing, ref _missing);

            IRing thirdFloorRing = thirdFloorPointCollection as IRing;
            thirdFloorRing.Close();

            multiPatchGeometryCollection.AddGeometry(thirdFloorRing as IGeometry, ref _missing, ref _missing);

            //Roof

            IPointCollection roofPointCollection = new RingClass();
            roofPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(3, 3, 16), ref _missing, ref _missing);
            roofPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(3, -3, 16), ref _missing, ref _missing);
            roofPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-3, -3, 16), ref _missing, ref _missing);
            roofPointCollection.AddPoint(GeometryUtilities.ConstructPoint3D(-3, 3, 16), ref _missing, ref _missing);

            IRing roofRing = roofPointCollection as IRing;
            roofRing.Close();

            multiPatchGeometryCollection.AddGeometry(roofRing as IGeometry, ref _missing, ref _missing);

            return multiPatchGeometryCollection as IGeometry;
        }
예제 #33
0
        private IGeometry ConstructRing(IEnumerable<IPoint> points)
        {
            var r = new RingClass();

            foreach (var point in points)
            {
                r.AddPoint(point);
            }

            r.Close();

            return r;
        }