zoukankan      html  css  js  c++  java
  • AO 由坐标创建一个多边形

    创建一个环的 多边形

            IGeometryCollection CreatPolygon(List<jsonpoint> lstPts)
            {
                IPoint[] ComPoints = new IPoint[lstPts.Count];
                for (int j = 0; j < lstPts.Count; j++)
                {
                    ISpatialReferenceFactory fatory = new SpatialReferenceEnvironmentClass();
                    ComPoints[j] = new PointClass();
                    ComPoints[j].SpatialReference = fatory.CreateGeographicCoordinateSystem(4326);
                    ComPoints[j].X = lstPts[j].x;
                    ComPoints[j].Y = lstPts[j].y;
                    ComPoints[j].Project(sdeSpatialreference);
                }
    
                ISegmentCollection pSegments;
                ILine pLine;
                IRing pRing;
                pSegments = new RingClass();
                object Missing = Type.Missing;
                for (int k = 0; k < lstPts.Count - 1; k++)
                {
                    pLine = new LineClass();
                    pLine.PutCoords(ComPoints[k], ComPoints[k + 1]);
                    pSegments.AddSegment(pLine as ISegment, ref Missing, ref Missing);
                }
                pRing = pSegments as IRing;
    
                pRing.Close();
    
                IGeometryCollection pPolygon = new PolygonClass();
                pPolygon.AddGeometry(pRing, ref Missing, ref Missing);
    
                return pPolygon;
    
            }

    多个环的多边形

      IGeometryCollection CreatPolygon(List<jsonpoint>[] pRings)
            {
                IGeometryCollection pPolygon = new PolygonClass();
                for (int m = 0; m < pRings.Length; m++)
                {
                    IPoint[] ComPoints = new IPoint[pRings[m].Count];
                    for (int j = 0; j < pRings[m].Count; j++)
                    {
                        ISpatialReferenceFactory fatory = new SpatialReferenceEnvironmentClass();
                        ComPoints[j] = new PointClass();
                        ComPoints[j].SpatialReference = fatory.CreateGeographicCoordinateSystem(4326);
                        ComPoints[j].X = pRings[m][j].x;
                        ComPoints[j].Y = pRings[m][j].y;
                        ComPoints[j].Project(sdeSpatialreference);
                    }
    
                    ISegmentCollection pSegments;
                    ILine pLine;
                    IRing pRing;
                    pSegments = new RingClass();
                    object Missing = Type.Missing;
                    for (int k = 0; k < pRings[m].Count - 1; k++)
                    {
                        pLine = new LineClass();
                        pLine.PutCoords(ComPoints[k], ComPoints[k + 1]);
                        pSegments.AddSegment(pLine as ISegment, ref Missing, ref Missing);
                    }
                    pRing = pSegments as IRing;
    
                    pRing.Close();
    
                    pPolygon.AddGeometry(pRing, ref Missing, ref Missing);
                }
    
                return pPolygon;
            }

    完整示例

            private void AddNewFeatures(IFeatureClass featureclass)
            {
                IPoint[] pts = new IPoint[4];
                for (int i = 0; i < 4; i++)
                {
                    pts[i] = new PointClass();
                }
                pts[0].X = 121.480;
                pts[0].Y = 29.890;
                pts[1].X = 121.490;
                pts[1].Y = 29.890;
                pts[2].X = 121.490;
                pts[2].Y = 29.900;
                pts[3].X = 121.480;
                pts[3].Y = 29.900;
    
    
                ISegmentCollection pSegments;
                ILine pLine;
                IRing pRing;
                pSegments = new RingClass();
                object Missing = Type.Missing;
                for (int j = 3; j > 1; j++)
                {
                    pLine = new LineClass();
                    pLine.PutCoords(pts[j], pts[j- 1]);
                    pSegments.AddSegment(pLine as ISegment, ref Missing, ref Missing);
                }
    
    
                pRing = pSegments as IRing;
    
                pRing.Close();
    
                IGeometryCollection pPolygon = new PolygonClass();
                pPolygon.AddGeometry(pRing, ref Missing, ref Missing);
    
    
                IFeatureBuffer featurebuffer = featureclass.CreateFeatureBuffer();
                IFeatureCursor featurecursor = featureclass.Insert(true);
                featurebuffer.Shape = (IPolygon)pPolygon;
                featurebuffer.set_Value(featurebuffer.Fields.FindField("CODE"), "0_0");
    
                object featureOid = featurecursor.InsertFeature(featurebuffer);
                featurecursor.Flush();
                Marshal.ReleaseComObject(featurecursor);
               // pCursor = null;
            }
  • 相关阅读:
    [NOI2004]cashier 郁闷的出纳员
    [HNOI2004]宠物收养所
    [HNOI2002]营业额统计
    浅谈算法——莫比乌斯反演
    浅谈算法——splay
    [POI2006]Tet-Tetris 3D
    BZOJ2733 [HNOI2012]永无乡 【线段树合并】
    UOJ279 【UTR #2】题目交流通道
    UOJ278 【UTR #2】题目排列顺序
    POJ2761 Feed the dogs
  • 原文地址:https://www.cnblogs.com/marky/p/4025725.html
Copyright © 2011-2022 走看看