Esempio n. 1
0
        //节点捕捉
        private static void GetNodeCollection(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;
                }

                double dScreenSearchDist = pProximity.ReturnDistance(pFeature.Shape);
                if (dScreenSearchDist < 1.5 * dSearchDist)
                {
                    if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                    {
                        IPoint pPoint = pFeature.Shape as IPoint;
                        object befor  = Type.Missing;
                        object after  = Type.Missing;
                        m_PointCollection.AddPoint(pPoint, ref befor, ref after);
                        pPntColTemp.AddPoint(pPoint, ref befor, ref after);
                    }
                    else
                    {
                        IPointCollection pTempPtcln = pFeature.Shape as IPointCollection;
                        m_PointCollection.AddPointCollection(pTempPtcln);
                        pPntColTemp.AddPointCollection(pTempPtcln);
                    }
                }
            }

            m_dicPointCollection.Add(pPntColTemp, "Node");
        }
Esempio n. 2
0
        //相交点捕捉
        private static void GetIntersectPntCollection(List <IFeature> listFeats, IFeatureClass pFeatureClass, IProximityOperator pProximity, double dSearchDist)
        {
            IPointCollection pPntColTemp = new MultipointClass();

            List <IFeature> listFeatsTemp = new List <IFeature>();

            for (int i = 0; i < listFeats.Count; i++)
            {
                IFeature pFeature = listFeats[i];
                if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline || pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                {
                    double dScreenSearchDist = pProximity.ReturnDistance(pFeature.Shape);
                    if (dScreenSearchDist < 1.5 * dSearchDist)
                    {
                        listFeatsTemp.Add(pFeature);
                    }
                }
            }

            //收集线两两相交点,收集的交点有重复,但是不影响结果
            foreach (IFeature pFeat in listFeatsTemp)
            {
                IPointCollection pPntCol = GetAllIntersect(pFeat, listFeatsTemp);
                m_PointCollection.AddPointCollection(pPntCol);
                pPntColTemp.AddPointCollection(pPntCol);
            }

            m_dicPointCollection.Add(pPntColTemp, "IntersectPnt");
        }
Esempio n. 3
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");
        }
Esempio n. 4
0
        /// <summary>
        /// 得到Feature与 FeatureList所有的交点
        /// </summary>
        /// <param name="vNewFeature"></param>
        /// <param name="vFeatureCol"></param>
        /// <returns></returns>
        private IPointCollection GetAllIntersect(IFeature OneOfFeature, List <IFeature> list_AllFeatures)
        {
            IPolyline        tempLine   = new PolylineClass();
            IPointCollection pPointColl = tempLine as IPointCollection;

            pPointColl.AddPointCollection(OneOfFeature.Shape as IPointCollection);

            IPointCollection vItersectCol = new MultipointClass();


            IMultipoint vIntersectPnt = new MultipointClass();

            IFeature vFeature;

            for (int i = 0; i < list_AllFeatures.Count; i++)
            {
                vFeature = list_AllFeatures[i];
                if (vFeature != OneOfFeature)
                {
                    vIntersectPnt = GetIntersection(vFeature.Shape, tempLine as IPolyline) as IMultipoint;
                    if (vIntersectPnt != null)
                    {
                        vItersectCol.AddPointCollection(vIntersectPnt as IPointCollection);
                    }
                }
            }

            return(vItersectCol);
        }
Esempio n. 5
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. 6
0
        private static List <WKSPointVA> GetFromIPointCollection5(
            [NotNull] IMultiPatch multiPatch)
        {
            IPointCollection5 mps = new MultipointClass();

            mps.AddPointCollection((IPointCollection)multiPatch);

            int pointCount = mps.PointCount;
            var result     = new List <WKSPointVA>(pointCount);

            for (int i = 0; i < pointCount; i++)
            {
                WKSPointVA wks;
                mps.QueryWKSPointVA(i, 1, out wks);
                result.Add(wks);
            }

            return(result);
        }
Esempio n. 7
0
        public static List <WKSPointVA> GetPoints([NotNull] IPointCollection points)
        {
            Assert.ArgumentNotNull(points, nameof(points));

            IPointCollection5 mps = new MultipointClass();

            mps.AddPointCollection(points);

            int pointCount = points.PointCount;

            int iPoint = 0;
            var result = new List <WKSPointVA>(pointCount);

            for (int i = 0; i < pointCount; i++)
            {
                result.Add(GetWKSPointVA(mps, ref iPoint));
            }

            return(result);
        }
Esempio n. 8
0
        //得到所有交点
        private static IPointCollection GetAllIntersect(IFeature pFeat, List <IFeature> listFeats)
        {
            IPointCollection pItersectCol = new MultipointClass();

            IPointCollection pPntColTemp = pFeat.Shape as IPointCollection;
            IPolyline        pPolyline   = pPntColTemp as IPolyline;

            foreach (IFeature pFeatTemp in listFeats)
            {
                IGeometry pGeometry = pFeat.Shape;
                if (!pFeat.Equals(pFeatTemp))
                {
                    IPointCollection pItersectColTemp = GetIntersection(pFeatTemp.Shape, pPolyline);
                    if (pItersectColTemp != null)
                    {
                        pItersectCol.AddPointCollection(pItersectColTemp);
                    }
                }
            }

            return(pItersectCol);
        }
Esempio n. 9
0
        private void addPointCollectionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IPointCollection4 pointCollection  = new MultipointClass();
            IPointCollection  pointCollection2 = new MultipointClass();
            IGeometryBridge   geometryBridge   = new GeometryEnvironmentClass();

            IPoint[]    points = new PointClass[10];
            IMultipoint multipoint;
            object      missing = Type.Missing;
            IPoint      point;

            for (int i = 0; i < 10; i++)
            {
                point = new PointClass();
                point.PutCoords(i * 5, i);
                points[i] = point;
            }
            geometryBridge.SetPoints(pointCollection, ref points);
            pointCollection2.AddPointCollection(pointCollection);
            multipoint = pointCollection2 as IMultipoint;
            addFeature("multipoint", multipoint as IGeometry);
            this.axMapControl1.Extent = multipoint.Envelope;
            this.axMapControl1.Refresh();
        }
Esempio n. 10
0
        /// <summary>
        /// 内插值法求点的“地面高”
        /// </summary>
        /// <param name="pPnt"></param>
        /// <returns>点的高程值</returns>
        private double Calculate_Z2(IPoint pPnt)
        {
            double pZ = 0;
            //================================================
            double dRad                  = double.Parse("15".Trim()) / 2.0; //搜索半径一半
            double dBufferRad            = 0.0;
            ITopologicalOperator pTopo   = pPnt as ITopologicalOperator;
            IGeometry            pBuffer = pTopo.Buffer(dRad);

            IPointCollection pPC = new MultipointClass();

            pPC.AddPointCollection(PointCollectionFromEdit(pPnt, dRad));
            pPC.AddPointCollection(pntColl(pBuffer));
            //================================================
            int pTag = 1;

            //如果点数小于2,则增大搜索半径,重新搜索
            while (pPC.PointCount < 2)
            {
                if (pTag > 4)//若重新搜索4次还没有点,则退出
                {
                    break;
                }
                pTag++;
                dBufferRad = dRad * pTag;
                pBuffer    = pTopo.Buffer(dBufferRad);

                pPC.RemovePoints(0, pPC.PointCount);
                pPC.AddPointCollection(PointCollectionFromEdit(pPnt, dBufferRad));
                pPC.AddPointCollection(pntColl(pBuffer));
            }
            //================================================
            if (pPC.PointCount > 1)
            {
                double pTolZ   = 0;
                double pLength = 0;
                double iP      = 0;
                double pToliP  = 0;//权系数

                for (int i = 0; i < pPC.PointCount; i++)
                {
                    IPoint pPt = pPC.get_Point(i);

                    if (pPt.Z >= 0 || pPt.Z < 0)
                    {
                        pLength = Get_Len_2piont(pPnt, pPt);
                        if (pLength > 0)
                        {
                            iP     = 1 / Math.Pow(pLength, 2);
                            pToliP = pToliP + iP;
                            pTolZ  = pTolZ + iP * pPt.Z;
                        }
                    }//if (pPt.Z != double.NaN)
                }

                if (pToliP != 0)
                {
                    pZ = pTolZ / pToliP;
                }    //pToliP = 0使用初始化值0作为pZ结果
                else //大于两个点均与查询点重合
                {
                    pZ = 0;
                }
            }
            else//点数小于两个
            {
                //if (frmSetValue.UseConst)
                //{
                //    pZ = frmSetValue.ConstHight;
                //}
                //else
                //{
                //    frmSetValue pFrmSetValue = new frmSetValue(pPnt.X, pPnt.Y);
                //    if (pFrmSetValue.ShowDialog() == DialogResult.OK)
                //    {
                //        pZ = pFrmSetValue.ReturnValue;
                //        bolEdit = true;
                //    }
                //}
            }
            //================================================

            return(pZ);
        }
Esempio n. 11
0
        public static List <List <WKSPointVA> > GetRings([NotNull] IMultiPatch multiPatch)
        {
            Assert.ArgumentNotNull(multiPatch, nameof(multiPatch));

            IPointCollection5 mps = new MultipointClass();

            mps.AddPointCollection((IPointCollection)multiPatch);

            var parts     = (IGeometryCollection)multiPatch;
            int partCount = parts.GeometryCount;
            var rings     = new List <List <WKSPointVA> >(partCount);

            int pointIndex = 0;

            for (int partIndex = 0; partIndex < partCount; partIndex++)
            {
                IGeometry part = parts.Geometry[partIndex];

                var partPoints = (IPointCollection)part;

                if (part is IRing)
                {
                    int ringCount  = partPoints.PointCount;
                    var ringPoints = new List <WKSPointVA>(ringCount);
                    for (int iRingPoint = 0; iRingPoint < ringCount; iRingPoint++)
                    {
                        ringPoints.Add(GetWKSPointVA(mps, ref pointIndex));
                    }

                    rings.Add(ringPoints);
                }
                else if (part is ITriangleFan)
                {
                    int        fanCount = partPoints.PointCount;
                    WKSPointVA center   = GetWKSPointVA(mps, ref pointIndex);
                    WKSPointVA first    = GetWKSPointVA(mps, ref pointIndex);

                    for (int i = 2; i < fanCount; i++)
                    {
                        WKSPointVA second         = GetWKSPointVA(mps, ref pointIndex);
                        var        trainglePoints =
                            new List <WKSPointVA> {
                            center, first, second, center
                        };
                        rings.Add(trainglePoints);

                        first = second;
                    }
                }
                else if (part is ITriangleStrip)
                {
                    int        stripCount = partPoints.PointCount;
                    WKSPointVA first      = GetWKSPointVA(mps, ref pointIndex);
                    WKSPointVA second     = GetWKSPointVA(mps, ref pointIndex);

                    for (int i = 2; i < stripCount; i++)
                    {
                        WKSPointVA third = GetWKSPointVA(mps, ref pointIndex);
                        var        tri   = new List <WKSPointVA> {
                            first, second, third, first
                        };
                        rings.Add(tri);

                        first  = second;
                        second = third;
                    }
                }
                else if (part is ITriangles)
                {
                    int trianglePointsCount = partPoints.PointCount;
                    Assert.AreEqual(trianglePointsCount % 3, 0,
                                    string.Format("{0} points in ITriangles",
                                                  trianglePointsCount));
                    int triangleCount = trianglePointsCount / 3;

                    for (int i = 0; i < triangleCount; i++)
                    {
                        WKSPointVA first  = GetWKSPointVA(mps, ref pointIndex);
                        WKSPointVA second = GetWKSPointVA(mps, ref pointIndex);
                        WKSPointVA third  = GetWKSPointVA(mps, ref pointIndex);

                        var trianglePoints =
                            new List <WKSPointVA> {
                            first, second, third, first
                        };

                        rings.Add(trianglePoints);
                    }
                }
                else
                {
                    throw new InvalidOperationException(string.Format("{0} not handled",
                                                                      part.GeometryType));
                }

                Marshal.ReleaseComObject(part);
            }

            return(rings);
        }
Esempio n. 12
0
        public void SplitPolylines()        //分割线
        {
            m_pLineFeed = (INewLineFeedback)m_pFeedback;
            IPolyline pFeatureScissors = (IPolyline)m_pLineFeed.Stop();             //结束绘制切割线

            if (pFeatureScissors.Length == 0)
            {
                Reset();
                return;
            }

            ITopologicalOperator pTopologim_CalOperator = (ITopologicalOperator)pFeatureScissors;

            ILayer pFeatureLayer;

            pFeatureLayer = m_App.CurrentEditLayer;
            IGeometry pOldGeometry;
            IFeature  pOldFeature;

            IWorkspaceEdit pWorkspaceEdit;

            pWorkspaceEdit = (IWorkspaceEdit)CommonFunction.GetLayerWorkspace(pFeatureLayer);
            if (pWorkspaceEdit == null)
            {
                return;
            }
            if (!pWorkspaceEdit.IsBeingEdited())
            {
                return;
            }
            pWorkspaceEdit.StartEditOperation();

            for (int i = 0; i < m_OriginFeatureArray.Count; i++)         //遍历每个选中的要素
            {
                pOldFeature  = (IFeature)m_OriginFeatureArray.get_Element(i);
                pOldGeometry = (IGeometry)pOldFeature.Shape;

                IArray pArray = new ArrayClass();                 //将地理要素的坐标信息添加到点数组中
                pArray = CommonFunction.GeometryToArray(pOldGeometry);

                //跳转到拓扑操作接口,求“剪刀”与选中要素的交点
                IGeometry pIntersectGeo = pTopologim_CalOperator.Intersect(pOldGeometry, esriGeometryDimension.esriGeometry0Dimension);
                if (pIntersectGeo == null)
                {
                    return;                                        //无交点,则返回
                }
                ITopologicalOperator pTopOp = (ITopologicalOperator)pIntersectGeo;
                pTopOp.Simplify();
                IPointCollection pPointCol = (IPointCollection)pIntersectGeo;                //交点的集合

                //用相交的点集合打断该线
                IPointCollection pTmpPointCol = new MultipointClass();
                pTmpPointCol.AddPointCollection(pPointCol);                //临时点集

                IPolycurve2 pPolyCurve;
                pPolyCurve = (IPolycurve2)pOldGeometry;                //被剪切的线要素
                ((ITopologicalOperator)pPolyCurve).Simplify();

                IGeometryCollection pGeoCollection;
                IGeometryCollection pTmpGeoCollection;                     //保存每次打断产生的线段

                pTmpGeoCollection = (IGeometryCollection)pPolyCurve;
                pGeoCollection    = (IGeometryCollection)pPolyCurve;

                for (int j = 0; j < pPointCol.PointCount; j++)             //遍历每个交点
                {
                    IPoint pSplitPoint = pPointCol.get_Point(j);

                    int GeoCount            = 0;
                    int pGeoCollectionCount = pGeoCollection.GeometryCount;
                    while (GeoCount < pGeoCollectionCount)                   //遍历每个几何形体
                    {
                        IPolycurve2 pTmpPolycurve2;
                        pTmpPolycurve2 = CommonFunction.BuildPolyLineFromSegmentCollection((ISegmentCollection)pGeoCollection.get_Geometry(GeoCount));

                        bool bProject;                           //是否投影
                        bool bCreatePart;                        //是否创建新的附件
                        bool bSplitted;                          //分裂是否成功
                        int  lNewPart;
                        int  lNewSeg;
                        bProject    = true;
                        bCreatePart = true;

                        ((ITopologicalOperator)pTmpPolycurve2).Simplify();

                        pTmpPolycurve2.SplitAtPoint(pSplitPoint, bProject, bCreatePart, out bSplitted, out lNewPart, out lNewSeg);

                        if (bSplitted)                       //更新pGeoCollection
                        {
                            pGeoCollection.RemoveGeometries(GeoCount, 1);
                            pTmpGeoCollection = (IGeometryCollection)pTmpPolycurve2;
                            pGeoCollection.AddGeometryCollection(pTmpGeoCollection);
                        }

                        GeoCount++;
                    }
                }

                IGeometryCollection pGeometryCol = pGeoCollection;                //被打断后的线的集合
                for (int intCount = 0; intCount < pGeometryCol.GeometryCount; intCount++)
                {
                    IPolycurve2 pPolyline = CommonFunction.BuildPolyLineFromSegmentCollection((ISegmentCollection)pGeometryCol.get_Geometry(intCount));
                    CommonFunction.AddFeature(m_MapControl, (IGeometry)pPolyline, m_App.CurrentEditLayer, pOldFeature, pArray);
                }
                pOldFeature.Delete();
            }

            m_App.Workbench.CommandBarManager.Tools["2dmap.DFEditorTool.Undo"].SharedProps.Enabled = true;

            pWorkspaceEdit.StopEditOperation();

            Reset();
        }
Esempio n. 13
0
        private int ReportInvalidPoints([NotNull] IPointCollection points,
                                        [NotNull] IRow row)
        {
            var points5 = points as IPointCollection5;

            if (points5 == null)
            {
                points5 = new MultipointClass();
                points5.AddPointCollection(points);
            }

            int pointCount = points.PointCount;

            if (_sourcePoints == null || _sourcePoints.Length < points.PointCount)
            {
                const int margin = 2000;
                _sourcePoints = new WKSPointVA[pointCount + margin];
            }

            points5.QueryWKSPointVA(0, pointCount, out _sourcePoints[0]);
            // This would be fast, but about 4* slower then the statement above
            //for (int i = 0; i < pointCount; i++)
            //{
            //	WKSPointVA wksPoint;
            //	points5.QueryWKSPointVA(i, 1, out wksPoint);

            Dictionary <IssueCode, ErrorPoints> errorPointsDict = null;

            for (var i = 0; i < pointCount; i++)
            {
                WKSPointVA wksPoint = _sourcePoints[i];

                string    error;
                bool      isNewRow = i == 0;
                IssueCode code;
                if (IsInvalidValue(wksPoint.m_m, row, isNewRow, out error, out code))
                {
                    if (errorPointsDict == null)
                    {
                        errorPointsDict = new Dictionary <IssueCode, ErrorPoints>();
                    }

                    Assert.NotNull(code);
                    ErrorPoints errorPoints;
                    if (!errorPointsDict.TryGetValue(code, out errorPoints))
                    {
                        errorPoints = new ErrorPoints();
                        errorPointsDict.Add(code, errorPoints);
                    }

                    errorPoints.Add(wksPoint, error);
                }
            }
            //ICollection<IPoint> errorPoints = MeasureUtils.GetPointsWithInvalidM(
            //	points, _queryPoint, invalidValue);

            if (errorPointsDict == null)
            {
                return(NoError);
            }

            var errorCount = 0;

            foreach (KeyValuePair <IssueCode, ErrorPoints> pair in errorPointsDict)
            {
                IssueCode issueCode = pair.Key;

                ErrorPoints       errorPoints   = pair.Value;
                IPointCollection5 errorGeometry = new MultipointClass();
                errorGeometry.AddWKSPointVA(errorPoints.Points.Count,
                                            ref errorPoints.Points.ToArray()[0]);
                ((IGeometry)errorGeometry).SpatialReference =
                    ((IGeometry)points).SpatialReference;

                string errorDescription = GetErrorDescription(issueCode, errorPoints.Points.Count,
                                                              errorPoints.Errors);

                errorCount += ReportError(errorDescription, (IGeometry)errorGeometry,
                                          issueCode, _shapeFieldName,
                                          row);
            }

            return(errorCount);
        }