Esempio n. 1
0
        //获取当前的缓冲后的几何体
        private void get_BufferGeometry()
        {
            //存在上次的缓冲几何体 则先抹去其图形
            if (m_pBufferGeometry != null)
            {
                drawgeometryXOR(m_pBufferGeometry as IPolygon, m_pScreenDisplay);
            }

            //获取缓冲半径
            double dBufferSize = ((double)trackBar.Value /*/ 10*/);

            dBufferSize = dBufferSize < 1 ? 1 : dBufferSize;
            //if ( dBufferSize == 0.0) dBufferSize = 0.001;

            //==如果直接操作,则原pGeometry会被改变
            //进行克隆,获取topo实例
            IClone pClone = (IClone)m_pGeometry;
            ITopologicalOperator pTopo;

            if (m_pGeometry.GeometryType != esriGeometryType.esriGeometryBag)
            {
                pTopo = pClone.Clone() as ITopologicalOperator;

                //topo非空则进行缓冲,获取缓冲后的 m_pBufferGeometry
                if (pTopo != null)
                {
                    m_pBufferGeometry = pTopo.Buffer(dBufferSize);
                }
            }
            else
            {
                IGeometryCollection pGeometryBag = (IGeometryCollection)pClone.Clone();
                pTopo = (ITopologicalOperator)pGeometryBag.get_Geometry(0);
                IGeometry pUnionGeom = pTopo.Buffer(dBufferSize);
                for (int i = 1; i < pGeometryBag.GeometryCount; i++)
                {
                    pTopo = (ITopologicalOperator)pGeometryBag.get_Geometry(i);
                    IGeometry pTempGeom = pTopo.Buffer(dBufferSize);
                    pTopo      = (ITopologicalOperator)pUnionGeom;
                    pUnionGeom = pTopo.Union(pTempGeom);
                }
                m_pBufferGeometry = pUnionGeom;
            }
            // m_pBufferGeometry为空,直接返回
            if (m_pBufferGeometry == null)
            {
                return;
            }

            //对 m_pBufferGeometry的topo进行简化再绘出
            pTopo = m_pBufferGeometry as ITopologicalOperator;
            if (pTopo != null)
            {
                pTopo.Simplify();
            }

            IPolygon pPolygon = m_pBufferGeometry as IPolygon;

            drawgeometryXOR(pPolygon, m_pScreenDisplay);
        }
Esempio n. 2
0
        private IGeometryCollection GenerateYardSticks(IGeometryCollection verticesColl)
        {
            IPoint startPT = new PointClass();
            IPoint endPT   = new PointClass();
            IGeometryCollection yardstickColl = new GeometryBagClass();
            ISegmentCollection  yardsegColl   = new PolylineClass();
            object obj = Type.Missing;

            for (int i = 0; i < verticesColl.GeometryCount; i++)
            {
                if (i < verticesColl.GeometryCount - 1)
                {
                    ILine pLine = new LineClass();

                    startPT = verticesColl.get_Geometry(i) as IPoint;
                    endPT   = verticesColl.get_Geometry(i + 1) as IPoint;
                    pLine.PutCoords(startPT, endPT);
                    yardsegColl.AddSegment(pLine as ISegment, ref obj, ref obj);
                }
                else
                {
                    MessageBox.Show(i + " yardsticks generated");
                }
            }
            IPolyline pPolyline = (IPolyline)yardsegColl;

            yardstickColl.AddGeometry(pPolyline, ref obj, ref obj);
            return(yardstickColl);
        }
Esempio n. 3
0
        /// <summary>
        /// 算出量测计算结果,并在FormDis上进行显示
        /// </summary>
        /// <param name="ipGeo">人机交互生成的实体</param>
        public void WriteLabelText(IGeometry ipGeo)
        {
            switch (m_MeasureType)
            {
            case MeasureType.Length:              //量测长度
            {
                string strUnit = " " + (this.m_Tool as ToolMeasureLength).m_hookHelper.FocusMap.MapUnits.ToString().Substring(4);
                //this.m_LabelMeasureType.Text = "Line Measurement";
                this.m_LabelMeasureType.Text = "长度量测";
                this.m_labelArea.Visible     = true;
                if (ipGeo != null)
                {
                    IGeometryCollection ipGeoCol      = ipGeo as IGeometryCollection;
                    ISegmentCollection  ipSegmentColl = ipGeoCol.get_Geometry(0) as ISegmentCollection;
                    ILine ipLine = ipSegmentColl.get_Segment(ipSegmentColl.SegmentCount - 1) as ILine;
                    //this.m_labelSegment.Text = "段长度:" + ipLine.Length.ToString() + strUnit;
                    //this.m_labelLength.Text = "长度:" + (ipGeoCol.get_Geometry(0) as ICurve).Length.ToString() + "米";
                    this.m_labelArea.Text = "长度:" + (ipGeoCol.get_Geometry(0) as ICurve).Length.ToString("f3") + "米";
                }
                else
                {
                    this.m_labelArea.Text = "长度:" + "0" + "米";
                    //this.m_labelLength.Text = "总长度:" + "0" + strUnit;
                }
            }
            break;

            case MeasureType.Area:      //量测面积
            {
                string strUnit = " " + (this.m_Tool as ToolMeasureArea).m_hookHelper.FocusMap.MapUnits.ToString().Substring(4);
                //this.m_LabelMeasureType.Text = "Area Measurement";
                this.m_LabelMeasureType.Text = "面积量测";
                this.m_labelArea.Visible     = true;
                if (ipGeo != null)
                {
                    IGeometryCollection ipGeoCol      = ipGeo as IGeometryCollection;
                    ISegmentCollection  ipSegmentColl = ipGeoCol.get_Geometry(0) as ISegmentCollection;
                    ILine ipLine = ipSegmentColl.get_Segment(ipSegmentColl.SegmentCount - 1) as ILine;
                    //this.m_labelSegment.Text = "Segment:" + ipLine.Length.ToString() + strUnit;
                    //this.m_labelLength.Text = "Perimeter:" + (ipGeoCol.get_Geometry(0) as IRing).Length.ToString() + strUnit;
                    //this.m_labelSegment.Text = "段长度:" + ipLine.Length.ToString() + strUnit;
                    //this.m_labelLength.Text = "周长:" + (ipGeoCol.get_Geometry(0) as IRing).Length.ToString() + strUnit;

                    IClone               ipClone = ipGeo as IClone;
                    IGeometry            ipGeo1  = ipClone.Clone() as IGeometry;
                    ITopologicalOperator ipTopo  = ipGeo1 as ITopologicalOperator;
                    ipTopo.Simplify();

                    this.m_labelArea.Text = "面积:" + ((ipGeo1 as IPolygon) as IArea).Area.ToString(".###") + "平方米";
                }
                else
                {
                    this.m_labelArea.Text = "面积:" + "0" + "平方米";
                }
            }
            break;
            }
        }
Esempio n. 4
0
        private static void MergeLastWithFirstPart(IGeometryCollection paths)
        {
            int lastIndex = paths.GeometryCount - 1;

            var lastPart  = (ISegmentCollection)paths.get_Geometry(lastIndex);
            var firstPart = (ISegmentCollection)paths.get_Geometry(0);

            lastPart.AddSegmentCollection(firstPart);

            paths.RemoveGeometries(0, 1);
        }
Esempio n. 5
0
        public void UpdatePoint(int partIndex, int pointIndex, IPoint newPoint)
        {
            // TODO:  添加 ModifyPoint.WSGRI.DigitalFactory.DFQuery.IUpdatePoint.UpdatePoint 实现
            IPointCollection pColl = (IPointCollection)m_GeoColl.get_Geometry(partIndex);

            if ((pointIndex > -1) && (pointIndex < pColl.PointCount))
            {
                pColl.UpdatePoint(pointIndex, newPoint);
                Feature.Shape = m_GeoColl as IGeometry;
                Feature.Store();
            }
        }
Esempio n. 6
0
 private void ExportGeometry_ItemClick(object sender, ItemClickEventArgs e)
 {
     if (this.m_pGeometry != null)
     {
         SaveFileDialog dialog = new SaveFileDialog
         {
             Filter = "文本文件 (*.txt)|*.txt"
         };
         if (dialog.ShowDialog() == DialogResult.OK)
         {
             try
             {
                 int index =
                     this.m_pEditFeature.Fields.FindField(
                         (this.m_pEditFeature.Class as IFeatureClass).ShapeFieldName);
                 IGeometryDef geometryDef = this.m_pEditFeature.Fields.get_Field(index).GeometryDef;
                 this.m_HasZ = geometryDef.HasZ;
                 this.m_HasM = geometryDef.HasM;
                 using (StreamWriter writer = new StreamWriter(dialog.FileName))
                 {
                     if (this.m_pGeometry.GeometryType == esriGeometryType.esriGeometryPoint)
                     {
                         writer.WriteLine(this.WritePointToString(this.m_pGeometry as IPoint));
                     }
                     else if (this.m_pGeometry.GeometryType == esriGeometryType.esriGeometryMultipoint)
                     {
                         this.WritePointCollection(writer, this.m_pGeometry as IPointCollection);
                     }
                     else if ((this.m_pGeometry.GeometryType == esriGeometryType.esriGeometryPolyline) ||
                              (this.m_pGeometry.GeometryType == esriGeometryType.esriGeometryPolygon))
                     {
                         IGeometryCollection pGeometry = this.m_pGeometry as IGeometryCollection;
                         if (pGeometry.GeometryCount > 1)
                         {
                             for (int i = 0; i < pGeometry.GeometryCount; i++)
                             {
                                 writer.WriteLine("part");
                                 this.WritePointCollection(writer, pGeometry.get_Geometry(i) as IPointCollection);
                             }
                         }
                         else
                         {
                             this.WritePointCollection(writer, pGeometry.get_Geometry(0) as IPointCollection);
                         }
                     }
                 }
             }
             catch
             {
             }
         }
     }
 }
Esempio n. 7
0
        private void AddGeometryColToFeatureClass(IGeometryCollection pGeometryCollection, IFeatureClass pFeatureClass)
        {
            IFeatureCursor pFeatureCursor;
            IFeatureBuffer pFeatureBuffer;

            pFeatureCursor = pFeatureClass.Insert(true);
            pFeatureBuffer = pFeatureClass.CreateFeatureBuffer();

            IFields pFields;
            IField  pField;

            pFields = pFeatureClass.Fields;


            for (int i = 0; i < pGeometryCollection.GeometryCount; i++)
            {
                IGeometry pCurrentGeometry = pGeometryCollection.get_Geometry(i) as IGeometry;

                for (int n = 1; n <= pFields.FieldCount - 1; n++)
                {
                    pField = pFields.get_Field(n);

                    if (pField.Type == esriFieldType.esriFieldTypeGeometry)
                    {
                        pFeatureBuffer.set_Value(n, pCurrentGeometry);
                    }
                }
                pFeatureCursor.InsertFeature(pFeatureBuffer);
            }
            pFeatureCursor.Flush();
        }
Esempio n. 8
0
        // 端点捕捉
        private static void GetPortPntCollection(List <IFeature> listFeats, IFeatureClass pFeatureClass, IProximityOperator pProximity, double dSearchDist)
        {
            IPointCollection pPntColTemp = new MultipointClass();

            for (int i = 0; i < listFeats.Count; i++)
            {
                IFeature pFeature = listFeats[i];
                //判断该Feature图层
                if (pFeature.Class.ObjectClassID != pFeatureClass.ObjectClassID)
                {
                    continue;
                }

                if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline || pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                {
                    double dScreenSearchDist = pProximity.ReturnDistance(pFeature.Shape);
                    if (dScreenSearchDist < 1.5 * dSearchDist)
                    {
                        IGeometryCollection pGeoCollection = pFeature.Shape as IGeometryCollection;
                        for (int j = 0; j < pGeoCollection.GeometryCount; j++)
                        {
                            IGeometry        pGeom   = pGeoCollection.get_Geometry(j);
                            IPointCollection pPntCol = pGeom as IPointCollection;
                            m_PointCollection.AddPointCollection(pPntCol);
                            pPntColTemp.AddPointCollection(pPntCol);
                        }
                    }
                }
            }

            m_dicPointCollection.Add(pPntColTemp, "PortPnt");
        }
    public static void SchrijfTrianglesMP(IFeature pFeat)
    {
        IMultiPatch         pMultiPatch = (IMultiPatch)pFeat.ShapeCopy;
        IGeometryCollection GeoColl     = (IGeometryCollection)pMultiPatch;

        //Schrijf TrianglesVlag = true
        Boolean TrianglesVlag = true;

        WriteBoolean(TrianglesVlag);

        //Schrijf aantal parts
        int aantalparts = GeoColl.GeometryCount;

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

        //Loop door de onderdelen
        for (int i = 0; i < aantalparts; i++)
        {
            IPointCollection pPartPoints = (IPointCollection)GeoColl.get_Geometry(i);

            //Schrijf aantal punten
            int aantalpunten = pPartPoints.PointCount;
            Naar3dsMax.binWriter.Write(aantalpunten);     //int

            //Loop door de vertices van de onderdelen
            for (int n = 0; n < aantalpunten; n++)
            {
                SchrijfTransformatie(pPartPoints.get_Point(n));
            }
        }
    }
    //----------------------------------------------------------------------------------

    public static void SchrijfRingenMP(IFeature pFeat)
    {
        IMultiPatch         pMultiPatch = (IMultiPatch)pFeat.ShapeCopy;
        IGeometryCollection GeoColl     = (IGeometryCollection)pMultiPatch;

        //Schrijf TrianglesVlag = false
        Boolean TrianglesVlag = false;

        WriteBoolean(TrianglesVlag);

        //Schrijf aantalringen
        int aantalringen = GeoColl.GeometryCount;

        Naar3dsMax.binWriter.Write(aantalringen);

        //Loop door de ringencollectie
        for (int i = 0; i < aantalringen; i++)
        {
            IRing   pRing                   = (IRing)GeoColl.get_Geometry(i);
            Boolean isbeginning             = true;
            esriMultiPatchRingType ringtype = pMultiPatch.GetRingType(pRing, ref isbeginning);

            //Schrijf Buitenringvlag
            Boolean Buitenringvlag = (ringtype == esriMultiPatchRingType.esriMultiPatchOuterRing);
            WriteBoolean(Buitenringvlag);
            SchrijfRing(pRing);
        }
    }
    //----------------------------------------------------------------------------------

    public static void SchrijfPolyline(IFeature pFeat)
    {
        IPolyline           pPolyline = (IPolyline)pFeat.ShapeCopy;
        IGeometryCollection GeoColl   = (IGeometryCollection)pPolyline;
        IPointCollection    pPartPoints;

        //Schrijf aantal onderdelen
        int aantalonderdelen = GeoColl.GeometryCount;

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

        //Loop door de onderdelen
        for (int i = 0; i < aantalonderdelen; i++)
        {
            pPartPoints = (IPointCollection)GeoColl.get_Geometry(i);

            //Schrijf puntenaantal
            int puntenaantal = pPartPoints.PointCount;
            Naar3dsMax.binWriter.Write(puntenaantal);     //int

            //Loop door de vertices van de onderdelen
            for (int n = 0; n < puntenaantal; n++)
            {
                SchrijfTransformatie(pPartPoints.get_Point(n));
            }
        }
    }
Esempio n. 12
0
 /// <summary>
 /// 显示点列表
 /// </summary>
 /// <param name="index"></param>
 private void ShowPointList(int index)
 {
     if (!this._isFirst)
     {
         try
         {
             DataTable dataSource = this.gridView1.DataSource as DataTable;
             if (dataSource == null)
             {
                 dataSource = this.CreateTable();
             }
             dataSource.Clear();
             IGeometryCollection geometry = this.m_Geometry as IGeometryCollection;
             IPointCollection    points   = geometry.get_Geometry(index) as IPointCollection;
             IPoint  point = null;
             DataRow row   = null;
             for (int i = 0; i < (points.PointCount - 1); i++)
             {
                 point  = points.get_Point(i);
                 row    = dataSource.NewRow();
                 row[0] = i.ToString();
                 row[1] = point.X;
                 row[2] = point.Y;
                 dataSource.Rows.Add(row);
             }
             this.gcVertex.DataSource = dataSource;
             this.gcVertex.Refresh();
         }
         catch
         {
         }
     }
 }
Esempio n. 13
0
        //面构成线
        private static IPolyline PolygonToPolyline(ref IPolygon pPolygon)
        {
            try
            {
                //创建一个新的Polygon geometry.
                IGeometryCollection pPolygonGeometryCol = new PolylineClass();

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

                IGeometryCollection pGeoms_Polygon = pClone.Clone() as IGeometryCollection;
                object pBObj = Type.Missing;
                object pAObj = Type.Missing;
                for (int i = 0; i < pGeoms_Polygon.GeometryCount; i++)
                {
                    //通过Polyline的每个Path创建为一个新的Ring,并把Ring增加到一个新的Polygon
                    ISegmentCollection pSegs_Path = new Path() as ISegmentCollection;
                    pSegs_Path.AddSegmentCollection(pGeoms_Polygon.get_Geometry(i) as ISegmentCollection);
                    pPolygonGeometryCol.AddGeometry(pSegs_Path as IGeometry, ref pBObj, ref pAObj);
                }
                //生成的Polygon旋转的顺序可能不正确,为确保正确调用SimplifyPreserveFromTo
                IPolyline pNewPolyline = new PolylineClass();
                pNewPolyline = pPolygonGeometryCol as IPolyline;

                return(pNewPolyline);
            }
            catch
            {
                return(null);
            }
        }
Esempio n. 14
0
        private List <IPoint> SplitPolyline(IPolyline polyline, IPointCollection intersectpointsColl, IPoint presentCP)
        {
            IEnumVertex pEnumVertex = intersectpointsColl.EnumVertices;
            //IPolycurve2 has SplitAtPoints

            IPolycurve2 pPolyCurve = polyline as IPolycurve2;

            pPolyCurve.SplitAtPoints(pEnumVertex, false, true, -1);
            IGeometryCollection geoColl = pPolyCurve as IGeometryCollection;
            //MessageBox.Show(geoColl.GeometryCount.ToString());
            List <IPoint> ptlist = new List <IPoint>();
            // The results are pathclass
            IPath resultPath;

            for (int i = 0; i < geoColl.GeometryCount; i++)
            {
                object obj = Type.Missing;
                resultPath = new PathClass();
                resultPath = (IPath)geoColl.get_Geometry(i);
                IGeometryCollection lineColl = new PolylineClass();
                lineColl.AddGeometry(resultPath, ref obj, ref obj);
                IPolyline           line         = (IPolyline)lineColl;
                IRelationalOperator pRelOperator = (IRelationalOperator)line;
                if (pRelOperator.Touches(presentCP) || pRelOperator.Contains(presentCP))
                {
                    IPoint temPT1 = resultPath.FromPoint;
                    IPoint temPT2 = resultPath.ToPoint;
                    //pGeometryCollection.AddGeometry(temPT1);
                    //pGeometryCollection.AddGeometry(temPT2);
                    ptlist.Add(temPT1);
                    ptlist.Add(temPT2);
                }
            }
            return(ptlist);
        }
Esempio n. 15
0
        /// <summary>
        /// 多部分(多外环)的多边形转成多个单部分的多边形
        /// </summary>
        /// <param name="polygon"></param>
        /// <returns></returns>
        public static IPolygon[] MultiPartToSinglePart(this IPolygon4 polygon)
        {
            List <IPolygon> polygons = new List <IPolygon>();

            //外部环
            IGeometryBag        exteriorRingGeometryBag        = polygon.ExteriorRingBag;
            IGeometryCollection exteriorRingGeometryCollection = exteriorRingGeometryBag as IGeometryCollection;

            for (int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++)
            {
                IGeometry exteriorRingGeometry = exteriorRingGeometryCollection.get_Geometry(i);
                IRing     ring = exteriorRingGeometry as IRing;
                ring.Close();
                IGeometryCollection pGeometryColl = new PolygonClass();
                pGeometryColl.AddGeometry(ring);

                //内部环
                IGeometryBag        interiorRingGeometryBag        = polygon.get_InteriorRingBag(exteriorRingGeometry as IRing);
                IGeometryCollection interiorRingGeometryCollection = interiorRingGeometryBag as IGeometryCollection;
                for (int k = 0; k < interiorRingGeometryCollection.GeometryCount; k++)
                {
                    IGeometry interiorRingGeometry = interiorRingGeometryCollection.get_Geometry(k);
                    IRing     ring2 = interiorRingGeometry as IRing;
                    ring2.Close();
                    pGeometryColl.AddGeometry(ring2);
                }

                ITopologicalOperator pTopological = pGeometryColl as ITopologicalOperator;
                pTopological.Simplify();
                IPolygon p = pGeometryColl as IPolygon;
                polygons.Add(p);
            }
            return(polygons.ToArray());
        }
 public static IEnumerable <T> GetTEbFromIGeoCol <T>(IGeometryCollection pGeoCol)
 {
     for (int i = 0; i < pGeoCol.GeometryCount; i++)
     {
         yield return((T)pGeoCol.get_Geometry(i));
     }
 }
Esempio n. 17
0
        private void method_2(ICoFeature icoFeature_0, IFeature ifeature_0)
        {
            ICoPolygonFeature feature = icoFeature_0 as ICoPolygonFeature;
            IPolygon          shape   = ifeature_0.Shape as IPolygon;

            if ((feature != null) && (shape != null))
            {
                IGeometryCollection geometrys = shape as IGeometryCollection;
                if (geometrys != null)
                {
                    for (int i = 0; i < geometrys.GeometryCount; i++)
                    {
                        IPointCollection points = geometrys.get_Geometry(i) as IPointCollection;
                        if (points != null)
                        {
                            CoPointCollection item = new CoPointCollection();
                            for (int j = 0; j < points.PointCount; j++)
                            {
                                IPoint point = points.get_Point(j);
                                if (point != null)
                                {
                                    item.Add(new CoPointClass(point.X, point.Y, point.Z));
                                }
                            }
                            feature.Points.Add(item);
                        }
                    }
                }
            }
        }
Esempio n. 18
0
        /// <summary>
        /// 获取构成多边形的所有环的点集(包括外环和内环),返回的环内的点集统一按顺时针或逆时针排序
        /// </summary>
        /// <param name="polygon"></param>
        /// <param name="clockwise">时针方向,true为顺时针,false为逆时针</param>
        /// <returns></returns>
        public static List <List <IPoint> > GetRingPointsByClockwise(this IPolygon4 polygon, bool clockwise)
        {
            List <List <IPoint> > rings = new List <List <IPoint> >();
            //外部环
            IGeometryBag        exteriorRingGeometryBag        = polygon.ExteriorRingBag;//全部外部环
            IGeometryCollection exteriorRingGeometryCollection = (IGeometryCollection)exteriorRingGeometryBag;

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

                var interiorRings = GetInteriorRingPoints(polygon, exteriorRingGeometry as IRing); //内部环
                if (clockwise)                                                                     //内环的点是逆时针排序的,要求顺时针排序时反序List
                {
                    foreach (var ring in interiorRings)
                    {
                        ring.Reverse();
                    }
                }
                rings.AddRange(interiorRings);
            }
            return(rings);
        }
        private GeoAPI.Geometries.IMultiLineString ConvertTo(IPolyline lines)
        {
            IGeometryCollection paths = lines as IGeometryCollection;

            if (paths != null)
            {
                List <GeoAPI.Geometries.ILineString> newLines = new List <GeoAPI.Geometries.ILineString>();
                for (int i = 0; i < paths.GeometryCount; i++)
                {
                    IPath path = paths.get_Geometry(i) as IPath;
                    if (path != null)
                    {
                        List <GeoAPI.Geometries.ICoordinate> list = new List <GeoAPI.Geometries.ICoordinate>();
                        IPointCollection pointCollection          = path as IPointCollection;
                        for (int j = 0; j < pointCollection.PointCount; j++)
                        {
                            IPoint point = pointCollection.get_Point(j);
                            list.Add(new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(point.X, point.Y, point.Z));
                        }
                        newLines.Add(new GisSharpBlog.NetTopologySuite.Geometries.LineString(list.ToArray()));
                    }
                }
                return(new GisSharpBlog.NetTopologySuite.Geometries.MultiLineString(newLines.ToArray()));
            }

            return(null);
        }
Esempio n. 20
0
        /// <summary>
        /// Construct multi patch outline
        /// </summary>
        /// <param name="multiPatchGeometry">multi patch geometry</param>
        /// <returns>object implements IGeometryCollection</returns>
        public static IGeometryCollection ConstructMultiPatchOutline(IGeometry multiPatchGeometry)
        {
            IGeometryCollection outlineGeometryCollection = new GeometryBagClass();

            IGeometryCollection multiPatchGeometryCollection = multiPatchGeometry as IGeometryCollection;

            for (int i = 0; i < multiPatchGeometryCollection.GeometryCount; i++)
            {
                IGeometry geometry = multiPatchGeometryCollection.get_Geometry(i);

                switch (geometry.GeometryType)
                {
                case esriGeometryType.esriGeometryTriangleStrip:
                    outlineGeometryCollection.AddGeometryCollection(ConstructTriangleStripOutline(geometry));
                    break;

                case esriGeometryType.esriGeometryTriangleFan:
                    outlineGeometryCollection.AddGeometryCollection(ConstructTriangleFanOutline(geometry));
                    break;

                case esriGeometryType.esriGeometryTriangles:
                    outlineGeometryCollection.AddGeometryCollection(ConstructTrianglesOutline(geometry));
                    break;

                case esriGeometryType.esriGeometryRing:
                    outlineGeometryCollection.AddGeometry(ConstructRingOutline(geometry), ref missing, ref missing);
                    break;

                default:
                    throw new Exception("Unhandled Geometry Type. " + geometry.GeometryType);
                }
            }

            return(outlineGeometryCollection);
        }
Esempio n. 21
0
        private void method_1(ICoFeature icoFeature_0, IGeometry igeometry_0)
        {
            ICoPolylineFeature feature  = icoFeature_0 as ICoPolylineFeature;
            IPolyline          polyline = igeometry_0 as IPolyline;

            if ((feature != null) && (polyline != null))
            {
                IGeometryCollection geometrys = polyline as IGeometryCollection;
                if (geometrys != null)
                {
                    for (int i = 0; i < geometrys.GeometryCount; i++)
                    {
                        CoPointCollection item    = new CoPointCollection();
                        IPointCollection  points2 = geometrys.get_Geometry(i) as IPointCollection;
                        if (points2 != null)
                        {
                            for (int j = 0; j < points2.PointCount; j++)
                            {
                                IPoint point = points2.get_Point(j);
                                item.Add(new CoPointClass(point.X, point.Y, point.Z));
                            }
                            feature.Points.Add(item);
                        }
                    }
                }
            }
        }
Esempio n. 22
0
        public static void AddOutlineToGraphicsLayer3D(IGraphicsContainer3D graphicsContainer3D, IGeometryCollection geometryCollection, IColor color, esriSimple3DLineStyle style, double width)
        {
            for (int i = 0; i < geometryCollection.GeometryCount; i++)
            {
                IGeometry geometry = geometryCollection.get_Geometry(i);

                graphicsContainer3D.AddElement(ElementUtilities.ConstructPolylineElement(geometry, color, style, width));
            }
        }
        public static void AddOutlineToGraphicsLayer3D(IGraphicsContainer3D graphicsContainer3D, IGeometryCollection geometryCollection, IColor color, esriSimple3DLineStyle style, double width)
        {
            for (int i = 0; i < geometryCollection.GeometryCount; i++)
            {
                IGeometry geometry = geometryCollection.get_Geometry(i);

                graphicsContainer3D.AddElement(ElementUtilities.ConstructPolylineElement(geometry, color, style, width));
            }
        }
Esempio n. 24
0
        private void DrawGraphics(IGeometryCollection geometries)
        {
            IGeometry geometry;

            for (int i = 0; i < geometries.GeometryCount; i++)
            {
                geometry = geometries.get_Geometry(i);
                DrawGraphics(geometry);
            }
        }
Esempio n. 25
0
        /// <summary>
        /// 获得一个Geometry的所有顶点
        /// </summary>
        /// <param name="sourceGeom"></param>
        /// <returns></returns>
        public static IMultipoint GetVertices(IGeometry pGeometry)
        {
            if (pGeometry == null)
            {
                return(null);
            }

            IPointCollection pPointCollection = new MultipointClass();

            object obj = null;

            if (pGeometry is IPoint)
            {
                pPointCollection.AddPoint(pGeometry as IPoint, ref obj, ref obj);
                return(pPointCollection as IMultipoint);
            }
            else if (pGeometry is ISegment)
            {
                ISegment pSegment = pGeometry as ISegment;
                pPointCollection.AddPoint(pSegment.FromPoint, ref obj, ref obj);
                pPointCollection.AddPoint(pSegment.ToPoint, ref obj, ref obj);
            }
            else if (pGeometry is IEnvelope)
            {
                IEnvelope pEnvelope = pGeometry as IEnvelope;
                pPointCollection.AddPoint(pEnvelope.UpperLeft, ref obj, ref obj);
                pPointCollection.AddPoint(pEnvelope.UpperRight, ref obj, ref obj);
                pPointCollection.AddPoint(pEnvelope.LowerLeft, ref obj, ref obj);
                pPointCollection.AddPoint(pEnvelope.LowerRight, ref obj, ref obj);
            }
            else if (pGeometry is IGeometryCollection)
            {
                IGeometryCollection pGeometryCollection = pGeometry as IGeometryCollection;
                for (int i = 0; i < pGeometryCollection.GeometryCount; i++)
                {
                    IGeometry        pSubGeo             = pGeometryCollection.get_Geometry(i);
                    IPointCollection pSubPointCollection = GetVertices(pSubGeo) as IPointCollection;
                    if (pSubPointCollection != null)
                    {
                        pPointCollection.AddPointCollection(pSubPointCollection);
                    }
                }
            }

            if (pPointCollection.PointCount == 0)
            {
                return(null);
            }
            else
            {
                return(pPointCollection as IMultipoint);
            }
        }
Esempio n. 26
0
        public bool CheckFeature(IFeature pFeature, ref object pErrFeatureInf)
        {
            IFieldEdit        edit             = this._layer.FeatureClass.Fields.get_Field(this._layer.FeatureClass.Fields.FindField(this._layer.FeatureClass.ShapeFieldName)) as IFieldEdit;
            ISpatialReference spatialReference = edit.GeometryDef.SpatialReference;
            bool                flag           = true;
            List <double[]>     list           = (List <double[]>)pErrFeatureInf;
            IGeometryCollection shape          = pFeature.Shape as IGeometryCollection;

            for (int i = 0; i < shape.GeometryCount; i++)
            {
                esriNonSimpleReasonEnum enum2     = esriNonSimpleReasonEnum.esriNonSimpleOK;
                IPointCollection        newPoints = shape.get_Geometry(i) as IPointCollection;
                PolylineClass           o         = new PolylineClass();
                o.AddPointCollection(newPoints);
                o.SpatialReference = spatialReference;
                ITopologicalOperator3 ioperator = o as ITopologicalOperator3;
                ioperator.IsKnownSimple_2 = false;
                if (!ioperator.get_IsSimpleEx(out enum2))
                {
                    IRing ring = newPoints as IRing;
                    int   num2 = 0;
                    if (ring.IsClosed)
                    {
                        num2 = 1;
                    }
                    flag = false;
                    List <string> list2 = new List <string>();
                    List <string> list3 = new List <string>();
                    for (int j = num2; j < newPoints.PointCount; j++)
                    {
                        IPoint point = newPoints.get_Point(j);
                        string item  = point.X.ToString() + "," + point.Y.ToString();
                        if (list2.Contains(item))
                        {
                            if (!list3.Contains(item))
                            {
                                double[] numArray = new double[] { point.X, point.Y };
                                list.Add(numArray);
                                list3.Add(item);
                            }
                        }
                        else
                        {
                            list2.Add(item);
                        }
                    }
                }
                Marshal.ReleaseComObject(o);
                o = null;
            }
            return(flag);
        }
Esempio n. 27
0
        /// <summary>
        /// 获取多边形指定外环所包含的内环
        /// </summary>
        /// <param name="polygon">多边形</param>
        /// <param name="exteriorRing">外部环,此外部环必须是指定多边形的</param>
        /// <returns></returns>
        public static List <IRing> GetInteriorRings(this IPolygon4 polygon, IRing exteriorRing)
        {
            List <IRing>        rings = new List <IRing>();
            IGeometryBag        interiorRingGeometryBag        = polygon.get_InteriorRingBag(exteriorRing);
            IGeometryCollection interiorRingGeometryCollection = (IGeometryCollection)interiorRingGeometryBag;

            for (int k = 0; k < interiorRingGeometryCollection.GeometryCount; k++)
            {
                IGeometry interiorRingGeometry = interiorRingGeometryCollection.get_Geometry(k);
                rings.Add(interiorRingGeometry as IRing);
            }
            return(rings);
        }
Esempio n. 28
0
        /// <summary>
        /// 获取多边形的外环
        /// </summary>
        /// <param name="polygon"></param>
        /// <returns></returns>
        public static List <IRing> GetExteriorRings(this IPolygon4 polygon)
        {
            List <IRing>        rings = new List <IRing>();
            IGeometryBag        exteriorRingGeometryBag        = polygon.ExteriorRingBag;//全部外部环
            IGeometryCollection exteriorRingGeometryCollection = (IGeometryCollection)exteriorRingGeometryBag;

            for (int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++)
            {
                IGeometry exteriorRingGeometry = exteriorRingGeometryCollection.get_Geometry(i);
                rings.Add(exteriorRingGeometry as IRing);
            }
            return(rings);
        }
Esempio n. 29
0
        /// <summary>
        /// 获取构成多边形的所有环的数量
        /// </summary>
        /// <param name="polygon"></param>
        /// <returns></returns>
        public static int GetRingCount(this IPolygon4 polygon)
        {
            int count = 0;
            IGeometryCollection exteriorRingGeometryCollection = (IGeometryCollection)polygon.ExteriorRingBag;//全部外部环

            for (int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++)
            {
                count++;
                IGeometry exteriorRingGeometry = exteriorRingGeometryCollection.get_Geometry(i);
                count += GetInnerRingCount(polygon, exteriorRingGeometry as IRing); //内部环
            }
            return(count);
        }
Esempio n. 30
0
 private void InsertPointBefore_ItemClick(object sender, ItemClickEventArgs e)
 {
     try
     {
         IPointCollection pGeometry;
         IEnvelope        envelope = this.m_pGeometry.Envelope;
         double           dx       = CommonHelper.ConvertPixelsToMapUnits(this.m_pMap as IActiveView, 6.0);
         envelope.Expand(dx, dx, false);
         if (this.m_pGeometry.GeometryType == esriGeometryType.esriGeometryMultipoint)
         {
             pGeometry = this.m_pGeometry as IPointCollection;
         }
         else
         {
             IGeometryCollection geometrys = this.m_pGeometry as IGeometryCollection;
             pGeometry = geometrys.get_Geometry(this.listBox1.SelectedIndex) as IPointCollection;
         }
         int    i       = this.listView1.SelectedIndices[0];
         IPoint point   = pGeometry.get_Point(i - 1);
         IPoint point2  = pGeometry.get_Point(i);
         IPoint inPoint = new PointClass();
         inPoint.PutCoords((point.X + point2.X) / 2.0, (point.Y + point2.Y) / 2.0);
         if (this.m_HasZ)
         {
             inPoint.Z = (point.Z + point2.Z) / 2.0;
         }
         if (this.m_HasM)
         {
             inPoint.M = (point.M + point2.M) / 2.0;
         }
         object before = i;
         object after  = Missing.Value;
         pGeometry.AddPoint(inPoint, ref before, ref after);
         this.ResetListView();
         (this.m_pMap as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, envelope);
         IWorkspaceEdit workspace = (this.m_pEditFeature.Class as IDataset).Workspace as IWorkspaceEdit;
         workspace.StartEditOperation();
         this.m_pEditFeature.Shape = this.m_pGeometry;
         this.m_pEditFeature.Store();
         workspace.StopEditOperation();
         envelope = this.m_pGeometry.Envelope;
         envelope.Expand(dx, dx, false);
         (this.m_pMap as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, envelope);
         this.SetStatus();
     }
     catch (Exception exception)
     {
         Logger.Current.Error("", exception, "");
     }
 }
Esempio n. 31
0
        /// <summary>
        ///     DETERMINE IF POLYCURVE NEEDS TO BE SIMPLIFIED.  MULTI-PART GEOMETRIES ARE SUPPORTED
        ///     BUT WE NEED TO DETERMINE IF THENY NEED TO BE SIMPLIFIED.  THIS ROUTINE MEASURES THE
        ///     DISTANCE BETWEEN GEOMETRY PARTS TO DETERMINE IF TWO CONSECUTIVE PARTS ARE SPATIALLY
        ///     ADJACENT.
        /// </summary>
        /// <param name="polyCurve">geometry polycurve </param>
        /// <returns>NON-GEODATABASE GEOMETRY = TRUE and RESULT OF ROUTING MULTIPLE STOPS = FALSE</returns>
        internal static bool ShouldSimplify(IPolycurve3 polyCurve)
        {
            IGeometryCollection subGeometries = (IGeometryCollection)polyCurve;
            int geometryCount = subGeometries.GeometryCount;

            if (geometryCount > 1)
            {
                for (int geomIndex = 0; geomIndex < (geometryCount - 1); geomIndex++)
                {
                    ICurve subGeom1 = (ICurve)subGeometries.get_Geometry(geomIndex);
                    ICurve subGeom2 = (ICurve)subGeometries.get_Geometry(geomIndex + 1);

                    IProximityOperator proximityOp          = (IProximityOperator)subGeom1.ToPoint;
                    double             distanceBetweenParts = proximityOp.ReturnDistance(subGeom2.FromPoint);
                    if (distanceBetweenParts > 0.0)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 32
0
        // creates a multipart polyline with all polylines in the geometry collection
        private IGeometry BuildMultiPartPolyline(IGeometryCollection pGeomCollection)
        {
            IGeometry retVal = null;
            try
            {
                object missing = System.Reflection.Missing.Value;

                IPolyline pPolylineNew = new PolylineClass();
                IGeometryCollection pGeomCollectionNew = (IGeometryCollection)pPolylineNew;

                for(int x = 0; x < pGeomCollection.GeometryCount; x++)
                {
                    IPolyline pPolyline = (IPolyline)pGeomCollection.get_Geometry(x);

                    IGeometryCollection pPathColl;
                    pPathColl = (IGeometryCollection)pPolyline;

                    for(int y = 0; y < pPathColl.GeometryCount; y++)
                    {
                        IPath pPath = (IPath)pPathColl.get_Geometry(y);
                        pGeomCollectionNew.AddGeometry(pPath,ref missing,ref missing);
                    }
                }

                retVal = (IGeometry)pGeomCollectionNew;

            }
            catch(Exception ex)
            {
                Debug.WriteLine(ex.Message + "\n" + ex.StackTrace);
                util.Logger.Write(" Descrip  : Building a multipart polyline (if required)." +
                    "\n Message  : " + ex.Message +
                    "\n StackTrc : " + ex.StackTrace,util.Logger.LogLevel.Debug);
            }
            return retVal;
        }
Esempio n. 33
0
        // creates a multipart polygon with all polygons in the geometry collection
        private IGeometry BuildMultiPartPolygon(IGeometryCollection pGeomCollection)
        {
            IGeometry retVal = null;

            try
            {
                object missing = System.Reflection.Missing.Value;
                IPolygon pPolygonNew = new PolygonClass();
                IGeometryCollection pGeomCollectionNew = (IGeometryCollection)pPolygonNew;

                //IArea pArea = null;

                for(int x = 0; x < pGeomCollection.GeometryCount; x++)
                {

                    IPolygon pPolygon = (IPolygon)pGeomCollection.get_Geometry(x);

                    //pArea = (IArea)pPolygon;
                    //Debug.WriteLine("area = " + pArea.Area);

                    IGeometryCollection pRingColl;
                    pRingColl = (IGeometryCollection)pPolygon;

                    for(int y = 0; y < pRingColl.GeometryCount; y++)
                    {
                        IRing pRing = (IRing)pRingColl.get_Geometry(y);
                        //Debug.WriteLine("length = " + pRing.Length);
                        pGeomCollectionNew.AddGeometry(pRing,ref missing,ref missing);
                    }
                }

                //pArea = (IArea)pGeomCollectionNew;
                //Debug.WriteLine("Total area = " + pArea.Area);

                retVal = (IGeometry)pGeomCollectionNew;

            }
            catch(Exception ex)
            {
                Debug.WriteLine(ex.Message + "\n" + ex.StackTrace);
                util.Logger.Write(" Descrip  : Building a multipart polygon (if required)." +
                    "\n Message  : " + ex.Message +
                    "\n StackTrc : " + ex.StackTrace,util.Logger.LogLevel.Debug);

            }

            return retVal;
        }