Example #1
0
        static private void GetRealPt(IFeatureLayer conFyr, IFeature pFeature, bool isPeakOrBottom, int fid, int sMark)//true表示山包线,false表示山洼线
        {
            Dictionary <IPoint, IFeature> feaAndCenPt = RaterPtToVectorPt(pFeature);

            for (int i = 0; i < feaAndCenPt.Count; i++)
            {
                IPoint               newPeakOrBotPt = feaAndCenPt.Keys.ElementAt(i);
                IPointCollection     ptC            = feaAndCenPt.Values.ElementAt(i).Shape as IPointCollection;
                double               Z              = Math.Round(ptC.get_Point(0).Z, 0);
                IPolyline            mainLine       = GetMainDirection(pFeature);
                IPolyline            sectionPly     = GetaSectionPly(mainLine, newPeakOrBotPt);
                IPoint               leftPtOfMouPt  = new PointClass();
                IPoint               rightPtOfMouPt = new PointClass();
                ITopologicalOperator sTopo          = sectionPly as ITopologicalOperator;
                IGeometry            pGeo           = sTopo.Intersect(pFeature.Shape, esriGeometryDimension.esriGeometry0Dimension);
                IPointCollection     ptCol          = new MultipointClass();
                if (pGeo.IsEmpty == false)
                {
                    ptCol = pGeo as IPointCollection;
                    IPoint pt1 = ptCol.get_Point(0);
                    IPoint pt2 = ptCol.get_Point(1);
                    if (pt1.X > pt2.X)
                    {
                        rightPtOfMouPt = pt1;
                        leftPtOfMouPt  = pt2;
                    }
                    else
                    {
                        rightPtOfMouPt = pt2;
                        leftPtOfMouPt  = pt1;
                    }
                }

                IPoint   leftPtOfAdjPt  = new PointClass();
                IPoint   rightPtOfAdjPt = new PointClass();
                IFeature adjacentF      = GetAdjacentFea(closedline, Z, newPeakOrBotPt, isPeakOrBottom);
                if (adjacentF == null)
                {
                    adjacentF = GetAdjacentFea(openline, Z, newPeakOrBotPt, isPeakOrBottom);
                }
                pGeo = sTopo.Intersect(adjacentF.Shape, esriGeometryDimension.esriGeometry0Dimension);
                if (pGeo.IsEmpty == false)
                {
                    ptCol = pGeo as IPointCollection;
                    if (ptCol.PointCount == 2)
                    {
                        IPoint pt1 = ptCol.get_Point(0);
                        IPoint pt2 = ptCol.get_Point(1);
                        if (pt1.X > pt2.X)
                        {
                            rightPtOfAdjPt = pt1;
                            leftPtOfAdjPt  = pt2;
                        }
                        else
                        {
                            rightPtOfAdjPt = pt2;
                            leftPtOfAdjPt  = pt1;
                        }
                    }
                    else if (ptCol.PointCount > 2)
                    {
                        Dictionary <IPoint, double> dic = new Dictionary <IPoint, double>();
                        for (int i_1 = 0; i_1 < ptCol.PointCount; i_1++)
                        {
                            IPoint pt  = ptCol.get_Point(i_1);
                            double dis = Math.Pow(newPeakOrBotPt.X - pt.X, 2) + Math.Pow(newPeakOrBotPt.Y - pt.Y, 2);
                            dic.Add(pt, dis);
                        }
                        var           disCd  = from objDic in dic orderby objDic.Value ascending select objDic;
                        List <IPoint> ptList = new List <IPoint>();
                        foreach (KeyValuePair <IPoint, double> key in disCd)
                        {
                            ptList.Add(key.Key);
                            if (ptList.Count == 2)
                            {
                                break;
                            }
                        }
                        IPoint pt1 = ptList[0];
                        IPoint pt2 = ptList[1];
                        if (pt1.X > pt2.X)
                        {
                            rightPtOfAdjPt = pt1;
                            leftPtOfAdjPt  = pt2;
                        }
                        else
                        {
                            rightPtOfAdjPt = pt2;
                            leftPtOfAdjPt  = pt1;
                        }
                    }
                    else if (ptCol.PointCount == 1)
                    {
                        IPoint pt1 = ptCol.get_Point(0);
                        IPoint pt2 = new PointClass();
                        Dictionary <IPolyline, int> boundD = GetBounds.GetNewBoundAndPtsDataFun(conFyr);
                        for (int j = 0; j < boundD.Count; j++)
                        {
                            IPolyline ply = boundD.Keys.ElementAt(j);
                            IGeometry pg  = sTopo.Intersect(ply, esriGeometryDimension.esriGeometry0Dimension);
                            if (pg.IsEmpty == false)
                            {
                                IPointCollection otherPtc = pg as IPointCollection;
                                pt2 = otherPtc.get_Point(0);
                                break;
                            }
                        }
                        if (pt1.X > pt2.X)
                        {
                            rightPtOfAdjPt = pt1;
                            leftPtOfAdjPt  = pt2;
                        }
                        else
                        {
                            rightPtOfAdjPt = pt2;
                            leftPtOfAdjPt  = pt1;
                        }
                    }
                }
                ILine newLine = new LineClass();
                newLine.FromPoint = sectionPly.FromPoint;
                newLine.ToPoint   = sectionPly.ToPoint;
                IPoint newPt1 = new PointClass();
                IPoint newPt2 = new PointClass();
                newPt1 = RotateCoordinate(leftPtOfMouPt, newLine.Angle);
                newPt2 = RotateCoordinate(rightPtOfMouPt, newLine.Angle);
                double angle1   = 0;
                double angle2   = 0;
                double rightDis = Math.Sqrt(Math.Pow(rightPtOfMouPt.X - rightPtOfAdjPt.X, 2) + Math.Pow(rightPtOfMouPt.Y - Math.Abs(rightPtOfAdjPt.Y), 2)); //右边
                double leftDis  = Math.Sqrt(Math.Pow(leftPtOfAdjPt.X - leftPtOfMouPt.X, 2) + Math.Pow(leftPtOfAdjPt.Y - Math.Abs(leftPtOfMouPt.Y), 2));     //左边
                if (isPeakOrBottom == true)
                {
                    if (leftDis < rightDis)
                    {
                        angle1 = Math.Atan(intervalValue / leftDis);
                        angle2 = 2 * Math.PI - Math.Atan(intervalValue / rightDis);
                    }
                    else if (leftDis > rightDis)
                    {
                        angle1 = Math.PI - Math.Atan(intervalValue / rightDis);
                        angle2 = Math.PI + Math.Atan(intervalValue / leftDis);
                    }
                }
                else
                {
                    if (leftDis < rightDis)
                    {
                        angle1 = 2 * Math.PI - Math.Atan(intervalValue / leftDis);
                        angle2 = Math.Atan(intervalValue / rightDis);
                    }
                    else if (leftDis > rightDis)
                    {
                        angle1 = Math.PI + Math.Atan(intervalValue / rightDis);
                        angle2 = Math.PI - Math.Atan(intervalValue / leftDis);
                    }
                }

                Dictionary <double, double> ptXZDic = new Dictionary <double, double>();
                GetCalculatedPoints.dTightness = 2.5;
                for (int j = 0; j < 1; j++)
                {
                    ptXZDic = GetCalculatedPoints.CreateNewPoint(newPt1.X, Z, newPt2.X, Z, angle1, angle2, 20);
                    ptXZDic = SortedByZValue(ptXZDic, isPeakOrBottom);
                    double diffZ = ptXZDic.Values.ElementAt(0);
                    IPoint ppts  = RotateCoordinate(newPeakOrBotPt, newLine.Angle);
                    if ((diffZ < Z + intervalValue && diffZ > Z) || (diffZ > Z - intervalValue && diffZ < Z))
                    {
                        IPoint pt = new PointClass();
                        if (ptXZDic.Keys.ElementAt(0) > ppts.X)
                        {
                            pt.X = ppts.X + Math.Abs(ptXZDic.Keys.ElementAt(0) - ppts.X);
                        }
                        else
                        {
                            pt.X = ppts.X - Math.Abs(ptXZDic.Keys.ElementAt(0) - ppts.X);
                        }
                        pt.Y = ((pt.X - newPt2.X) * (newPt1.Y - newPt2.Y) / (newPt1.X - newPt2.X)) + newPt2.Y;
                        IPoint nPt = RotateCoordinate(pt, -newLine.Angle);
                        nPt.Z = ptXZDic.Values.ElementAt(0);
                        mounTPtList.Add(nPt, feaAndCenPt.Values.ElementAt(i));
                        break;
                    }
                    else
                    {
                        GetCalculatedPoints.dTightness -= 0.1;
                        j = -1;
                    }
                }
            }
        }
Example #2
0
        public static IGroupElement CreateFacadesFromPolygon(IFeature ifeature_0, IFeature3DProperties ifeature3DProperties_0, clsTextureGroup clsTextureGroup_0, ISurface isurface_0, string string_0, IPolygon ipolygon_0, bool bool_0)
        {
            IGroupElement groupElement = null;
            IGroupElement result;

            try
            {
                IEncode3DProperties encode3DProperties = new GeometryEnvironment() as IEncode3DProperties;
                IGroupElement       groupElement2      = new GroupElement() as IGroupElement;
                if (modFacades.m_limitAngle == 0.0)
                {
                    modFacades.m_limitAngle = 0.5235987666666666;
                }
                IGeometry geometry = null;
                if (ifeature_0 != null)
                {
                    if (ifeature3DProperties_0 != null && bool_0)
                    {
                        ifeature3DProperties_0.ApplyFeatureProperties(ifeature_0, out geometry, false);
                    }
                    else
                    {
                        geometry = ifeature_0.Shape;
                    }
                }
                else if (ipolygon_0 != null)
                {
                    geometry = ipolygon_0;
                }
                if (geometry == null)
                {
                    result = null;
                    return(result);
                }
                if (!(geometry is IMultiPatch))
                {
                }
                IEnvelope         envelope         = geometry.Envelope;
                double            num              = envelope.ZMin;
                ISpatialReference spatialReference = BuildingProperty.Scene.SpatialReference;
                geometry.Project(spatialReference);
                string a = num.ToString();
                if (a.Equals("非数字"))
                {
                    num = 0.0;
                }
                double num2 = 0.0;
                if (ifeature3DProperties_0 != null)
                {
                    I3DProperties i3DProperties = ifeature3DProperties_0 as I3DProperties;
                    if (i3DProperties.OffsetExpressionString.Length > 0)
                    {
                        try
                        {
                            num2 = Convert.ToDouble(i3DProperties.OffsetExpressionString);
                        }
                        catch
                        {
                        }
                    }
                    if (geometry is IPolygon)
                    {
                        num += num2;
                    }
                }
                IGeometryCollection geometryCollection = geometry as IGeometryCollection;
                int geometryCount = geometryCollection.GeometryCount;
                int num3;
                if (geometry is IMultiPatch)
                {
                    geometryCount = geometryCollection.GeometryCount;
                    num3          = geometryCollection.GeometryCount * 2 / 3;
                    modFacades.m_extrusionHeight = geometry.Envelope.ZMax - geometry.Envelope.ZMin;
                }
                else
                {
                    num3          = 0;
                    geometryCount = geometryCollection.GeometryCount;
                }
                if (modFacades.m_extrusionHeight < 1.0)
                {
                    modFacades.m_extrusionHeight = 1.0;
                }
                IPoint point = null;
                double num4  = 0.0;
                double num5  = 0.0;
                double num6  = 0.0;
                object value = Missing.Value;
                for (int i = num3; i < geometryCount; i++)
                {
                    IGeometry        geometry2    = geometryCollection.get_Geometry(i);
                    esriGeometryType geometryType = geometry2.GeometryType;
                    if (geometryType == esriGeometryType.esriGeometryRing || geometryType == esriGeometryType.esriGeometryPolyline)
                    {
                        IPointCollection pointCollection = geometry2 as IPointCollection;
                        int pointCount = pointCollection.PointCount;
                        if (pointCount >= 2)
                        {
                            int                 num7 = 0;
                            int                 num8 = 1;
                            bool                flag = false;
                            IPointCollection    pointCollection2;
                            double              m;
                            IMultiPatch         multiPatch;
                            IGeometryCollection geometryCollection2;
                            IZAware             iZAware;
                            IMAware             iMAware;
                            IElement            element;
                            while (!flag)
                            {
                                bool flag2 = false;
                                while (num8 < pointCount && !flag2)
                                {
                                    if (num8 - num7 == 1)
                                    {
                                        IPoint point2 = pointCollection.get_Point(num7);
                                        point = pointCollection.get_Point(num8);
                                        num5  = point.X - point2.X;
                                        num6  = point.Y - point2.Y;
                                        num4  = Math.Sqrt(num5 * num5 + num6 * num6);
                                        if (isurface_0 != null)
                                        {
                                            num  = isurface_0.get_Z(point.X, point.Y);
                                            num += num2;
                                        }
                                    }
                                    else
                                    {
                                        IPoint point2 = point;
                                        double num9   = num5;
                                        double num10  = num6;
                                        point = pointCollection.get_Point(num8);
                                        if (isurface_0 != null)
                                        {
                                            num  = isurface_0.get_Z(point.X, point.Y);
                                            num += num2;
                                        }
                                        num5 = point.X - point2.X;
                                        num6 = point.Y - point2.Y;
                                        double num11 = Math.Sqrt(num9 * num9 + num10 * num10);
                                        double num12 = Math.Sqrt(num5 * num5 + num6 * num6);
                                        double num13 = (num9 * num5 + num10 * num6) / (num11 * num12);
                                        if (num13 < Math.Cos(modFacades.m_limitAngle))
                                        {
                                            flag2 = true;
                                            break;
                                        }
                                        num4 += num12;
                                    }
                                    num8++;
                                }
                                if (flag2)
                                {
                                    num8--;
                                }
                                else
                                {
                                    num8--;
                                }
                                pointCollection2 = new TriangleStrip();
                                double num14 = 0.0;
                                for (int j = num7; j <= num8; j++)
                                {
                                    if (j > 0)
                                    {
                                        IPoint point2 = point;
                                        point  = pointCollection.get_Point(j);
                                        num5   = point.X - point2.Y;
                                        num6   = point.Y - point2.Y;
                                        num14 += Math.Sqrt(num5 * num5 + num6 * num6);
                                    }
                                    else
                                    {
                                        point = pointCollection.get_Point(j);
                                    }
                                    point.Z = num;
                                    m       = 0.0;
                                    encode3DProperties.PackTexture2D(num14 / num4, 0.0, out m);
                                    point.M = m;
                                    IClone clone = point as IClone;
                                    pointCollection2.AddPoint(clone.Clone() as IPoint, ref value, ref value);
                                    point.Z = num + modFacades.m_extrusionHeight;
                                    m       = 0.0;
                                    encode3DProperties.PackTexture2D(num14 / num4, -1.0, out m);
                                    point.M = m;
                                    pointCollection2.AddPoint(clone.Clone() as IPoint, ref value, ref value);
                                }
                                multiPatch          = new MultiPatch() as IMultiPatch;
                                geometryCollection2 = (multiPatch as IGeometryCollection);
                                iZAware             = (multiPatch as IZAware);
                                iZAware.ZAware      = true;
                                iMAware             = (multiPatch as IMAware);
                                iMAware.MAware      = true;
                                geometryCollection2.AddGeometry(pointCollection2 as IGeometry, ref value, ref value);
                                if (clsTextureGroup_0 != null)
                                {
                                    int index = modFacades.FindTextureByAspect(clsTextureGroup_0, num4 / modFacades.m_extrusionHeight);
                                    element = modFacades.CreateElement(multiPatch, clsTextureGroup_0.Symbols[index], string_0);
                                }
                                else
                                {
                                    element = modFacades.CreateElement(multiPatch, null, string_0);
                                }
                                if (element != null)
                                {
                                    groupElement2.AddElement(element);
                                }
                                num7 = num8;
                                num8 = num7 + 1;
                                if (num7 >= pointCount - 1)
                                {
                                    flag = true;
                                }
                            }
                            IVector3D vector3D = new Vector3D() as IVector3D;
                            vector3D.XComponent = 0.0;
                            vector3D.YComponent = 0.0;
                            vector3D.ZComponent = 1.0;
                            m = 0.0;
                            encode3DProperties.PackNormal(vector3D, out m);
                            pointCollection2 = new Ring();
                            for (int j = 0; j <= pointCount - 1; j++)
                            {
                                IPoint point3 = pointCollection.get_Point(j);
                                point3.Z = num + modFacades.m_extrusionHeight;
                                point3.M = 0.0;
                                IClone clone = point3 as IClone;
                                pointCollection2.AddPoint(clone.Clone() as IPoint, ref value, ref value);
                            }
                            IRing ring = pointCollection2 as IRing;
                            ring.Close();
                            multiPatch          = new MultiPatch() as IMultiPatch;
                            geometryCollection2 = (multiPatch as IGeometryCollection);
                            iZAware             = (multiPatch as IZAware);
                            iZAware.ZAware      = true;
                            iMAware             = (multiPatch as IMAware);
                            iMAware.MAware      = true;
                            geometryCollection2.AddGeometry(pointCollection2 as IGeometry, ref value, ref value);
                            multiPatch.PutRingType(pointCollection2 as IRing, esriMultiPatchRingType.esriMultiPatchOuterRing);
                            if (clsTextureGroup_0 != null)
                            {
                                element = modFacades.CreateElement(multiPatch, clsTextureGroup_0.RoofSymbol, string_0 + ";ROOFCOLOR=" + clsTextureGroup_0.RoofColorRGB.ToString());
                            }
                            else
                            {
                                element = modFacades.CreateElement(multiPatch, null, string_0 + ";ROOFCOLOR=1");
                            }
                            if (element != null)
                            {
                                groupElement2.AddElement(element);
                            }
                        }
                    }
                }
                if (groupElement2 != null)
                {
                    IElementProperties elementProperties = groupElement2 as IElementProperties;
                    elementProperties.Name = string_0;
                }
                groupElement = groupElement2;
                result       = groupElement;
                return(result);
            }
            catch
            {
            }
            result = groupElement;
            return(result);
        }
Example #3
0
        private void DelVertexNode(IPoint pPnt)
        {
            try
            {
                IFeatureLayer pFeaturelayer = m_EngineEditLayers.TargetLayer;
                IActiveView pActiveView = m_activeView;
                IPoint pPoint = pPnt;
                if (pFeaturelayer.FeatureClass == null) return;
                //如果不是面状地物则退出
                if (pFeaturelayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryEnvelope
                    && pFeaturelayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolygon
                    && pFeaturelayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryLine
                    && pFeaturelayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolyline)
                    return;
                IGeometry pGeo = null;
                IFeature pSelFeature = null;
                pSelFeature = EditVertexClass.GetSelectedFeature(pFeaturelayer);
                //是否有选中的几何体
                if (pSelFeature == null)
                {
                    return;
                }
                pGeo = pSelFeature.ShapeCopy;
                double pSrchDis = 0;
                double pHitDis = 0;
                pSrchDis = pActiveView.Extent.Width / 200;
                pPoint.Z = 0;
                int pIndex = 0;
                IElement pElement = null;
                IHitTest pHtTest = null;
                bool pBoolHitTest = false;
                IPoint pPtHit = null;
                IPointCollection pPointCol = null;
                IPolygon pPolygon = null;
                IPolyline pPyline = null;
                bool bRightZSide = true;
                int pInt = 0;
                m_EngineEditor.StartOperation();
                //删除面状要素的节点
                if (pFeaturelayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon
                    || pFeaturelayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryEnvelope)
                {
                    pElement = new PolygonElement();
                    pElement.Geometry = pSelFeature.Shape;
                    IPolygon pPoly = null;
                    pPoly = pElement.Geometry as IPolygon;
                    pHtTest = pPoly as IHitTest;
                    pBoolHitTest = pHtTest.HitTest(pPoint, pSrchDis, esriGeometryHitPartType.esriGeometryPartVertex,
                        pPtHit, ref pHitDis, ref pInt, ref pIndex, ref  bRightZSide);
                    if (pBoolHitTest == false)
                        return;
                    EditVertexClass.pHitPnt = pPtHit;
                    pPointCol = pSelFeature.ShapeCopy as IPointCollection;
                    //如果多边形的节点只有3个则不能再删除了
                    if (pPointCol.PointCount <= 4)
                    {
                        MessageBox.Show("多边形的节点至少需要3个!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    //顶点删除
                    pPointCol.RemovePoints(pIndex, 1);
                    pPolygon = pPointCol as IPolygon;
                    pPolygon.Close();
                    pSelFeature.Shape = pPolygon;
                    pSelFeature.Store();

                }
                //删除线状要素的节点
                else if (pFeaturelayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline
                    || pFeaturelayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryLine)
                {
                    pElement = new LineElement();
                    pElement.Geometry = pSelFeature.Shape;
                    IPolyline pPolyLine = default(IPolyline);
                    pPolyLine = pElement.Geometry as IPolyline;
                    pHtTest = pPolyLine as IHitTest;
                    pBoolHitTest = pHtTest.HitTest(pPoint, pSrchDis, esriGeometryHitPartType.esriGeometryPartVertex,
                        pPtHit, ref pHitDis, ref pInt, ref pIndex, ref bRightZSide);
                    if (pBoolHitTest == false)
                        return;
                    EditVertexClass.pHitPnt = pPtHit;
                    pPointCol = pSelFeature.ShapeCopy as IPointCollection;
                    //如果Polyline节点只有2个则不能再删除了
                    if (pPointCol.PointCount <= 2)
                    {
                        MessageBox.Show("线的节点至少需要2个!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    //顶点删除
                    pPointCol.RemovePoints(pIndex, 1);
                    pPyline = pPointCol as IPolyline;
                    pSelFeature.Shape = pPyline;
                    pSelFeature.Store();
                }
                //与选中点坐标相同的节点都删除
                for (int i = 0; i <= pPointCol.PointCount - 1; i++)
                {
                    if (i > pPointCol.PointCount - 1)
                        break;
                    if (pPointCol.get_Point(i).X == pPoint.X & pPointCol.get_Point(i).Y == pPoint.Y)
                    {
                        pPointCol.RemovePoints(i, 1);
                        i = i - 1;
                    }
                }
                //停止编辑
                m_EngineEditor.StopOperation("DelVertexTool");
                //显示顶点
                EditVertexClass.ShowAllVertex(pFeaturelayer);
                m_activeView.Refresh();
            }
            catch (Exception ex)
            {
                m_activeView.Refresh();
            }
        }
Example #4
0
        //鼠标移动
        private void MainMapControl_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
        {
            sMapUnits = GetMapUnit(mainMapControl.Map.MapUnits);
            mainform.toolStripStatusLabel1.Text = String.Format("当前坐标:X = {0:#.###} Y = {1:#.###} {2}", e.mapX, e.mapY, sMapUnits);
            try
            {
                frmMeasureResult.label2.Text = String.Format("当前坐标:X = {0:#.###} Y = {1:#.###} {2}", e.mapX, e.mapY, sMapUnits);
            }
            catch
            {
                ;
            }

            pMovePt = (mainMapControl.Map as IActiveView).ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);

            if (pMouseOperate == "MeasureLength")
            {
                if (pNewLineFeedback != null)
                {
                    pNewLineFeedback.MoveTo(pMovePt);
                }
                double deltaX = 0; //两点之间X差值
                double deltaY = 0; //两点之间Y差值

                if ((pPointPt != null) && (pNewLineFeedback != null))
                {
                    deltaX         = pMovePt.X - pPointPt.X;
                    deltaY         = pMovePt.Y - pPointPt.Y;
                    dSegmentLength = Math.Round(Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY)), 3);
                    dToltalLength  = dToltalLength + dSegmentLength;
                    if (frmMeasureResult != null)
                    {
                        frmMeasureResult.label2.Text = String.Format(
                            "当前线段长度:{0:.###}{1};\r\n总长度为: {2:.###}{1}",
                            dSegmentLength, sMapUnits, dToltalLength);
                        dToltalLength = dToltalLength - dSegmentLength; //鼠标移动到新点重新开始计算
                    }
                    frmMeasureResult.frmClosed += new FormMeasureResult.FormClosedEventHandler(frmMeasureResult_frmColsed);
                }
            }
            if (pMouseOperate == "MeasureArea")
            {
                if (pNewPolygonFeedback != null)
                {
                    pNewPolygonFeedback.MoveTo(pMovePt);
                }

                IPointCollection pPointCol = new Polygon();
                IPolygon         pPolygon  = new PolygonClass();
                IGeometry        pGeo      = null;

                ITopologicalOperator pTopo = null;
                for (int i = 0; i <= pAreaPointCol.PointCount - 1; i++)
                {
                    pPointCol.AddPoint(pAreaPointCol.get_Point(i), ref missing, ref missing);
                }
                pPointCol.AddPoint(pMovePt, ref missing, ref missing);

                if (pPointCol.PointCount < 3)
                {
                    return;
                }
                pPolygon = pPointCol as IPolygon;

                if ((pPolygon != null))
                {
                    pPolygon.Close();
                    pGeo  = pPolygon as IGeometry;
                    pTopo = pGeo as ITopologicalOperator;
                    //使几何图形的拓扑正确
                    pTopo.Simplify();
                    pGeo.Project(mainMapControl.Map.SpatialReference);
                    IArea pArea = pGeo as IArea;

                    frmMeasureResult.label2.Text = String.Format("总面积为:{0:.####}平方{1};\r\n总长度为:{2:.####}{1}", pArea.Area, sMapUnits, pPolygon.Length);
                    pPolygon = null;
                }
            }
        }
Example #5
0
        /// <summary>
        /// 将指定的多义线,按某一方向,一定的距离偏移出新的多义线(右手规则)
        /// </summary>
        /// <param name="pBaseLine">指定的多义线</param>
        /// <param name="bOrient">偏移方向(可以使用IHitTest取出方向)</param>
        /// <param name="dOffset">偏移距离</param>
        /// <returns>偏移出的多义线</returns>
        public static IPolyline Offset(IPolyline pBaseLine, bool bOrient, double dOffset)
        {
            // bOrient 以第一点到第二点右边为正方向
            // dOffset 以bOrient方向作出的偏移
            // 1.或取偏移的第一个点
            IPointCollection ptColl      = (IPointCollection)pBaseLine;
            IPoint           pt0         = ptColl.get_Point(0);
            IPoint           pt1         = ptColl.get_Point(1);
            IPoint           pt2         = null;
            IPolyline        pOffsetLine = new PolylineClass();
            IPointCollection pOffsetColl = (IPointCollection)pOffsetLine;
            IPoint           pTemp       = GetOffsetPoint(pt0, pt1, dOffset, bOrient);
            object           o           = Type.Missing;

            pOffsetColl.AddPoint(pTemp, ref o, ref o);

            double seta, seta1, b, b1;

            for (int i = 1; i < ptColl.PointCount - 1; ++i)
            {
                pt0 = ptColl.get_Point(i - 1);
                pt1 = ptColl.get_Point(i);
                pt2 = ptColl.get_Point(i + 1);

                IPoint pTemp1 = GetOffsetPoint(pt1, pt2, dOffset, bOrient);
                if (pTemp1 == null)
                {
                    continue;
                }

                // 内积为 0,三点共线
                if ((pt2.X - pt0.X) * (pt1.Y - pt0.Y) - (pt1.X - pt0.X) * (pt2.Y - pt0.Y) == 0)
                {
                    o = Type.Missing;
                    pOffsetColl.AddPoint(pTemp1, ref o, ref o);
                    continue;
                }
                else
                {
                    double base1 = pt1.X - pt0.X;
                    double base2 = pt2.X - pt1.X;
                    if (base1 != 0 && base2 != 0)
                    {
                        seta    = (pt1.Y - pt0.Y) / base1;
                        b       = pTemp.Y - seta * pTemp.X;
                        seta1   = (pt2.Y - pt1.Y) / base2;
                        b1      = pTemp1.Y - seta1 * pTemp1.X;
                        pTemp.X = (b - b1) / (seta1 - seta);
                        pTemp.Y = seta * pTemp.X + b;
                        o       = Type.Missing;
                        pOffsetColl.AddPoint(pTemp, ref o, ref o);
                    }
                    else if (base1 != 0 && base2 == 0)
                    {
                        seta    = (pt1.Y - pt0.Y) / base1;
                        b       = pTemp.Y - seta * pTemp.X;
                        pTemp.X = pTemp1.X;
                        pTemp.Y = pTemp.X * seta + b;
                        o       = Type.Missing;
                        pOffsetColl.AddPoint(pTemp, ref o, ref o);
                    }
                    else if (base1 == 0 && base2 != 0)
                    {
                        seta1   = (pt2.Y - pt1.Y) / base2;
                        b1      = pTemp1.Y - seta1 * pTemp1.X;
                        pTemp.X = pTemp1.X;
                        pTemp.Y = pTemp.X * seta1 + b1;
                        o       = Type.Missing;
                        pOffsetColl.AddPoint(pTemp, ref o, ref o);
                    }
                    else
                    {
                        throw new Exception("error");
                    }
                }
            }
            pt0 = ptColl.get_Point(ptColl.PointCount - 2);
            pt1 = ptColl.get_Point(ptColl.PointCount - 1);
            pt2 = pOffsetColl.get_Point(pOffsetColl.PointCount - 1);
            // 矢量和
            double dx0 = pt2.X - pt0.X;
            double dy0 = pt2.Y - pt0.Y;
            double dx1 = pt1.X - pt0.X;
            double dy1 = pt1.Y - pt0.Y;

            pTemp.X = dx0 + dx1 + pt0.X;
            pTemp.Y = dy0 + dy1 + pt0.Y;
            o       = Type.Missing;
            pOffsetColl.AddPoint(pTemp, ref o, ref o);
            return((IPolyline)pOffsetColl);
        }
Example #6
0
        private GPoints CalculateIntersections(IPolyline baseline, IFeature pFeature, IBasicLayerInfo lineConfig)
        {
            IPointCollection pointCollection = (IPointCollection)baseline;
            int     pointCount = pointCollection.PointCount;
            GPoints result;

            if (pointCount == 0)
            {
                result = null;
            }
            else
            {
                GPolyLine gPolyLine = new GPolyLine();
                gPolyLine.Clear();
                for (int i = 0; i < pointCount; i++)
                {
                    IPoint point = pointCollection.get_Point(i);
                    double x     = point.X;
                    double y     = point.Y;
                    double z     = point.Z - point.M;
                    double z2    = point.Z;
                    gPolyLine.PushBack(new GPoint
                    {
                        X = x,
                        Y = y,
                        Z = z,
                        M = z2
                    });
                }
                pointCollection = (IPointCollection)pFeature.Shape;
                pointCount      = pointCollection.PointCount;
                if (pointCount == 0)
                {
                    result = null;
                }
                else
                {
                    GPolyLine gPolyLine2 = new GPolyLine();
                    gPolyLine2.Clear();

                    int qdgcIndex =
                        pFeature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.QDGC));
                    int qdmsIndex =
                        pFeature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.QDMS));
                    int zdgcIndex =
                        pFeature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.ZDGC));
                    int zdmsIndex =
                        pFeature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.ZDMS));
                    double height = 0;
                    double qdgc   = GetDoubleValue(pFeature, qdgcIndex, out height);
                    double zdgc   = GetDoubleValue(pFeature, zdgcIndex, out height);
                    double qdms   = GetDoubleValue(pFeature, qdmsIndex, out height);
                    double zdms   = GetDoubleValue(pFeature, zdmsIndex, out height);
                    if (qdms == 0)
                    {
                        qdms = 1;
                    }
                    if (zdms == 0)
                    {
                        zdms = 1;
                    }
                    IPoint startPoint = pointCollection.Point[0];
                    IPoint endPoint   = pointCollection.Point[pointCollection.PointCount - 1];

                    gPolyLine2.PushBack(new GPoint
                    {
                        X = startPoint.X,
                        Y = startPoint.Y,
                        Z = qdgc - qdms,
                        M = qdgc
                    });
                    gPolyLine2.PushBack(new GPoint
                    {
                        X = endPoint.X,
                        Y = endPoint.Y,
                        Z = zdgc - zdms,
                        M = zdgc
                    });

                    //for (int j = 0; j < pointCount; j++)
                    //{
                    //    IPoint point2 = pointCollection.get_Point(j);
                    //    double x2 = point2.X;
                    //    double y2 = point2.Y;
                    //    double z3 = point2.Z - point2.M;
                    //    double m;
                    //    if (double.IsNaN(point2.M))
                    //    {
                    //        m = 1.0 + point2.Z;
                    //    }
                    //    else
                    //    {
                    //        m = point2.Z;
                    //    }
                    //    gPolyLine2.PushBack(new GPoint
                    //    {
                    //        X = x2,
                    //        Y = y2,
                    //        Z = z3,
                    //        M = m
                    //    });
                    //}
                    //new GPoints();
                    result = gPolyLine.GetInterPtsToPolyLineWithHeightForTransect(gPolyLine2);
                }
            }
            return(result);
        }
Example #7
0
		/// <summary>
		/// 获取VCT线实体节点
		/// </summary>
		public override EntityNode GetEntityNode()
        {
            try
            {
                LineNode pLineNode = new LineNode();
                pLineNode.SegmentNodes = new SegmentNodes();

                IFeature pFeature = this.Feature as IFeature;

                //特征类型统一设置为1
                pLineNode.LineType = 1;

                ///标识码赋值
                int dBSMIndex = -1;
                dBSMIndex = this.Feature.Fields.FindField(m_strEntityIDFiled);
                if (dBSMIndex != -1)
                    pLineNode.EntityID = Convert.ToInt32(this.Feature.get_Value(dBSMIndex));
                
                ///要素代码赋值
                //int dSYDMIndex = -1;
                //dSYDMIndex = this.Feature.Fields.FindField(m_strYSDMField);
                //if (dSYDMIndex != -1)
                //    pLineNode.FeatureCode = this.Feature.get_Value(dSYDMIndex).ToString();
                //string sAttriTableName = (pFeature.Class as IDataset).Name;
                //pLineNode.FeatureCode = MetaDataFile.GetFeatureCodeByName(sAttriTableName);
                pLineNode.FeatureCode = this.FeatureCode;

                ///图形表现编码
                //pLineNode.Representation = pFeature.Class.AliasName;
                ///add by 曾平 2011-9-7 添加裁切
                IGeometry pFeatureGeometry = null;
                if (m_bCut)
                {
                    pFeatureGeometry = GetSubGeometry();
                    if (pFeatureGeometry == null)
                    {
                        pFeatureGeometry = pFeature.Shape;
                    }
                }
                else
                {
                    pFeatureGeometry = pFeature.Shape;
                }

                IPolyline pPolygon =pFeatureGeometry as IPolyline;
                ///构造节点数据
                IPointCollection pPointCollection = pPolygon as IPointCollection;
                BrokenLineNode pBLineNode = new BrokenLineNode();
                pBLineNode.PointInfoNodes = new PointInfoNodes();
                for (int i = 0; i < pPointCollection.PointCount; i++)
                {
                    
                    IPoint pPoint = pPointCollection.get_Point(i);
                    PointInfoNode pInfoNode1 = new PointInfoNode(pPoint.X, pPoint.Y);
                    pBLineNode.PointInfoNodes.Add(pInfoNode1);
                   
                } 

                pLineNode.SegmentNodes.Add(pBLineNode);
                return pLineNode;
            }
            catch (Exception ex)
            {
                LogAPI.WriteErrorLog(ex);
                return null;
            }
		}
 private void createpolyline(IPointCollection ippoints)
 {
     ISegmentCollection ppath = new PathClass();
     IGeometryCollection ppolyline = new PolylineClass();
     if (ippoints.PointCount >= 2)
     {
         int i;
         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;
             object o = Type.Missing;
             ppath.AddSegment(psegment, ref o, ref o);
             ppolyline.AddGeometry(ppath as IGeometry, ref o, ref o);
         }
         ipPolyResult = ppolyline as IPolyline;
     }
 }
Example #9
0
        public void RefreshBaseLineGrid()
        {
            if (this.m_commonDistAls.m_pBaseLine == null)
            {
                this.dataGridViewBase.Rows.Clear();
                return;
            }
            IPointCollection mPBaseLine = (IPointCollection)this.m_commonDistAls.m_pBaseLine;
            IFeature         pFeature   = null;
            int qdgcIdx = -1;
            int qdmsIdx = -1;
            int zdgcIdx = -1;
            int zdmsIdx = -1;

            if (cmbDepthType.SelectedIndex == 0)
            {
                pFeature = this.chitAnalyse_0.PipeLayer_Class.GetFeature(this.chitAnalyse_0.BaseLine_OID);
                qdgcIdx  = pFeature.Fields.FindField(_baseLayerInfo.GetFieldName(PipeConfigWordHelper.LineWords.QDGC));
                qdmsIdx  = pFeature.Fields.FindField(_baseLayerInfo.GetFieldName(PipeConfigWordHelper.LineWords.QDMS));
                zdgcIdx  = pFeature.Fields.FindField(_baseLayerInfo.GetFieldName(PipeConfigWordHelper.LineWords.ZDGC));
                zdmsIdx  = pFeature.Fields.FindField(_baseLayerInfo.GetFieldName(PipeConfigWordHelper.LineWords.ZDMS));
            }
            int pointCount = mPBaseLine.PointCount;

            if (pointCount != 0)
            {
                this.dataGridViewBase.Rows.Clear();
                for (int i = 0; i < pointCount; i++)
                {
                    IPoint point = mPBaseLine.get_Point(i);
                    double x     = point.X;
                    double y     = point.Y;
                    double z     = 0;

                    if (cmbDepthType.SelectedIndex == 0)
                    {
                        if (i == 0)
                        {
                            double z1 = Convert.ToDouble(pFeature.Value[qdgcIdx]);
                            double z2 = Convert.ToDouble(pFeature.Value[qdmsIdx]);
                            z = z1 - z2;
                        }
                        else if (i == pointCount - 1)
                        {
                            double z1 = Convert.ToDouble(pFeature.Value[zdgcIdx]);
                            double z2 = Convert.ToDouble(pFeature.Value[zdmsIdx]);
                            z = z1 - z2;
                        }
                    }
                    else
                    {
                        z = point.Z - point.M;
                    }
                    this.dataGridViewBase.Rows.Add(new object[] { "" });
                    this.dataGridViewBase[0, i].Value = i + 1;
                    this.dataGridViewBase[1, i].Value = x.ToString("f3");
                    this.dataGridViewBase[2, i].Value = y.ToString("f3");
                    this.dataGridViewBase[3, i].Value = z.ToString("f3");
                    if (this.hitAnalyseType_0 == HitAnalyseDlg.HitAnalyseType.emHitAnalyseDraw)
                    {
                        this.dataGridViewBase[3, i].Value = "0.000";
                    }
                }
            }
        }
Example #10
0
        private bool slovePath()
        {
            try
            {
                double costLength = 0;
                m_ipPointToEID                  = new PointToEIDClass();
                m_ipPointToEID.SourceMap        = m_HookHelper.ActiveView.FocusMap;
                m_ipPointToEID.GeometricNetwork = m_ipGeometricNetwork;
                m_ipPointToEID.SnapTolerance    = m_HookHelper.ActiveView.Extent.Envelope.Width / 100;


                INetwork ipNetwork;

                INetElements ipNetElements;
                INetFlag     ipNetFlag;

                //IEdgeFlag ipEdgeFlag;

                IEdgeFlag [] EdgeFlagArray;

                int    pEdgeID;
                IPoint pLocation;
                double dblEdgePercent;
                int    iUserClassID, iUserID, iUserSubID;

                // look up the EID for the current point  (this will populate intEdgeID and dblEdgePercent)

                ipTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolver;

                //get the inetsolver interface
                ipNetSolver = ipTraceFlowSolver as INetSolver;

                ipNetwork = m_ipGeometricNetwork.Network;

                //set the net solver's source network
                ipNetSolver.SourceNetwork = ipNetwork;

                //make edge flags from the points
                //the INetElements interface is needed to get UserID, UserClassID,
                //and UserSubID from an element id

                EdgeFlagArray = new IEdgeFlag[mPointArray.PointCount];
                ipNetElements = ipNetwork as INetElements;


                for (int ii = 0; ii < mPointArray.PointCount; ii++)
                {
                    ipNetFlag = new EdgeFlagClass();

                    point = mPointArray.get_Point(ii);



                    m_ipPointToEID.GetNearestEdge(point, out pEdgeID, out pLocation, out dblEdgePercent);

                    //iUserClassID是featureclass ID,userID是objectID,userSubID
                    ipNetElements.QueryIDs(pEdgeID, esriElementType.esriETEdge, out iUserClassID, out iUserID, out iUserSubID);

                    ipNetFlag.UserClassID = iUserClassID;

                    ipNetFlag.UserID = iUserID;

                    ipNetFlag.UserSubID = iUserSubID;

                    EdgeFlagArray[ii] = ipNetFlag as IEdgeFlag;

                    //MessageBox.Show(iUserID.ToString());
                }

                //添加到TraceFlowSolver中
                ITraceFlowSolverGEN pTFSolverGEN = ipTraceFlowSolver as ITraceFlowSolverGEN;
                pTFSolverGEN.PutEdgeOrigins(ref EdgeFlagArray);



                //get the INetSchema interface
                INetSchema ipNetSchema = ipNetwork as INetSchema;

                INetWeight ipNetWeight = ipNetSchema.get_Weight(0);

                //MessageBox.Show(ipNetWeight.WeightName);

                INetSolverWeights ipNetSolverWeights = ipTraceFlowSolver as INetSolverWeights;

                //来回使用同一个权重



                ipNetSolverWeights.FromToEdgeWeight = ipNetWeight;

                ipNetSolverWeights.ToFromEdgeWeight = ipNetWeight;



                object [] totalCost = new object[mPointArray.PointCount - 1];



                pTFSolverGEN.FindPath(esriFlowMethod.esriFMConnected,
                                      esriShortestPathObjFn.esriSPObjFnMinSum,
                                      out m_ipEnumNetEID_Junctions,
                                      out m_ipEnumNetEID_Edges,
                                      mPointArray.PointCount - 1, ref totalCost);
                //MessageBox.Show(totalCost[0].ToString());



                for (int ii = 0; ii < totalCost.Length; ii++)
                {
                    costLength += (double)(totalCost[ii]);
                }
                pStatusBar.Panels[0].Text = "水管长度:" + costLength.ToString();
                return(true);
            }
            catch (Exception e) {
                MessageBox.Show(e.Message);
                return(false);
            }
        }
Example #11
0
        private void DoCrossAnalysis(Dictionary <string, List <IFeature> > dict, int crosstype)
        {
            if (dict.Count == 0)
            {
                return;
            }
            if (_hsCross == null)
            {
                return;
            }
            List <string> mcChecked = new List <string>();
            Dictionary <string, string> sameCross = new Dictionary <string, string>();

            try
            {
                foreach (MajorClass mca in LogicDataStructureManage2D.Instance.GetAllMajorClass())
                {
                    if (!dict.ContainsKey(mca.Alias))
                    {
                        continue;
                    }
                    List <IFeature> linesA = dict[mca.Alias];
                    foreach (MajorClass mcb in LogicDataStructureManage2D.Instance.GetAllMajorClass())
                    {
                        if (IsMcChecked(mcChecked, mcb.Name))
                        {
                            continue;
                        }
                        if (!dict.ContainsKey(mcb.Alias))
                        {
                            continue;
                        }
                        List <IFeature> linesB = dict[mcb.Alias];
                        int             count  = 0;
                        int             n      = 0;
                        string          hint;
                        foreach (IFeature la in linesA)
                        {
                            count++;
                            hint = "正在分析【" + mca.Alias + "】与【" + mcb.Alias + "】," + count + "/" + linesA.Count;
                            WaitForm.SetCaption(hint, "请稍后");
                            double    dA    = GetDiameter(la, this._diameter);
                            IPolyline lineA = la.Shape as IPolyline;
                            foreach (IFeature lb in linesB)
                            {
                                if (la == lb)
                                {
                                    continue;
                                }
                                double    dB    = GetDiameter(lb, this._diameter);
                                IPolyline lineB = lb.Shape as IPolyline;
                                //ITopologicalOperator topo = lineA as ITopologicalOperator;
                                ITopologicalOperator topo = lineA as ITopologicalOperator;
                                topo.Simplify();
                                IGeometry geo = topo.Intersect(lineB, esriGeometryDimension.esriGeometry0Dimension);
                                if (geo.IsEmpty)
                                {
                                    continue;
                                }
                                IPointCollection pc    = geo as IPointCollection;
                                IPoint           point = pc.get_Point(0);
                                //if (point == lineA.FromPoint || point == lineA.ToPoint || point == lineB.FromPoint || point == lineB.ToPoint)
                                if (IsPointSame(point, lineA.FromPoint) || IsPointSame(point, lineA.ToPoint) || IsPointSame(point, lineB.FromPoint) || IsPointSame(point, lineB.ToPoint))
                                {
                                    continue;
                                }
                                string hlbA = GetHLB(la);
                                string hlbB = GetHLB(lb);
                                double disA = double.MaxValue;
                                double zA   = double.MaxValue;//A管中心线高
                                GetDistanceAndZ(lineA, point, dA, hlbA, out disA, out zA);
                                double disB = double.MaxValue;
                                double zB   = double.MaxValue;//B管中心线高
                                GetDistanceAndZ(lineB, point, dB, hlbB, out disB, out zB);

                                double l = Double.MaxValue;
                                if (_crosstype == 0)
                                {
                                    l = (dA + dB) / 2000;
                                    //if (zA > zB)
                                    //{
                                    //    if (IsTopOrBottom(hlbA) && IsTopOrBottom(hlbB))
                                    //    {
                                    //        l = dA / 1000 ;
                                    //    }
                                    //    else if (IsTopOrBottom(hlbA) && !IsTopOrBottom(hlbB))
                                    //    {
                                    //        l = (dA + dB) / 1000 ;
                                    //    }
                                    //    else
                                    //    {
                                    //        l = dB / 1000 ;
                                    //    }
                                    //}
                                    //else if (zA < zB)
                                    //{
                                    //    if (IsTopOrBottom(hlbB) && IsTopOrBottom(hlbA))
                                    //    {
                                    //        l = dB / 1000 ;
                                    //    }
                                    //    else if (IsTopOrBottom(hlbB) && !IsTopOrBottom(hlbA))
                                    //    {
                                    //        l = (dB + dA) / 1000 ;
                                    //    }
                                    //    else
                                    //    {
                                    //        l = dA / 1000 ;
                                    //    }
                                    //}
                                }
                                else
                                {
                                    if (dictVertical.ContainsKey(mca.Name + "_" + mcb.Name))
                                    {
                                        l = (dA + dB) / 2000 + dictVertical[mca.Name + "_" + mcb.Name];
                                        //if (zA > zB)
                                        //{
                                        //    if (IsTopOrBottom(hlbA) && IsTopOrBottom(hlbB))
                                        //    {
                                        //        l = dA / 1000 + dictVertical[mca.Name + "_" + mcb.Name];
                                        //    }
                                        //    else if (IsTopOrBottom(hlbA) && !IsTopOrBottom(hlbB))
                                        //    {
                                        //        l = (dA + dB) / 1000 + dictVertical[mca.Name + "_" + mcb.Name];
                                        //    }
                                        //    else
                                        //    {
                                        //        l =dB / 1000 + dictVertical[mca.Name + "_" + mcb.Name];
                                        //    }
                                        //}
                                        //else if (zA < zB)
                                        //{
                                        //    if (IsTopOrBottom(hlbB) && IsTopOrBottom(hlbA))
                                        //    {
                                        //        l = dB / 1000 + dictVertical[mca.Name + "_" + mcb.Name];
                                        //    }
                                        //    else if (IsTopOrBottom(hlbB) && !IsTopOrBottom(hlbA))
                                        //    {
                                        //        l = (dB + dA) / 1000 + dictVertical[mca.Name + "_" + mcb.Name];
                                        //    }
                                        //    else
                                        //    {
                                        //        l = dA / 1000 + dictVertical[mca.Name + "_" + mcb.Name];
                                        //    }
                                        //}
                                    }


                                    //l = (((double)dA + (double)dB) / 2000) + dictVertical[mca.Name + "_" + mcb.Name];
                                }
                                if (l == Double.MaxValue)
                                {
                                    continue;
                                }
                                double deltaH = System.Math.Abs(zA - zB);
                                if (deltaH > l)
                                {
                                    continue;
                                }
                                else
                                {
                                    string idA = mca.Name + "_" + la.OID;
                                    string idB = mcb.Name + "_" + lb.OID;
                                    if (mca.Alias == mcb.Alias)                       //如果是同类型管线分析碰撞
                                    {
                                        sameCross[idA + "," + idB] = idA + "," + idB; //将管线碰撞ID对添加到字典
                                        if (!sameCross.ContainsKey(idB + "," + idA))  //如果字典中查不到该id对(相同的id对,顺序相反)
                                        {
                                            _hsCross.Add(idA + "," + idB);            //将该碰撞管线对添加到碰撞列表
                                        }
                                    }
                                    else
                                    {
                                        _hsCross.Add(idA + "," + idB);
                                    }
                                    if (_hsTxt != null)
                                    {
                                        if (mca.Alias == mcb.Alias)
                                        {
                                            sameCross[idA + "," + idB] = idA + "," + idB;
                                            if (!sameCross.ContainsKey(idB + "," + idA))
                                            {
                                                _hsTxt.Add(idA + "," + idB + "," + point.X.ToString() + "," + point.Y.ToString() + "," + zA.ToString() + "," + zB.ToString() + "," + System.Math.Abs(deltaH - l).ToString());
                                            }
                                        }
                                        else
                                        {
                                            _hsTxt.Add(idA + "," + idB + "," + point.X.ToString() + "," + point.Y.ToString() + "," + zA.ToString() + "," + zB.ToString() + "," + System.Math.Abs(deltaH - l).ToString());
                                        }
                                    }
                                    //if (_dicCross.ContainsValue(idA) && _dicCross.ContainsKey(idB))
                                    //{
                                    //    if (_dicCross[idB] == idA) continue;

                                    //}
                                    //else
                                    //{
                                    //    if (_dicCross.ContainsKey(idA)) continue;
                                    //    _dicCross[idA] = idB;
                                    //    n++;

                                    //}
                                }
                            }
                        }
                    }
                    mcChecked.Add(mca.Name);
                }
            }
            catch (System.Exception ex)
            {
                return;
            }
        }
Example #12
0
        private static bool IsStartOrEnd(IPoint pt, IPointCollection pc)
        {
            var pt2 = pc.get_Point(pc.PointCount - 1);
            var pt1 = pc.get_Point(0);

            if (Math.Abs(pt.X - pt1.X) < 1e-8 && Math.Abs(pt.Y - pt1.Y) < 1e-8) return true;
            if (Math.Abs(pt.X - pt2.X) < 1e-8 && Math.Abs(pt.Y - pt2.Y) < 1e-8) return true;
            return false;
        }
Example #13
0
        /// <summary>
        ///  ��ȡͼ��������
        /// </summary>
        /// <param name="ipPointCollection">����㼯��</param>
        /// <param name="ipTuFuEnvelope">ͼ����������</param>
        /// <returns></returns>
        private IArray GetTuFuGriddingLine(IPointCollection ipPointCollection, IEnvelope ipTuFuEnvelope)
        {
            try
            {
                IArray aryGriddingLine = new ArrayClass();
                double dMinX = 0.0;
                double dMaxX = 0.0;
                double dMinY = 0.0;
                double dMaxY = 0.0;

                dMinX = ipTuFuEnvelope.XMin;
                dMaxX = ipTuFuEnvelope.XMax;
                dMinY = ipTuFuEnvelope.YMin;
                dMaxY = ipTuFuEnvelope.YMax;

                int nPointCount = ipPointCollection.PointCount;

                IPoint ipPoint1 = null;
                IPoint ipPoint2 = null;

                double dX1 = 0.0;
                double dY1 = 0.0;
                double dX2 = 0.0;
                double dY2 = 0.0;

                double dHeight = (dMaxY - dMinY)/1000;
                double dWidth = (dMaxX - dMinX)/1000;
                double dTempTol = dHeight > dWidth ? dWidth : dHeight;

                List<int> aryVerticalIndex = new List<int>(); //CArray<long,long> aryVerticalIndex;//���д�ֱ�����ߵ��������
                List<int> aryHorizontal = new List<int>(); //CArray<long,long> aryHorizontal;//����ˮƽ�����ߵ��������

                int nVerCount = 0;
                int nHorCount = 0;
                int i, j;

                //����߿��ϵĵ�,�м�ĵ�ȥ��
                for (i = 0; i < nPointCount;)
                {
                    ipPoint1 = ipPointCollection.get_Point(i);
                    if (!PointBIsOverBoundary(ipPoint1, ipTuFuEnvelope, dTempTol))
                    {
                        ipPointCollection.RemovePoints(i, 1);
                        nPointCount--;
                    }
                    else
                    {
                        i++;
                    }
                }

                nPointCount = ipPointCollection.PointCount;
                for (i = 0; i < nPointCount; i++)
                {
                    ipPoint1 = ipPointCollection.get_Point(i);

                    dX1 = ipPoint1.X;
                    dY1 = ipPoint1.Y;

                    nVerCount = aryVerticalIndex.Count;
                    if (nVerCount == 0 && Math.Abs(dY1 - dMinY) < dTempTol
                        && Math.Abs(dX1 - dMinX) > dTempTol
                        && Math.Abs(dX1 - dMaxX) > dTempTol)
                    {
                        nVerCount++;
                        aryVerticalIndex.Add(i);
                    }

                    nHorCount = aryHorizontal.Count;
                    if (nHorCount == 0 && Math.Abs(dX1 - dMinX) < dTempTol
                        && Math.Abs(dY1 - dMinY) > dTempTol
                        && Math.Abs(dY1 - dMaxY) > dTempTol)
                    {
                        nHorCount++;
                        aryHorizontal.Add(i);
                    }

                    for (j = 0; j < nVerCount; j++)
                    {
                        ipPoint2 = ipPointCollection.get_Point(aryVerticalIndex[j]);
                        dX2 = ipPoint2.X;
                        dY2 = ipPoint2.Y;

                        if (Math.Abs(dX1 - dX2) < dTempTol && Math.Abs(dY1 - dY2) < dTempTol)
                        {
                            break;
                        }
                    }

                    if (j >= nVerCount)
                    {
                        //ȡ�ײ�ȥ����������ĵ�Ϊ���
                        if (Math.Abs(dY1 - dMinY) < dTempTol
                            && Math.Abs(dX1 - dMinX) > dTempTol
                            && Math.Abs(dX1 - dMaxX) > dTempTol)
                        {
                            aryVerticalIndex.Add(i);
                        }
                    }

                    for (j = 0; j < nHorCount; j++)
                    {
                        ipPoint2 = ipPointCollection.get_Point(aryHorizontal[j]);
                        dX2 = ipPoint2.X;
                        dY2 = ipPoint2.Y;
                        if (Math.Abs(dX1 - dX2) < dTempTol && Math.Abs(dY1 - dY2) < dTempTol)
                        {
                            break;
                        }
                    }

                    if (j >= nHorCount)
                    {
                        //ȡ���ȥ����������ĵ�Ϊ���
                        if (Math.Abs(dX1 - dMinX) < dTempTol
                            && Math.Abs(dY1 - dMinY) > dTempTol
                            && Math.Abs(dY1 - dMaxY) > dTempTol)
                        {
                            aryHorizontal.Add(i);
                        }
                    }
                }

                nPointCount = ipPointCollection.PointCount;

                //��֯��ֱ������
                nVerCount = aryVerticalIndex.Count;
                for (i = 0; i < nVerCount; i++)
                {
                    ipPoint1 = ipPointCollection.get_Point(aryVerticalIndex[i]);
                    dX1 = ipPoint1.X;
                    dY1 = ipPoint1.Y;

                    //������
                    IPolyline ipPolyline = new PolylineClass();
                    ipPolyline.FromPoint = ipPoint1;

                    for (j = 0; j < nPointCount; j++)
                    {
                        ipPoint2 = ipPointCollection.get_Point(j);
                        dX2 = ipPoint2.X;
                        dY2 = ipPoint2.Y;
                        if (Math.Abs(dX1 - dX2) < dTempTol && Math.Abs(dY1 - dY2) > dTempTol)
                        {
                            //����յ�
                            ipPolyline.ToPoint = ipPoint2;
                            break;
                        }
                    }
                    aryGriddingLine.Add(ipPolyline);
                }

                //��֯ˮƽ������
                nHorCount = aryHorizontal.Count;
                for (i = 0; i < nHorCount; i++)
                {
                    ipPoint1 = ipPointCollection.get_Point(aryHorizontal[i]);
                    dX1 = ipPoint1.X;
                    dY1 = ipPoint1.Y;

                    //������
                    IPolyline ipPolyline = new PolylineClass();
                    ipPolyline.FromPoint = ipPoint1;

                    for (j = 0; j < nPointCount; j++)
                    {
                        ipPoint2 = ipPointCollection.get_Point(j);
                        dX2 = ipPoint2.X;
                        dY2 = ipPoint2.Y;
                        if (Math.Abs(dY1 - dY2) < dTempTol && Math.Abs(dX1 - dX2) > dTempTol)
                        {
                            //����յ�
                            ipPolyline.ToPoint = ipPoint2;
                            break;
                        }
                    }
                    aryGriddingLine.Add(ipPolyline);
                }
                return aryGriddingLine;
            }
            catch (Exception ex)
            {
                SendMessage(enumMessageType.Exception, ex.ToString());
                return null;
            }
        }
Example #14
0
        ////几何网络
        //private IGeometricNetwork mGeometricNetwork;
        ////给定点的集合
        //private IPointCollection mPointCollection;
        ////获取给定点最近的Network元素
        //private IPointToEID mPointToEID;

        ////返回结果变量
        //private IEnumNetEID mEnumNetEID_Junctions;
        //private IEnumNetEID mEnumNetEID_Edges;
        //private double mdblPathCost;



        /// <summary>
        /// 实现路径分析
        /// </summary>
        /// <param name="weightName">路径权重字段</param>
        public void SolvePath(string weightName, IGeometricNetwork mGeometricNetwork, IPointCollection mPointCollection, IPointToEID mPointToEID, out IEnumNetEID mEnumNetEID_Junctions, out IEnumNetEID mEnumNetEID_Edges, out double mdblPathCost)
        {
            //创建ITraceFlowSolverGEN
            ITraceFlowSolverGEN pTraceFlowSolverGEN = new TraceFlowSolverClass();
            INetSolver          pNetSolver          = pTraceFlowSolverGEN as INetSolver;
            //初始化用于路径计算的Network
            INetwork pNetWork = mGeometricNetwork.Network;

            pNetSolver.SourceNetwork = pNetWork;

            //获取分析经过的点的个数
            int intCount = mPointCollection.PointCount;

            if (intCount < 1)
            {
                MessageBox.Show("未获取到车辆点或目标点!");
            }


            INetFlag pNetFlag;

            //用于存储路径计算得到的边
            IEdgeFlag[] pEdgeFlags = new IEdgeFlag[intCount];


            IPoint pEdgePoint = new PointClass();
            int    intEdgeEID;
            IPoint pFoundEdgePoint;
            double dblEdgePercent;

            //用于获取几何网络元素的UserID, UserClassID,UserSubID
            INetElements pNetElements = pNetWork as INetElements;
            int          intEdgeUserClassID;
            int          intEdgeUserID;
            int          intEdgeUserSubID;

            for (int i = 0; i < intCount; i++)
            {
                pNetFlag = new EdgeFlagClass();
                //获取用户点击点
                pEdgePoint = mPointCollection.get_Point(i);
                //获取距离用户点击点最近的边
                mPointToEID.GetNearestEdge(pEdgePoint, out intEdgeEID, out pFoundEdgePoint, out dblEdgePercent);
                if (intEdgeEID <= 0)
                {
                    continue;
                }
                //根据得到的边查询对应的几何网络中的元素UserID, UserClassID,UserSubID
                pNetElements.QueryIDs(intEdgeEID, esriElementType.esriETEdge,
                                      out intEdgeUserClassID, out intEdgeUserID, out intEdgeUserSubID);
                if (intEdgeUserClassID <= 0 || intEdgeUserID <= 0)
                {
                    continue;
                }

                pNetFlag.UserClassID = intEdgeUserClassID;
                pNetFlag.UserID      = intEdgeUserID;
                pNetFlag.UserSubID   = intEdgeUserSubID;
                pEdgeFlags[i]        = pNetFlag as IEdgeFlag;
            }
            //设置路径求解的边
            pTraceFlowSolverGEN.PutEdgeOrigins(ref pEdgeFlags);

            //路径计算权重
            INetSchema pNetSchema = pNetWork as INetSchema;
            INetWeight pNetWeight = pNetSchema.get_WeightByName(weightName);

            if (pNetWeight == null)
            {
                MessageBox.Show("权重设置有误!");
            }

            //设置权重,这里双向的权重设为一致
            INetSolverWeights pNetSolverWeights = pTraceFlowSolverGEN as INetSolverWeights;

            pNetSolverWeights.ToFromEdgeWeight = pNetWeight;
            pNetSolverWeights.FromToEdgeWeight = pNetWeight;

            object[] arrResults = new object[intCount - 1];
            //执行路径计算
            pTraceFlowSolverGEN.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum,
                                         out mEnumNetEID_Junctions, out mEnumNetEID_Edges, intCount - 1, ref arrResults);

            //获取路径计算总代价(cost)
            mdblPathCost = 0;
            for (int i = 0; i < intCount - 1; i++)
            {
                mdblPathCost += (double)arrResults[i];
            }
        }
Example #15
0
        public List <ErrorEntity> AreaSelfIntersect(string idname, IFeatureLayer pLayer)
        {
            IFeatureCursor cursor;
            IQueryFilter   filter = new QueryFilterClass();

            filter.SubFields = pLayer.FeatureClass.OIDFieldName + "," + pLayer.FeatureClass.ShapeFieldName;
            cursor           = pLayer.FeatureClass.Search(filter, true);
            IFieldEdit         edit             = pLayer.FeatureClass.Fields.get_Field(pLayer.FeatureClass.Fields.FindField(pLayer.FeatureClass.ShapeFieldName)) as IFieldEdit;
            ISpatialReference  spatialReference = edit.GeometryDef.SpatialReference;
            List <ErrorEntity> list             = new List <ErrorEntity>();
            IFeature           feature          = null;
            object             missing          = Type.Missing;

            while ((feature = cursor.NextFeature()) != null)
            {
                IPoint              tempPoint = null;
                StringBuilder       builder   = new StringBuilder();
                IGeometryCollection shape     = feature.Shape as IGeometryCollection;
                for (int i = 0; i < shape.GeometryCount; i++)
                {
                    esriNonSimpleReasonEnum enum2;
                    IPointCollection        newPoints = shape.get_Geometry(i) as IPointCollection;
                    IRing ring = newPoints as IRing;
                    int   num2 = 0;
                    if (ring.IsClosed)
                    {
                        num2 = 1;
                    }
                    PolylineClass o = new PolylineClass();
                    o.AddPointCollection(newPoints);
                    o.SpatialReference = spatialReference;

                    ITopologicalOperator3 @operator = o;
                    @operator.IsKnownSimple_2 = false;
                    if ([email protected]_IsSimpleEx(out enum2) && (enum2 == esriNonSimpleReasonEnum.esriNonSimpleSelfIntersections))
                    {
                        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);
                            tempPoint = point;
                            string item = point.X.ToString() + "," + point.Y.ToString();
                            if (list2.Contains(item))
                            {
                                if (!list3.Contains(item))
                                {
                                    builder.Append(";");
                                    builder.Append(item);
                                    list3.Add(item);
                                }
                            }
                            else
                            {
                                list2.Add(item);
                            }
                        }
                    }
                    Marshal.ReleaseComObject(o);
                    o = null;
                }
                if (builder.Length > 0)
                {
                    list.Add(new ErrorEntity(idname, feature.OID.ToString(), "自相交", builder.ToString().Substring(1), ErrType.SelfIntersect, tempPoint));
                }
            }
            return(list);
        }
        private way ConvertFeatureToOSMWay(IFeature currentFeature, IWorkspace featureWorkspace, IFeatureClass pointFeatureClass, int osmIDPointFieldIndex, int tagsFieldIndex, int osmIDFieldIndex, int changesetIDFieldIndex, int osmVersionFieldIndex, int userIDFieldIndex, int userNameFieldIndex, int timeStampFieldIndex, int visibleFieldIndex, int extensionVersion)
        {

            if (currentFeature == null)
                throw new ArgumentNullException("currentFeature");

            way osmWay = new way();
            object featureValue = DBNull.Value;

            List<nd> vertexIDs = new List<nd>();

            if (currentFeature.Shape.IsEmpty == false)
            {
                IPointCollection pointCollection = currentFeature.Shape as IPointCollection;

                if (currentFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                {
                    for (int pointIndex = 0; pointIndex < pointCollection.PointCount - 1; pointIndex++)
                    {
                        nd vertex = new nd();
                        vertex.@ref = OSMToolHelper.retrieveNodeID(pointFeatureClass, osmIDPointFieldIndex, extensionVersion, pointCollection.get_Point(pointIndex));
                        vertexIDs.Add(vertex);
                    }

                    // the last node is the first one again even though it doesn't have an internal ID
                    nd lastVertex = new nd();
                    lastVertex.@ref = OSMToolHelper.retrieveNodeID(pointFeatureClass, osmIDPointFieldIndex, extensionVersion, pointCollection.get_Point(0));
                    vertexIDs.Add(lastVertex);

                }
                else
                {
                    for (int pointIndex = 0; pointIndex < pointCollection.PointCount; pointIndex++)
                    {
                        nd vertex = new nd();
                        vertex.@ref = OSMToolHelper.retrieveNodeID(pointFeatureClass, osmIDPointFieldIndex, extensionVersion, pointCollection.get_Point(pointIndex));
                        vertexIDs.Add(vertex);
                    }
                }

                osmWay.nd = vertexIDs.ToArray();
            }

            if (osmIDFieldIndex != -1)
            {
                osmWay.id = Convert.ToString(currentFeature.get_Value(osmIDFieldIndex));
            }

            if (changesetIDFieldIndex != -1)
            {
                featureValue = currentFeature.get_Value(changesetIDFieldIndex);

                if (featureValue != DBNull.Value)
                {
                    osmWay.changeset = Convert.ToString(currentFeature.get_Value(changesetIDFieldIndex));
                }
            }

            if (osmVersionFieldIndex != -1)
            {
                featureValue = currentFeature.get_Value(osmVersionFieldIndex);

                if (featureValue != DBNull.Value)
                {
                    osmWay.version = Convert.ToString(featureValue);
                }
            }

            if (userIDFieldIndex != -1)
            {
                featureValue = currentFeature.get_Value(userIDFieldIndex);

                if (featureValue != DBNull.Value)
                {
                    osmWay.uid = Convert.ToString(featureValue);
                }
            }

            if (userNameFieldIndex != -1)
            {
                featureValue = currentFeature.get_Value(userNameFieldIndex);

                if (featureValue != DBNull.Value)
                {
                    osmWay.user = Convert.ToString(featureValue);
                }
            }

            if (timeStampFieldIndex != -1)
            {
                featureValue = currentFeature.get_Value(timeStampFieldIndex);

                if (featureValue != DBNull.Value)
                {
                    osmWay.timestamp = Convert.ToDateTime(featureValue).ToUniversalTime().ToString("u");
                }
            }

            if (visibleFieldIndex != -1)
            {
                featureValue = currentFeature.get_Value(visibleFieldIndex);

                if (featureValue != DBNull.Value)
                {
                    try
                    {
                        osmWay.visible = (wayVisible)Enum.Parse(typeof(wayVisible), Convert.ToString(featureValue));
                    }
                    catch
                    {
                        osmWay.visible = wayVisible.@true;
                    }
                }
            }

            if (tagsFieldIndex > -1)
            {
                tag[] tags = null;
                tags = _osmUtility.retrieveOSMTags((IRow)currentFeature, tagsFieldIndex, featureWorkspace);

                if (tags.Length != 0)
                {
                    osmWay.tag = tags;
                }
            }

            return osmWay;
        }
        public static void ShowAllVertex(IFeatureLayer pFeatLyr)
        {
            m_vertexGeoBag = null;
            if (pFeatLyr == null)
            {
                return;
            }
            IFeatureCursor pFeatureCursor = MapManager.GetSelectedFeatures(pFeatLyr);

            if (pFeatureCursor == null)
            {
                return;
            }
            IFeature pTFeature = null;

            //得到要显示节点的地物
            pTFeature = pFeatureCursor.NextFeature();
            if (pTFeature == null)
            {
                return;
            }
            //只选中一个地物进行节点移动
            m_Map.ClearSelection();
            m_Map.SelectFeature(pFeatLyr as ILayer, pTFeature);
            m_activeView.Refresh();
            //如果为点状地物,不显示节点
            if (pTFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
            {
                return;
            }
            IArray pFeatureArray = null;

            pFeatureArray = new ESRI.ArcGIS.esriSystem.Array();
            pFeatureArray.Add(pTFeature);
            //绘图符号初始化
            SymbolInit();
            IFeature         pFeature = default(IFeature);
            IPointCollection pPointCol = default(IPointCollection);
            IPoint           pPoint = default(IPoint);
            int i = 0; int j = 0;

            m_vertexGeoBag = new GeometryBagClass();
            for (i = 0; i <= pFeatureArray.Count - 1; i++)
            {
                pFeature = pFeatureArray.get_Element(i) as IFeature;
                //获取图形边界的点集
                pPointCol = pFeature.ShapeCopy as IPointCollection;
                for (j = 0; j <= pPointCol.PointCount - 1; j++)
                {
                    pPoint = pPointCol.get_Point(j);
                    if (j == 0 | j == pPointCol.PointCount - 1)
                    {
                        //两个端点的ID设为10
                        pPoint.ID = 10;
                    }
                    else
                    {
                        //中间点的ID设为100
                        pPoint.ID = 100;
                    }
                    IColor pColor = null;
                    object obj    = Type.Missing;
                    //显示节点
                    if (pPoint == pHitPnt)
                    {
                        DisplayGraphic(pPoint, pColor, m_selPointSym as ISymbol);
                    }
                    if (j == 0 || j == pPointCol.PointCount - 1)
                    {
                        DisplayGraphic(pPoint, pColor, m_endPointSym as ISymbol);
                    }
                    else
                    {
                        DisplayGraphic(pPoint, pColor, m_vertexSym as ISymbol);
                    }

                    m_vertexGeoBag.AddGeometry(pPoint, ref obj, ref obj);
                }
            }
            Marshal.ReleaseComObject(pFeatureCursor);
        }
        /// <summary>
        /// _pFtClass参数为Stops的要素类,_pPointC是用鼠标点的点生成的点的集合,最后一个参数是捕捉距离
        /// </summary>
        /// <param name="_pNaContext"></param>
        /// <param name="_pFtClass"></param>
        /// <param name="_pPointC"></param>
        /// <param name="_pDist"></param>
        void NASolve(INAContext _pNaContext,IFeatureClass _pFtClass, IPointCollection _pPointC, double _pDist)
        {
            INALocator pNAlocator = _pNaContext.Locator;
            for (int i = 0; i < _pPointC.PointCount; i++)
            {
                IFeature pFt = _pFtClass.CreateFeature();

                IRowSubtypes pRowSubtypes = pFt as IRowSubtypes;

                pRowSubtypes.InitDefaultValues();

                pFt.Shape = _pPointC.get_Point(i) as IGeometry;

                IPoint pPoint = null;

                 INALocation pNalocation = null;

                pNAlocator.QueryLocationByPoint(_pPointC .get_Point(i),ref pNalocation,ref pPoint,ref _pDist);

                INALocationObject pNAobject = pFt as INALocationObject;

                pNAobject.NALocation = pNalocation;

                int pNameFieldIndex = _pFtClass.FindField("Name");

                pFt.set_Value(pNameFieldIndex, pPoint.X.ToString() + "," + pPoint.Y.ToString());

                int pStatusFieldIndex = _pFtClass.FindField("Status");

                pFt.set_Value(pStatusFieldIndex, esriNAObjectStatus.esriNAObjectStatusOK);

                int pSequenceFieldIndex = _pFtClass.FindField("Sequence");

                pFt.set_Value(_pFtClass.FindField("Sequence"), ((ITable)_pFtClass).RowCount(null));

                pFt.Store();

            }
        }
        public List <Result> DepotToDest(IFeatureLayer DepotLayer, IFeatureLayer DestLayer, string pFeatureFID)
        {
            InitializationRoadNetwork(DepotLayer, DestLayer, pFeatureFID);
            IPolyline[] depotlines = new IPolyline[2];
            IPolyline[] destlines  = new IPolyline[2];
            double[]    depottime  = new double[2];
            double[]    desttime   = new double[2];

            string[] DestPointID = new string[DestPoint.PointCount];
            for (int j = 0; j < DestPoint.PointCount; j++)
            {
                string[] StartdestPoint = new string[DestPoint.PointCount];
                string[] EnddestPoint   = new string[DestPoint.PointCount];

                IFeature pDestpointFeature;
                IPoint   destPoint = DestPoint.get_Point(j);
                pDestpointFeature = GetNearestFeature(destPoint);
                StartdestPoint[j] = Convert.ToString(pDestpointFeature.get_Value(pDestpointFeature.Fields.FindField("StartNodeI")));
                EnddestPoint[j]   = Convert.ToString(pDestpointFeature.get_Value(pDestpointFeature.Fields.FindField("EndNodeID")));
                double time             = Convert.ToDouble(pDestpointFeature.get_Value(pDestpointFeature.Fields.FindField("Minutes")));
                string SpaceFeatureName = Convert.ToString(pDestpointFeature.get_Value(pDestpointFeature.Fields.FindField("Name")));



                DestPointID[j] = (NodeList.Count + 1).ToString();


                destlines   = GetSubLine(destPoint, pDestpointFeature);
                desttime[0] = time * (destlines[0].Length / (destlines[0].Length + destlines[1].Length));
                desttime[1] = time - desttime[0];

                //移除应急处置空间位置点最近的路径要素
                for (int i = 0; i < 2; i++)
                {
                    if (i == 0)
                    {
                        Edge pedge = new Edge();
                        pedge.StartNodeID = StartdestPoint[j];
                        pedge.EndNodeID   = EnddestPoint[j];
                        pedge.Weight      = time;
                        pedge.line        = pDestpointFeature.Shape as IPolyline;
                        pedge.name        = SpaceFeatureName;
                        NodeList[Convert.ToInt32(StartdestPoint[j]) - 1].EdgeList.Remove(pedge);
                    }
                    if (i == 1)
                    {
                        Edge pedge = new Edge();
                        pedge.StartNodeID = EnddestPoint[j];
                        pedge.EndNodeID   = StartdestPoint[j];
                        pedge.Weight      = time;
                        pedge.line        = pDestpointFeature.Shape as IPolyline;
                        pedge.name        = SpaceFeatureName;
                        NodeList[Convert.ToInt32(EnddestPoint[j]) - 1].EdgeList.Remove(pedge);
                    }
                }

                Node addNode = new Node((NodeList.Count + 1).ToString());
                NodeList.Add(addNode);
                //添加应急处置空间位置点最近的路径要素从起点到最近点的路径要素
                for (int k = 0; k < 2; k++)
                {
                    if (k == 0)
                    {
                        Edge pedge = new Edge();
                        pedge.StartNodeID = StartdestPoint[j];
                        pedge.EndNodeID   = NodeList.Count.ToString();
                        pedge.Weight      = desttime[0];
                        pedge.line        = destlines[0];
                        pedge.name        = SpaceFeatureName;
                        NodeList[Convert.ToInt32(StartdestPoint[j]) - 1].EdgeList.Add(pedge);
                    }
                    if (k == 1)
                    {
                        Edge pedge = new Edge();
                        pedge.StartNodeID = NodeList.Count.ToString();
                        pedge.EndNodeID   = StartdestPoint[j];
                        pedge.Weight      = desttime[0];
                        pedge.line        = destlines[0];
                        pedge.name        = SpaceFeatureName;
                        NodeList[NodeList.Count - 1].EdgeList.Add(pedge);
                    }
                }
                //添加应急处置空间位置点最近的路径要素从终点到最近点的路径要素
                for (int k = 0; k < 2; k++)
                {
                    if (k == 0)
                    {
                        Edge pedge = new Edge();
                        pedge.StartNodeID = EnddestPoint[j];
                        pedge.EndNodeID   = NodeList.Count.ToString();
                        pedge.Weight      = desttime[1];
                        pedge.line        = destlines[1];
                        pedge.name        = SpaceFeatureName;
                        NodeList[Convert.ToInt32(EnddestPoint[j]) - 1].EdgeList.Add(pedge);
                    }
                    if (k == 1)
                    {
                        Edge pedge = new Edge();
                        pedge.StartNodeID = NodeList.Count.ToString();
                        pedge.EndNodeID   = EnddestPoint[j];
                        pedge.Weight      = desttime[1];
                        pedge.line        = destlines[1];
                        pedge.name        = SpaceFeatureName;
                        NodeList[NodeList.Count - 1].EdgeList.Add(pedge);
                    }
                }
            }


            //应急资源仓库最近路段的管理
            for (int i = 0; i < DepotPoint.PointCount; i++)
            {
                FindPath(DepotNodeID[i].ToString(), DepotName[i], DestPointID);
            }
            return(ResultList);
        }
Example #20
0
        public override void GetSelectedData()
        {
            this.method_3();
            IMap map = this.m_context.FocusMap;
            ITopologicalOperator topologicalOperator = (ITopologicalOperator)this.m_pBaseLine;
            IGeometry            geometry            = topologicalOperator.Buffer(0.0);

            map.ClearSelection();
            ISelectionEnvironment selectionEnvironment = new SelectionEnvironment();

            map.SelectByShape(geometry, selectionEnvironment, false);
            IEnumFeature enumFeature = (IEnumFeature)map.FeatureSelection;
            IFeature     feature     = enumFeature.Next();

            while (feature != null)
            {
                if (feature.FeatureType == esriFeatureType.esriFTSimpleEdge)
                {
                    IPolyline egLine    = feature.Shape as IPolyline;
                    IPoint    newCenter = new PointClass();
                    egLine.QueryPoint(esriSegmentExtension.esriNoExtension, 0.01, true, newCenter);

                    IEdgeFeature pEgFeature = feature as IEdgeFeature;


                    IFeatureClass pClass        = feature.Class as IFeatureClass;
                    INetworkClass pNetworkClass = pClass as INetworkClass;
                    INetElements  network       = pNetworkClass.GeometricNetwork.Network as INetElements;
                    IPointToEID   pntEID        = new PointToEIDClass();
                    pntEID.GeometricNetwork = pNetworkClass.GeometricNetwork;
                    pntEID.SourceMap        = m_context.FocusMap;
                    pntEID.SnapTolerance    = CommonHelper.ConvertPixelsToMapUnits(m_context.ActiveView, 5.0);
                    double percent;
                    int    edgeID;
                    IPoint location;
                    pntEID.GetNearestEdge(newCenter, out edgeID, out location, out percent);
                    if (percent == 0)
                    {
                        feature = enumFeature.Next();
                        continue;
                    }

                    int userClassID, userID, userSubID;

                    network.QueryIDs(edgeID, esriElementType.esriETEdge, out userClassID, out userID, out userSubID);
                    if (pClass.FeatureClassID == userClassID)
                    {
                        feature = pClass.GetFeature(userID);
                    }
                    else
                    {
                        IEnumDataset dses = pNetworkClass.FeatureDataset.Subsets;
                        dses.Reset();
                        IDataset ds = dses.Next();
                        while (ds != null)
                        {
                            if (ds is IFeatureClass)
                            {
                                IFeatureClass pClass2 = ds as IFeatureClass;
                                if (pClass2.FeatureClassID == userClassID)
                                {
                                    feature = pClass2.GetFeature(userID);
                                    break;
                                }
                            }
                        }
                    }
                }
                string  smpClassName = CommonUtils.GetSmpClassName(feature.Class.AliasName);
                IMAware mWAware      = feature.Shape as IMAware;
                bool    isMUsing     = mWAware.MAware;

                IBasicLayerInfo lineConfig = PipeConfig.GetBasicLayerInfo(feature.Class.AliasName) as IBasicLayerInfo;
                if (lineConfig == null && !smpClassName.ToUpper().Contains("JT_JT_L") &&
                    !smpClassName.ToUpper().Contains("SY_ZX_L") && !smpClassName.ToUpper().Contains("ZB_LD_R"))
                {
                    feature = enumFeature.Next();
                }
                else
                {
                    IGeometry shape = feature.Shape;
                    if (shape.GeometryType != esriGeometryType.esriGeometryPolyline &&
                        shape.GeometryType != esriGeometryType.esriGeometryPolygon)
                    {
                        feature = enumFeature.Next();
                    }
                    else
                    {
                        IPolyline polyline;
                        if (shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                        {
                            polyline = this.PolygonToPolyline((IPolygon)shape);
                        }
                        else
                        {
                            polyline = (IPolyline)shape;
                        }
                        GPoints gPoints = null;
                        if (isMUsing)
                        {
                            gPoints = this.CalculateIntersections(this.m_pBaseLine, polyline);
                        }
                        else
                        {
                            gPoints = this.CalculateIntersections(this.m_pBaseLine, feature, lineConfig);
                        }

                        //string text = "管线性质";
                        string text            = lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.GDXZ);
                        string bstrDatasetName = "";
                        int    num             = feature.Fields.FindField(text);
                        if (num != -1)
                        {
                            object obj = feature.get_Value(num);
                            if (obj == null || Convert.IsDBNull(obj))
                            {
                                bstrDatasetName = "";
                            }
                            else
                            {
                                bstrDatasetName = obj.ToString();
                            }
                        }
                        if (gPoints == null)
                        {
                            feature = enumFeature.Next();
                        }
                        else
                        {
                            int num2 = gPoints.Size();
                            for (int i = 0; i < num2; i++)
                            {
                                GPoint gPoint = gPoints[i];

                                PipePoint pipePoint = new PipePoint();
                                if (smpClassName.ToUpper().Contains("JT_JT_L"))
                                {
                                    pipePoint.PointType = PipePoint.SectionPointType.sptRoadBorder;
                                }
                                else if (smpClassName.ToUpper().Contains("SY_ZX_L"))
                                {
                                    pipePoint.PointType = PipePoint.SectionPointType.sptMidRoadLine;
                                }
                                else if (smpClassName.ToUpper().Contains("ZB_LD_R"))
                                {
                                    pipePoint.PointType = PipePoint.SectionPointType.sptMidGreen;
                                }
                                else
                                {
                                    pipePoint.PointType = PipePoint.SectionPointType.sptPipe;
                                }
                                pipePoint.x = gPoint.X;
                                pipePoint.y = gPoint.Y;
                                pipePoint.z = gPoint.Z;
                                pipePoint.m = gPoint.M;
                                pipePoint.bstrDatasetName = bstrDatasetName;
                                //  int num3 = feature.Fields.FindField(base.PipeConfig.get_Material());
                                int num3 =
                                    feature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.GXCZ));
                                if (num3 == -1)
                                {
                                    pipePoint.strMaterial = "";
                                }
                                else
                                {
                                    object obj2 = feature.get_Value(num3);
                                    if (obj2 != null)
                                    {
                                        pipePoint.strMaterial = feature.get_Value(num3).ToString();
                                    }
                                    else
                                    {
                                        pipePoint.strMaterial = "";
                                    }
                                }
                                // num3 = feature.Fields.FindField(base.PipeConfig.get_Diameter());
                                num3 =
                                    feature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.GJ));
                                string text2;
                                if (num3 != -1 && feature.get_Value(num3) != null)
                                {
                                    text2 = feature.get_Value(num3).ToString();
                                }
                                else
                                {
                                    text2 = "";
                                }
                                num3 =
                                    feature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.DMCC));
                                string text3;
                                if (num3 != -1 && feature.get_Value(num3) != null)
                                {
                                    text3 = feature.get_Value(num3).ToString();
                                }
                                else
                                {
                                    text3 = "";
                                }
                                if (text2 != "")
                                {
                                    pipePoint.strPipeWidthHeight = text2;
                                }
                                if (text3 != "")
                                {
                                    pipePoint.strPipeWidthHeight = text3;
                                }
                                Color featureColor = CommonUtils.GetFeatureColor(map, feature.Class.AliasName, feature);
                                pipePoint.Red   = (int)featureColor.R;
                                pipePoint.Green = (int)featureColor.G;
                                pipePoint.Blue  = (int)featureColor.B;
                                this.m_arrPipePoints.Add(pipePoint);
                            }
                            feature = enumFeature.Next();
                        }
                    }
                }
            }
            map.ClearSelection();
            IPointCollection pointCollection = (IPointCollection)this.m_pBaseLine;
            int pointCount = pointCollection.PointCount;

            if (pointCount != 0)
            {
                for (int j = 0; j < pointCount; j++)
                {
                    IPoint    point      = pointCollection.get_Point(j);
                    double    x          = point.X;
                    double    y          = point.Y;
                    PipePoint pipePoint2 = new PipePoint();
                    pipePoint2.x         = x;
                    pipePoint2.y         = y;
                    pipePoint2.PointType = PipePoint.SectionPointType.sptDrawPoint;
                    this.m_arrPipePoints.Add(pipePoint2);
                }
                this.fEswZsmwIx((PipePoint)this.m_arrPipePoints[this.m_arrPipePoints.Count - 2]);
                this.method_1();
                if (this.method_2())
                {
                    this.method_5(this.m_arrPipePointsDraw, this.m_arrPipePoints);
                    this.method_4();
                    this.method_7(this.m_arrPipePointsDraw);
                }
            }
        }
Example #21
0
        public void Run(IFeatureClass inp, IFeatureClass outp, ProgressCallback progress)
        {
            IFeatureCursor all_inp = inp.Search(null, true);

            LineSegOverlay <ArcSegInf> op = new LineSegOverlay <ArcSegInf>(new PMQTree(4, 8), m_atol, m_dtol);

            double   inp_count    = inp.FeatureCount(null);
            int      steps        = (int)Math.Ceiling((double)inp_count / 20.0);
            int      inp_progress = 0;
            IFeature infeat       = all_inp.NextFeature();

            while (infeat != null)
            {
                int fid = infeat.OID;
                IGeometryCollection c = infeat.Shape as IGeometryCollection;
                for (int shell_num = 0; shell_num < c.GeometryCount; shell_num++)
                {
                    IPointCollection ps   = c.get_Geometry(shell_num) as IPointCollection;
                    IPoint           last = null;
                    for (int seg_num = 0; seg_num < ps.PointCount; seg_num++)
                    {
                        IPoint cur = ps.get_Point(seg_num);
                        if (last != null)
                        {
                            LineSeg seg = LineSeg.FromEndpoints(new Vector(last.X, last.Y),
                                                                new Vector(cur.X, cur.Y));
                            op.Insert(new ArcSegInf(seg, fid, shell_num, seg_num));
                            m_seensegs++;
                        }
                        last = cur;
                    }
                }
                inp_progress++;
                if (inp_progress % steps == 0)
                {
                    progress(0.5 * (inp_progress / inp_count));
                }
                infeat = all_inp.NextFeature();
            }

            int lfid = outp.FindField("left_fid");
            int rfid = outp.FindField("right_fid");

            // Reassemble line strings
            SegmentAssembler sa = new SegmentAssembler();

            foreach (Pair <LineSeg, IEnumerable <ArcSegInf> > r in op.Segments)
            {
                int overlap_count = 0;
                foreach (Pair <ArcSegInf, ArcSegInf> v in
                         Pair <ArcSegInf, ArcSegInf> .Pairs(r.Second))
                {
                    OverlapSegment o = new OverlapSegment(r.First, v.First, v.Second);
                    if (v.First.SrcFid < v.Second.SrcFid)
                    {
                        sa.AddSegment(o);
                    }
                    overlap_count++;
                }
                if (overlap_count == 0)
                {
                    // TODO: add exterior boundaries?
                    ArcSegInf seen = null;
                    foreach (ArcSegInf seg in r.Second)
                    {
                        seen = seg;
                    }
                    sa.AddSegment(new OverlapSegment(r.First, seen, null));
                }
            }

            double         outp_count    = sa.OverlapCount;
            int            outp_progress = 0;
            int            outp_steps    = (int)Math.Ceiling((double)outp_count / 20.0);
            IFeatureBuffer outfeat       = outp.CreateFeatureBuffer();
            IFeatureCursor outcursor     = outp.Insert(true);

            foreach (Pair <Pair <int, int>, Pair <int, int> > ss in sa.SegsAndShells)
            {
                int rhs_fid     = ss.First.First;
                int rhs_shellid = ss.First.Second;
                int lhs_fid     = ss.Second.First;
                int lhs_shellid = ss.Second.Second;

                foreach (Pair <Pair <int, int>, List <LineSeg> > linestring in sa.GetStrings(ss))
                {
                    IPolyline line = assemblePolyLine(linestring.Second);
                    outfeat.set_Value(lfid, lhs_fid);
                    outfeat.set_Value(rfid, rhs_fid);
                    outfeat.Shape = line;
                    outcursor.InsertFeature(outfeat);

                    // Same boundary but swapped!
                    outfeat.set_Value(lfid, rhs_fid);
                    outfeat.set_Value(rfid, lhs_fid);
                    outfeat.Shape = line;
                    outcursor.InsertFeature(outfeat);
                }
                // progress
                outp_progress++;
                if (outp_progress % outp_steps == 0)
                {
                    progress(0.5 + (0.5 * outp_progress / outp_count));
                }
            }

            outcursor.Flush();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(outcursor);
        }
Example #22
0
        private GPoints CalculateIntersections(IPolyline polyline, IPolyline polyline2)
        {
            IPointCollection pointCollection = (IPointCollection)polyline;
            int     pointCount = pointCollection.PointCount;
            GPoints result;

            if (pointCount == 0)
            {
                result = null;
            }
            else
            {
                GPolyLine gPolyLine = new GPolyLine();
                gPolyLine.Clear();
                for (int i = 0; i < pointCount; i++)
                {
                    IPoint point = pointCollection.get_Point(i);
                    double x     = point.X;
                    double y     = point.Y;
                    double z     = point.Z - point.M;
                    double z2    = point.Z;
                    gPolyLine.PushBack(new GPoint
                    {
                        X = x,
                        Y = y,
                        Z = z,
                        M = z2
                    });
                }
                pointCollection = (IPointCollection)polyline2;
                pointCount      = pointCollection.PointCount;
                if (pointCount == 0)
                {
                    result = null;
                }
                else
                {
                    GPolyLine gPolyLine2 = new GPolyLine();
                    gPolyLine2.Clear();
                    for (int j = 0; j < pointCount; j++)
                    {
                        IPoint point2 = pointCollection.get_Point(j);
                        double x2     = point2.X;
                        double y2     = point2.Y;
                        double z3     = point2.Z - point2.M;
                        double m;
                        if (double.IsNaN(point2.M))
                        {
                            m = 1.0 + point2.Z;
                        }
                        else
                        {
                            m = point2.Z;
                        }
                        gPolyLine2.PushBack(new GPoint
                        {
                            X = x2,
                            Y = y2,
                            Z = z3,
                            M = m
                        });
                    }
                    new GPoints();
                    result = gPolyLine.GetInterPtsToPolyLineWithHeightForTransect(gPolyLine2);
                }
            }
            return(result);
        }
Example #23
0
        private void OnSketchFinished()
        {
            ConfigUtil.type = "address";
            //send a space to hide the construction toolbar
            SendKeys.SendWait(" ");

            List <CreatePointWithReferenceDetails> configDetails = null;
            AddressReturnInfo retInfo = null;
            IPointCollection  pPnts   = null;
            List <IFeature>   pFeats  = null;
            IPoint            pPnt    = null;

            try
            {
                ((IMxDocument)ArcMap.Document).FocusMap.ClearSelection();

                Keys ModKey = Control.ModifierKeys;


                pPnts = m_edSketch.Geometry as IPointCollection;
                if (pPnts == null)
                {
                    return;
                }

                if (pPnts.PointCount < 2)
                {
                    return;
                }

                try
                {
                    m_editor.StartOperation();
                }
                catch
                {
                    m_editor.AbortOperation();
                    m_editor.StartOperation();
                }

                int idxConfig = -1;
                // TODO: Add developer code here
                configDetails = ConfigUtil.GetCreatePointWithRefConfig();


                retInfo = AMGeometryTools.AddPointWithRef(ArcMap.Application, pPnts.get_Point(0), configDetails, ((IFeatureLayer)m_editor.CurrentTemplate.Layer), ref idxConfig);//,config,null,true,true);
                if (idxConfig == -1)
                {
                    return;
                }

                if (retInfo == null)
                {
                    return;
                }


                int targetAddFieldIdx = Globals.GetFieldIndex(((IFeatureLayer)m_editor.CurrentTemplate.Layer), configDetails[idxConfig].AddressField);

                if (targetAddFieldIdx == -1)
                {
                    return;
                }

                int targetNameFieldIdx = Globals.GetFieldIndex(((IFeatureLayer)m_editor.CurrentTemplate.Layer), configDetails[idxConfig].StreetNameField);

                if (targetNameFieldIdx == -1)
                {
                    return;
                }

                int targetIDFieldIdx = Globals.GetFieldIndex(((IFeatureLayer)m_editor.CurrentTemplate.Layer), configDetails[idxConfig].AddressPntKeyField);

                //if (targetIDFieldIdx == -1)
                //    return;

                //. .AddLaterals(m_application, ConfigUtil.GetAddLateralsConfig(), pFeat, false, true, false, false);

                //IFeature pFeat = null;
                pFeats = new List <IFeature>();

                for (int i = 1; i < pPnts.PointCount; i++)
                {
                    pFeats.Add(Globals.CreateFeature(pPnts.get_Point(i), m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true));
                    // pFeats.Add(pFeat);
                }

                foreach (IFeature pFeat in pFeats)
                {
                    if (retInfo.AddressDetails.StreetGeometry == null)
                    {
                        if (targetNameFieldIdx != -1)
                        {
                            pFeat.set_Value(targetNameFieldIdx, retInfo.AddressDetails.Messages);
                        }
                    }
                    else
                    {
                        bool rightSide = true;
                        pPnt = Globals.GetPointOnLine(pFeat.Shape as IPoint, retInfo.AddressDetails.StreetGeometry as IPolyline, 10000, out rightSide);
                        if (rightSide)
                        {
                            pFeat.set_Value(targetAddFieldIdx, retInfo.AddressDetails.RightAddress);
                        }
                        else
                        {
                            pFeat.set_Value(targetAddFieldIdx, retInfo.AddressDetails.LeftAddress);
                        }
                        if (targetNameFieldIdx != -1)
                        {
                            pFeat.set_Value(targetNameFieldIdx, retInfo.AddressDetails.StreetName);
                        }

                        if (targetIDFieldIdx != -1)
                        {
                            pFeat.set_Value(targetIDFieldIdx, retInfo.AddressPointKey);
                        }
                        pFeat.Store();
                    }
                }
                pPnts = null;
                ((IMxDocument)ArcMap.Document).ActiveView.Refresh();
                try
                {
                    m_editor.StopOperation("Create Point with Reference");
                }
                catch
                {
                }
            }
            catch
            {
                configDetails = null;
                retInfo       = null;
                pPnts         = null;
                pFeats        = null;
                pPnt          = null;
                try
                {
                    m_editor.AbortOperation();
                }
                catch
                {
                }
            }
        }
Example #24
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("Please input the yardstick length");
                return;
            }

            //Start main functions...
            GetWorkPath();
            if (strFilePath == null)
            {
                return;
            }
            IWorkspace        ws   = OpenShapfileWorkspace(strFilePath);
            IFeatureWorkspace pFWS = ws as IFeatureWorkspace;

            //Only one feature in the featureclass
            IFeatureClass fcCoastLine   = pFWS.OpenFeatureClass("UK_Coastline");
            IFeature      fCoastLine    = fcCoastLine.GetFeature(0);
            IPolyline     polylineCoast = new PolylineClass();

            polylineCoast = fCoastLine.ShapeCopy as IPolyline;
            //NOTE!!! Use SHAPECOPY NOT SHAPE!!!
            //Initialize coastline;
            Coastline = fCoastLine.ShapeCopy as IPolyline;

            IFeatureClass fcVertices = pFWS.OpenFeatureClass("UK_CoastlineVertices");

            ICircularArc startCircle;

            startCenterPoint = fcVertices.GetFeature(0).Shape as IPoint;
            MessageBox.Show("x: " + startCenterPoint.X.ToString() + " y: " + startCenterPoint.Y.ToString());

            yardStickLength = textBox1.Text;
            radius          = double.Parse(yardStickLength);

            startCircle = CreateCircleArc(startCenterPoint, radius, false);
            //Initialize startcirlcePolygon
            startCirclePolygon = Arc2Polygon(startCircle);
            //Get first Intersct points
            IPointCollection firstPointColl = IntersectPointColl(startCircle, polylineCoast);

            MessageBox.Show("first intersect point: " + firstPointColl.PointCount.ToString());

            //ICircularArc movingCircle = CreateCircleArc(firstPointColl.get_Point(0), radius, false);
            //IPointCollection newPointColl = IntersectPointColl(movingCircle, polylineCoast);
            //pGeometryCollection = newPointColl as IGeometryCollection;
            //CreateShpfile("2ndPoint2", pGeometryCollection);
            //判断交点个数
            if (firstPointColl.PointCount != 2)
            {
                initialCenterPoints = GetCorrectPointInitial(SplitPolyline(polylineCoast, firstPointColl, startCenterPoint), startCenterPoint);
            }
            else
            {
                IPoint        pt1    = firstPointColl.get_Point(0) as IPoint;
                IPoint        pt2    = firstPointColl.get_Point(1) as IPoint;
                List <IPoint> ptlist = new List <IPoint>();
                ptlist.Add(pt1);
                ptlist.Add(pt2);
                initialCenterPoints = ptlist;
            }
            //确定第二个圆心位置
            if (initialCenterPoints.Count == 2)
            {
                if (initialCenterPoints[0].X > initialCenterPoints[1].X)
                {
                    secondCenterPoint = initialCenterPoints[0];
                }
                else
                {
                    secondCenterPoint = initialCenterPoints[1];
                }
                MessageBox.Show("The second circle center is X " + secondCenterPoint.X + " Y " + secondCenterPoint.Y);
            }
            else
            {
                MessageBox.Show("Initialize failed");
            }
        }
Example #25
0
        private void CalculateIntersect(IFeatureCursor pFeatureCursor, IGeometry pGeometry)
        {
            if (pFeatureCursor == null)
            {
                return;
            }
            IMultipoint          pIntersectionPoints = null;
            IPointCollection     pPointColl          = null;
            List <IFeature>      pFeatureList        = new List <IFeature>();
            ITopologicalOperator pTopoOperator       = pGeometry as ITopologicalOperator;
            //画线的几何体
            IPointCollection pSkecthPiontColl = pGeometry as IPointCollection;
            IPoint           pPoint0          = pSkecthPiontColl.get_Point(0);
            IFeature         pFeature         = pFeatureCursor.NextFeature();

            pFeatureList.Clear();
            while ((pFeature != null))
            {
                pFeatureList.Add(pFeature);
                pFeature = pFeatureCursor.NextFeature();
            }
            IPolyline pPolyline = pGeometry as IPolyline;
            IPoint    pPointF   = pPolyline.FromPoint;
            Dictionary <double, IFeature> pDic = new Dictionary <double, IFeature>();
            int pCount = pFeatureList.Count;

            double[] sortArray = new double[pCount];
            for (int i = 0; i <= pCount; i++)
            {
                try
                {
                    pFeature            = pFeatureList[i];
                    pIntersectionPoints = pTopoOperator.Intersect(pFeature.Shape, esriGeometryDimension.esriGeometry0Dimension) as IMultipoint;
                    pPointColl          = pIntersectionPoints as IPointCollection;
                    sortArray[i]        = GetDistance(pPointF, pPointColl.get_Point(0));
                    pDic.Add(GetDistance(pPointF, pPointColl.get_Point(0)), pFeatureList[i]);
                    pFeature = pFeatureCursor.NextFeature();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            for (int H = sortArray.Length - 1; H >= 0; H--)
            {
                for (int j = 0; j < H; j++)
                {
                    if (sortArray[j] > sortArray[j + 1])
                    {
                        double temp = sortArray[j];
                        sortArray[j]     = sortArray[j + 1];
                        sortArray[j + 1] = temp;
                    }
                }
            }
            int pFieldIndex = pFeatureLayer.FeatureClass.Fields.FindField(pHeightName);
            Dictionary <IFeature, double> pDicdis = new Dictionary <IFeature, double>();

            for (int m = 0; m < sortArray.Length; m++)
            {
                foreach (KeyValuePair <double, IFeature> pKey in pDic)
                {
                    if (sortArray[m] == pKey.Key)
                    {
                        IFeature pFeatureH = pKey.Value;
                        pFeatureH.set_Value(pFieldIndex, pHeight + pInterval * m);
                        pFeatureH.Store();
                    }
                }
            }
        }
Example #26
0
        public override void OnMouseUp(int button, int shift, int x, int y, double mapX, double mapY)
        {
            base.OnMouseUp(button, shift, x, y, mapX, mapY);

            if (!m_bIsUse)
            {
                return;
            }

            IGeometry pEnv;

            if (m_pFeedbackEnve != null)
            {
                pEnv = m_pFeedbackEnve.Stop();
                m_FocusMap.SelectByShape(pEnv, null, false);
            }
            else
            {
                IEnvelope pRect;
                double    dblConst;
                dblConst = CommonFunction.ConvertPixelsToMapUnits(m_pActiveView, 8);//8个象素大小
                pRect    = CommonFunction.NewRect(m_pPoint, dblConst);
                m_FocusMap.SelectByShape(pRect, null, false);
            }

            IArray tempArray = CommonFunction.GetSelectFeatureSaveToArray(m_FocusMap);

            for (int i = 0; i < tempArray.Count; i++)
            {
                if (((IFeature)tempArray.get_Element(i)).Shape.GeometryType == esriGeometryType.esriGeometryPolyline ||
                    ((IFeature)tempArray.get_Element(i)).Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                {                                                                 //只能选中线要素或面要素
                    m_OriginFeatureArray.Add((IFeature)tempArray.get_Element(i)); //将线要素添加到源数组中
                }
            }
            tempArray.RemoveAll();                                             //请空临时数组

            CommonFunction.MadeFeatureArrayOnlyAloneOID(m_OriginFeatureArray); //使得源要素数组具有唯一性

            m_MapControl.ActiveView.FocusMap.ClearSelection();                 //清空地图选择的要素

            m_pEnvelope = CommonFunction.GetMinEnvelopeOfTheFeatures(m_OriginFeatureArray);
            if (m_pEnvelope != null && !m_pEnvelope.IsEmpty)
            {
                m_pEnvelope.Expand(1, 1, false);
            }

            if (m_OriginFeatureArray.Count != 0)
            {
                m_MapControl.ActiveView.GraphicsContainer.DeleteAllElements();
                CommonFunction.ShowSelectionFeatureArray(m_MapControl, m_OriginFeatureArray);//高亮显示选择的要素

                for (int i = 0; i < m_OriginFeatureArray.Count; i++)
                {
                    IPointCollection pPointCollection = (IPointCollection)(m_OriginFeatureArray.get_Element(i) as IFeature).Shape;

                    for (int j = 0; j < pPointCollection.PointCount; j++)
                    {
                        CommonFunction.DrawPointSMSSquareSymbol(m_MapControl, pPointCollection.get_Point(j));
                    }
                }
            }


            //选择复位
            m_pFeedbackEnve = null;
            m_bIsUse        = false;
        }
Example #27
0
        private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            if (e.button == 1)
            {
                //给m_graphicsContainer赋值
                m_graphicsContainer = axMapControl1.Map as IGraphicsContainer;
                //在添加polygon被选中时
                if (miAddPolygon.Checked)
                {
                    //在鼠标点击的位置生成一个点
                    IPoint p_Point = new PointClass();
                    p_Point.PutCoords(e.mapX, e.mapY);
                    IActiveView    p_activeview    = axMapControl1.Map as IActiveView;
                    IScreenDisplay p_ScreenDisplay = p_activeview.ScreenDisplay;
                    //标记符等于0时
                    if (m_marker == 0)
                    {
                        //对m_DisplayFeedback重新初始化
                        m_DisplayFeedback = new NewPolygonFeedbackClass();
                        //设置m_DisplayFeedback的display
                        m_DisplayFeedback.Display = p_ScreenDisplay;
                        //开始绘制polygon的第一个点
                        ((INewPolygonFeedback)m_DisplayFeedback).Start(p_Point);
                        //将m_polyline转为pointcollection
                        IPointCollection p_PointCollection = m_polyline as IPointCollection;
                        //将第一个点加入pointcollection中
                        p_PointCollection.AddPoint(p_Point);
                        //将第一个点记录到m_point中
                        m_point = p_Point;
                        //对m_polyline重新赋值
                        m_polyline = p_PointCollection as IPolyline;
                        if (m_marker == 0)
                        {
                            m_marker = 1;
                        }
                        //刷新
                        axMapControl1.ActiveView.Refresh();
                    }
                    //如果不是第一次点击,就添加节点
                    else
                    {
                        //初始化红线和蓝线
                        if (m_element_red != null)
                        {
                            m_graphicsContainer.DeleteElement(m_element_red);
                        }
                        if (m_element_green != null)
                        {
                            m_graphicsContainer.DeleteElement(m_element_green);
                        }
                        //向m_DisplayFeedback中添加顶点
                        ((INewPolygonFeedback)m_DisplayFeedback).AddPoint(p_Point);
                        IPointCollection p_PointCollection = m_polyline as IPointCollection;
                        p_PointCollection.AddPoint(p_Point);
                        //生成红线
                        m_polyline = p_PointCollection as IPolyline;
                        ILineElement p_LineElement_red = new LineElementClass();
                        m_element_red          = p_LineElement_red as IElement;
                        m_element_red.Geometry = m_polyline;
                        ISimpleLineSymbol p_SimpleLineSymbol = new SimpleLineSymbolClass();
                        IRgbColor         p_rgbcolor         = new RgbColorClass();
                        p_rgbcolor.Red           = 255;
                        p_rgbcolor.Green         = 0;
                        p_rgbcolor.Blue          = 0;
                        p_SimpleLineSymbol.Color = p_rgbcolor as IColor;
                        p_LineElement_red.Symbol = p_SimpleLineSymbol as ILineSymbol;
                        //设置蓝线symbol
                        ISimpleLineSymbol p_SimpleLine_green = new SimpleLineSymbolClass();
                        IRgbColor         p_rgbcolor_green   = new RgbColorClass();
                        p_rgbcolor_green.Red     = 0;
                        p_rgbcolor_green.Green   = 255;
                        p_rgbcolor_green.Blue    = 255;
                        p_SimpleLine_green.Color = p_rgbcolor_green as IColor;
                        //生成蓝线
                        IPolyline        p_polyline        = new PolylineClass();
                        IPointCollection p_pointColl_green = p_polyline as IPointCollection;
                        //向蓝线中添加两个顶点
                        p_pointColl_green.AddPoint(m_point);
                        p_pointColl_green.AddPoint(p_Point);
                        p_polyline = p_pointColl_green as IPolyline;
                        ILineElement p_LineElement_green = new LineElementClass();
                        m_element_green            = p_LineElement_green as IElement;
                        p_LineElement_green.Symbol = p_SimpleLine_green as ILineSymbol;
                        m_element_green.Geometry   = p_polyline;
                        //将红线和蓝线加入containner显示
                        m_graphicsContainer.AddElement(m_element_red, 0);
                        m_graphicsContainer.AddElement(m_element_green, 0);
                        //更新视图
                        axMapControl1.ActiveView.Refresh();
                    }
                }
                //当选择polygon被选中时
                if (miSelectPolygon.Checked)
                {
                    //如果m_list不为空,则从容器中把其所对应element删除并将m_list清空
                    if (m_list.Count != 0)
                    {
                        for (int i = 0; i < m_list.Count; i++)
                        {
                            m_graphicsContainer.DeleteElement(m_list[i]);
                        }
                        m_list.Clear();
                    }
                    //刷新
                    axMapControl1.ActiveView.Refresh();
                    IPoint p_point = new PointClass();
                    //记录点下的点
                    p_point.PutCoords(e.mapX, e.mapY);
                    //得到选中的element集合
                    IEnumElement p_EnumElement = m_graphicsContainer.LocateElements(p_point, 5);
                    IGeometry    p_geometry;
                    //选中的element集合不为空时
                    if (p_EnumElement != null)
                    {
                        m_hitElement = p_EnumElement.Next();
                        p_geometry   = m_hitElement.Geometry;
                        //循环找到类型为polygon的element
                        while (p_geometry.GeometryType != esriGeometryType.esriGeometryPolygon && m_hitElement != null)
                        {
                            m_hitElement = p_EnumElement.Next();
                            if (m_hitElement != null)
                            {
                                p_geometry = m_hitElement.Geometry;
                            }
                        }
                        if (p_geometry.GeometryType == esriGeometryType.esriGeometryPolygon)
                        {
                            m_polygon   = (IPolygon)p_geometry;
                            m_PointColl = m_polygon as IPointCollection;
                            //循环将选中的polygon的每个点以element加入容器中
                            for (int k = 1; k < m_PointColl.PointCount; k++)
                            {
                                IMarkerElement      p_MarkerElement = new MarkerElementClass();
                                ISimpleMarkerSymbol p_simpleMarker  = new SimpleMarkerSymbolClass();
                                p_simpleMarker.Size = 5;

                                IElement p_element = (IElement)p_MarkerElement;
                                p_MarkerElement.Symbol = p_simpleMarker as IMarkerSymbol;

                                if (!(p_element == null))
                                {
                                    p_element.Geometry = m_PointColl.get_Point(k);

                                    m_graphicsContainer.AddElement(p_element, 0);
                                }
                                m_list.Add(p_element);
                            }
                            axMapControl1.ActiveView.Refresh();
                        }
                    }
                }
                //当编辑polygon被选中时
                if (miEditPolygon.Checked)
                {
                    if (m_polygon != null)
                    {
                        //在鼠标点击的位置生成一个点
                        IPoint p_Point = new PointClass();
                        p_Point.PutCoords(e.mapX, e.mapY);
                        IActiveView    p_ActiveView    = axMapControl1.Map as IActiveView;
                        IScreenDisplay p_ScreenDisplay = p_ActiveView.ScreenDisplay;
                        //建立新的hittest,设置相关变量,获取点击处polygon的顶点
                        IHitTest p_HitTest         = m_polygon as IHitTest;
                        IPoint   p_hitPoint        = new PointClass();
                        double   p_distance        = 0;
                        bool     p_isOnRightSide   = true;
                        int      p_hitPartIndex    = 0;
                        int      p_hitSegmentIndex = 0;
                        bool     p_isHit           = p_HitTest.HitTest(p_Point, this.axMapControl1.ActiveView.Extent.Width / 100, esriGeometryHitPartType.esriGeometryPartVertex, p_hitPoint, ref p_distance, ref p_hitPartIndex, ref p_hitSegmentIndex, ref p_isOnRightSide);
                        //如果有点被选中,开始拖动该点
                        if (p_isHit)
                        {
                            m_DisplayFeedback         = new PolygonMovePointFeedbackClass();
                            m_marker                  = 2;
                            m_DisplayFeedback.Display = p_ScreenDisplay;
                            ((IPolygonMovePointFeedback)m_DisplayFeedback).Start(m_polygon, p_hitSegmentIndex, p_Point);
                        }
                    }
                }
            }
        }
Example #28
0
        static private void GetMouOrBotFun(IFeatureLayer conFyr)
        {
            closedline = OrderedOfClosedCon(conFyr);
            List <int> idContain = new List <int>();

            for (int i = 0; i < closedline.Count; i++)
            {
                if (idContain.Count != 0)
                {
                    if (idContain.Contains(closedline[i].ConFea.OID))
                    {
                        continue;
                    }
                }
                IPointCollection    ptCol     = closedline[i].ConFea.Shape as IPointCollection;
                IPoint              pt1       = ptCol.get_Point(0);
                double              Z1        = closedline[i].Z;
                IPolygon            pPolygon1 = GetPolygon(closedline[i].ConFea.Shape as IPolyline);
                IRelationalOperator topo1     = pPolygon1 as IRelationalOperator;
                int m = 0;
                List <FeaInfoClass> bottomFlist = new List <FeaInfoClass>();
                for (int j = i + 1; j < closedline.Count; j++)
                {
                    IPointCollection    ptC       = closedline[j].ConFea.Shape as IPointCollection;
                    IPoint              pt2       = ptC.get_Point(0);
                    double              Z2        = closedline[j].Z;
                    IPolygon            pPolygon2 = GetPolygon(closedline[j].ConFea.Shape as IPolyline);
                    IRelationalOperator topo2     = pPolygon2 as IRelationalOperator;
                    if (topo2.Contains(pt1 as IGeometry))
                    {
                        if (m == 0)
                        {
                            hellollFea.Add(closedline[i].ConFea);
                            idContain.Add(closedline[i].ConFea.OID);
                        }
                        idContain.Add(closedline[j].ConFea.OID);
                        m++;
                    }
                    else if (topo1.Contains(pt2 as IGeometry))
                    {
                        bottomFlist.Add(closedline[j]);
                    }
                }
                if (bottomFlist.Count != 0)
                {
                    idContain.Add(closedline[i].ConFea.OID);
                    for (int n = 0; n < bottomFlist.Count; n++)
                    {
                        idContain.Add(bottomFlist[n].ConFea.OID);
                    }
                    bottomFea.Add(bottomFlist[bottomFlist.Count - 1].ConFea);
                }
                if (m == 0 && bottomFlist.Count == 0)//从开曲线
                {
                    IPointCollection ring = new RingClass() as IPointCollection;
                    IRing            rng  = ring as IRing;
                    for (int j = 0; j < ptCol.PointCount; j++)
                    {
                        ring.AddPoint(ptCol.get_Point(j));
                    }
                    bool isExterior = rng.IsExterior;
                    if (isExterior == true)
                    {
                        bottomFea.Add(closedline[i].ConFea);
                    }
                    else
                    {
                        hellollFea.Add(closedline[i].ConFea);
                    }
                    idContain.Add(closedline[i].ConFea.OID);
                }
            }
        }
Example #29
0
        private double method_2(IPolyline polyline, IPolyline polyline2)
        {
            IPointCollection pointCollection = (IPointCollection)polyline;
            int    pointCount = pointCollection.PointCount;
            double result;

            if (pointCount == 0)
            {
                result = 0.0;
            }
            else
            {
                GPolyLine gPolyLine = new GPolyLine();
                gPolyLine.Clear();
                for (int i = 0; i < pointCount; i++)
                {
                    IPoint point = pointCollection.get_Point(i);
                    double x     = point.X;
                    double y     = point.Y;
                    double z     = point.Z;
                    double m     = point.M;
                    gPolyLine.PushBack(new GPoint
                    {
                        X = x,
                        Y = y,
                        Z = z,
                        M = m
                    });
                }
                pointCollection = (IPointCollection)polyline2;
                pointCount      = pointCollection.PointCount;
                if (pointCount == 0)
                {
                    result = 0.0;
                }
                else
                {
                    GPolyLine gPolyLine2 = new GPolyLine();
                    gPolyLine2.Clear();
                    for (int j = 0; j < pointCount; j++)
                    {
                        IPoint point2 = pointCollection.get_Point(j);
                        double x2     = point2.X;
                        double y2     = point2.Y;
                        double z2     = point2.Z;
                        double m2     = point2.M;
                        gPolyLine2.PushBack(new GPoint
                        {
                            X = x2,
                            Y = y2,
                            Z = z2,
                            M = m2
                        });
                    }
                    GPoints gPoints = new GPoints();
                    gPoints = gPolyLine.GetInterPtsToPolyLineWithHeight(gPolyLine2);
                    long   num  = (long)gPoints.Size();
                    double num2 = -1.0;
                    int    num3 = 0;
                    while ((long)num3 < num)
                    {
                        GPoint gPoint = gPoints[num3];
                        double num4   = this.method_5(gPoint.M, gPoint.Z);
                        if (num3 == 0)
                        {
                            num2 = num4;
                        }
                        else if (num2 > num4)
                        {
                            num2 = num4;
                        }
                        num3++;
                    }
                    result = num2;
                }
            }
            return(result);
        }
Example #30
0
        public static IGroupElement CreateRoadSurfaceFromPolygon(IFeature ifeature_0, IFeature3DProperties ifeature3DProperties_0, clsTextureGroup clsTextureGroup_0, ISurface isurface_0, string string_0, IPolygon ipolygon_0, bool bool_0)
        {
            IGroupElement groupElement = null;
            IGroupElement result;

            try
            {
                IEncode3DProperties encode3DProperties = new GeometryEnvironment() as IEncode3DProperties;
                IGroupElement       groupElement2      = new GroupElement() as IGroupElement;
                if (modFacades.m_limitAngle == 0.0)
                {
                    modFacades.m_limitAngle = 0.5235987666666666;
                }
                IGeometry geometry = null;
                if (ifeature_0 != null)
                {
                    if (ifeature3DProperties_0 != null && bool_0)
                    {
                        ifeature3DProperties_0.ApplyFeatureProperties(ifeature_0, out geometry, false);
                        modFacades.g_bFeaturePropertiesApplied = true;
                    }
                    else
                    {
                        geometry = ifeature_0.Shape;
                        modFacades.g_bFeaturePropertiesApplied = false;
                    }
                }
                else if (ipolygon_0 != null)
                {
                    geometry = ipolygon_0;
                }
                if (geometry == null)
                {
                    result = groupElement;
                    return(result);
                }
                if (!(geometry is IMultiPatch))
                {
                }
                IEnvelope envelope = geometry.Envelope;
                double    num      = envelope.ZMin;
                if (modFacades.IsNaN(num))
                {
                    num = 0.0;
                }
                double        num2          = 0.0;
                I3DProperties i3DProperties = ifeature3DProperties_0 as I3DProperties;
                if (i3DProperties.OffsetExpressionString.Length > 0)
                {
                    num2 = Convert.ToDouble(i3DProperties.OffsetExpressionString);
                }
                if (geometry is IPolygon)
                {
                    num += num2;
                }
                IGeometryCollection geometryCollection = geometry as IGeometryCollection;
                int geometryCount = geometryCollection.GeometryCount;
                int num3;
                if (geometry is IMultiPatch)
                {
                    geometryCount = geometryCollection.GeometryCount;
                    num3          = geometryCollection.GeometryCount * 2 / 3;
                    modFacades.m_extrusionHeight = geometry.Envelope.ZMax - geometry.Envelope.ZMin;
                }
                else
                {
                    num3          = 0;
                    geometryCount = geometryCollection.GeometryCount;
                }
                if (modFacades.m_extrusionHeight >= 1.0)
                {
                }
                for (int i = num3; i <= geometryCount - 1; i++)
                {
                    IGeometry        geometry2    = geometryCollection.get_Geometry(i);
                    esriGeometryType geometryType = geometry2.GeometryType;
                    if (geometryType == esriGeometryType.esriGeometryRing || geometryType == esriGeometryType.esriGeometryPolyline)
                    {
                    }
                    IPointCollection pointCollection = geometry2 as IPointCollection;
                    int pointCount = pointCollection.PointCount;
                    if (pointCount >= 2)
                    {
                    }
                    IVector3D vector3D = new Vector3D() as IVector3D;
                    vector3D.XComponent = 0.0;
                    vector3D.YComponent = 0.0;
                    vector3D.ZComponent = 1.0;
                    double m = 0.0;
                    encode3DProperties.PackNormal(vector3D, out m);
                    IPointCollection pointCollection2 = new Ring();
                    object           value            = Missing.Value;
                    short            num4             = 0;
                    while ((int)num4 <= pointCount - 1)
                    {
                        IPoint point = pointCollection.get_Point((int)num4);
                        point.Z = num;
                        point.M = m;
                        IClone clone = point as IClone;
                        pointCollection2.AddPoint(clone.Clone() as IPoint, ref value, ref value);
                        num4 += 1;
                    }
                    IRing ring = pointCollection2 as IRing;
                    ring.Close();
                    IMultiPatch         multiPatch          = new MultiPatch() as IMultiPatch;
                    IGeometryCollection geometryCollection2 = multiPatch as IGeometryCollection;
                    IZAware             iZAware             = multiPatch as IZAware;
                    iZAware.ZAware = true;
                    IMAware iMAware = multiPatch as IMAware;
                    iMAware.MAware = true;
                    geometryCollection2.AddGeometry(pointCollection2 as IGeometry, ref value, ref value);
                    multiPatch.PutRingType(pointCollection2 as IRing, esriMultiPatchRingType.esriMultiPatchOuterRing);
                    IElement element = modFacades.CreateElement(multiPatch, clsTextureGroup_0.RoofSymbol, string_0 + ";ROOFCOLOR=" + clsTextureGroup_0.RoofColorRGB.ToString());
                    if (element != null)
                    {
                        groupElement2.AddElement(element);
                    }
                }
                if (groupElement2 != null)
                {
                    IElementProperties elementProperties = groupElement2 as IElementProperties;
                    elementProperties.Name = string_0;
                }
                groupElement = groupElement2;
                result       = groupElement;
                return(result);
            }
            catch
            {
            }
            result = groupElement;
            return(result);
        }
Example #31
0
        private double method_3(IPolyline polyline, IPolyline polyline2)
        {
            IPointCollection pointCollection = (IPointCollection)polyline;
            int    pointCount = pointCollection.PointCount;
            double result;

            if (pointCount == 0)
            {
                result = -1.0;
            }
            else
            {
                double num  = 0.0;
                double num2 = 0.0;
                for (int i = 0; i < pointCount; i++)
                {
                    IPoint point = pointCollection.get_Point(i);
                    double z     = point.Z;
                    if (i == 0)
                    {
                        num = (num2 = z);
                    }
                    else
                    {
                        num  = ((z > num) ? z : num);
                        num2 = ((z < num2) ? z : num2);
                    }
                }
                pointCollection = (IPointCollection)polyline2;
                pointCount      = pointCollection.PointCount;
                if (pointCount == 0)
                {
                    result = -1.0;
                }
                else
                {
                    double num3 = 0.0;
                    double num4 = 0.0;
                    for (int j = 0; j < pointCount; j++)
                    {
                        IPoint point2 = pointCollection.get_Point(j);
                        double z2     = point2.Z;
                        if (j == 0)
                        {
                            num3 = (num4 = z2);
                        }
                        else
                        {
                            num3 = ((z2 > num3) ? z2 : num3);
                            num4 = ((z2 < num4) ? z2 : num4);
                        }
                    }
                    double val  = this.method_5(num, num3);
                    double val2 = this.method_5(num, num4);
                    double val3 = this.method_5(num2, num3);
                    double val4 = this.method_5(num2, num4);
                    result = Math.Min(Math.Min(val, val2), Math.Min(val3, val4));
                }
            }
            return(result);
        }
Example #32
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();
        }
        /// <summary>
        /// IGeometry对象投影转换
        /// </summary>
        /// <param name="sourceGeometry">源对象</param>
        /// <param name="SourceProjection">源投影</param>
        /// <param name="SourceStrip">源分带</param>
        /// <param name="L0">源中央子午线</param>
        /// <param name="IsBigNumber_Source">源是/否是大数</param>
        /// <param name="ObjectProjection">目标投影</param>
        /// <param name="ObjectStrip">目标分带</param>
        /// <param name="IsBigNumber_Object">目标是/否是大数</param>
        /// <param name="ObjectSpatialReference">目标空间参考接口</param>
        /// <returns>返加投影转换后对象IGeometry</returns>
        public IGeometry getObjectGeometry(IGeometry sourceGeometry,
                                           EnumProjectionDatum SourceProjection,
                                           EnumStrip SourceStrip, double L0, bool IsBigNumber_Source,
                                           EnumProjectionDatum ObjectProjection,
                                           EnumStrip ObjectStrip, bool IsBigNumber_Object,
                                           ISpatialReference ObjectSpatialReference)
        {
            IGeometry ObjGeometry = null;
            IPoint    p           = null;

            if (sourceGeometry is IPoint)
            {   //点
                #region Point
                double x = 0;
                double y = 0;
                double B = 0;
                double L = 0;
                x = (sourceGeometry as IPoint).X;
                y = (sourceGeometry as IPoint).Y;
                this.GetBLFromXY(y, x, ref B, ref L, 0, SourceProjection, SourceStrip, L0, IsBigNumber_Source);

                this.GetXYFromBL(B, L, ref x, ref y, 0, ObjectProjection, ObjectStrip, IsBigNumber_Object);
                IPoint objP = new PointClass();
                objP.X = y;
                objP.Y = x;
                //投影到目标点对象
                objP.SpatialReference = ObjectSpatialReference;
                ObjGeometry           = objP as IGeometry;
                #endregion
            }
            else if (sourceGeometry is IPolyline)
            {   //线
                #region polyline
                IPolyline        objPolyline = new PolylineClass();
                IPointCollection objPc       = objPolyline as IPointCollection;
                double           x           = 0;
                double           y           = 0;
                double           B           = 0;
                double           L           = 0;
                IPointCollection pcol        = sourceGeometry as IPointCollection;
                object           miss        = Type.Missing;
                for (int j = 0; j < pcol.PointCount; j++)
                {
                    p = pcol.get_Point(j);
                    x = p.X;
                    y = p.Y;
                    this.GetBLFromXY(y, x, ref B, ref L, 0, SourceProjection, SourceStrip, L0, IsBigNumber_Source);

                    this.GetXYFromBL(B, L, ref x, ref y, 0, ObjectProjection, ObjectStrip, IsBigNumber_Object);
                    IPoint objPoint = new PointClass();
                    objPoint.X = y;
                    objPoint.Y = x;
                    objPoint.SpatialReference = ObjectSpatialReference;
                    objPc.AddPoint(objPoint, ref miss, ref miss);
                }
                objPolyline.SpatialReference = ObjectSpatialReference;
                ObjGeometry = objPolyline as IGeometry;
                #endregion
            }
            else if (sourceGeometry is IPolygon)
            {   //面   /注记面
                #region polygon
                IPolygon            objPolygon = new PolygonClass();
                IGeometryCollection objPc      = objPolygon as IGeometryCollection;
                double x = 0;
                double y = 0;
                double B = 0;
                double L = 0;
                IGeometryCollection GeoCol        = sourceGeometry as IGeometryCollection;
                object           miss             = Type.Missing;
                IGeometry        tpGeo            = null;
                IPointCollection pcol             = null;
                IRing            newRing          = null;
                IPointCollection newRingPointColl = null;
                for (int j = 0; j < GeoCol.GeometryCount; j++)
                {
                    tpGeo = GeoCol.get_Geometry(j);  //面内环ring(内/外环)

                    pcol             = tpGeo as IPointCollection;
                    newRing          = new RingClass();
                    newRingPointColl = newRing as IPointCollection;
                    for (int k = 0; k < pcol.PointCount; k++)
                    {
                        p = pcol.get_Point(k);
                        x = p.X;
                        y = p.Y;
                        this.GetBLFromXY(y, x, ref B, ref L, 0, SourceProjection, SourceStrip, L0, IsBigNumber_Source);

                        this.GetXYFromBL(B, L, ref x, ref y, 0, ObjectProjection, ObjectStrip, IsBigNumber_Object);
                        IPoint objPoint = new PointClass();
                        objPoint.X = y;
                        objPoint.Y = x;
                        objPoint.SpatialReference = ObjectSpatialReference;
                        newRingPointColl.AddPoint(objPoint, ref miss, ref miss);
                    }
                    newRing.SpatialReference = ObjectSpatialReference;
                    objPc.AddGeometry(newRing as IGeometry, ref miss, ref miss);
                }
                objPolygon.SpatialReference = ObjectSpatialReference;
                ObjGeometry = objPolygon as IGeometry;
                #endregion
            }
            else if (sourceGeometry is IGeometryBag)
            {
                //包
                #region GeometryBag
                GeometryBagClass    objgeobag = new GeometryBagClass();
                IGeometryBag        geoBag    = sourceGeometry as IGeometryBag;
                IGeometryCollection geoColl   = geoBag as IGeometryCollection;
                IGeometry           geo       = null;
                IGeometry           objgeo    = null;
                object miss = Type.Missing;
                IGeometryCollection objgeobagColl = objgeobag as IGeometryCollection;
                for (int i = 0; i < geoColl.GeometryCount; i++)
                {
                    geo    = geoColl.get_Geometry(i);
                    objgeo = this.getObjectGeometry(geo, SourceProjection, SourceStrip, L0, IsBigNumber_Source,
                                                    ObjectProjection, ObjectStrip, IsBigNumber_Object, ObjectSpatialReference);
                    objgeo.SpatialReference = ObjectSpatialReference;
                    objgeobagColl.AddGeometry(objgeo, ref miss, ref miss);
                }
                objgeobag.SpatialReference = ObjectSpatialReference;
                ObjGeometry = objgeobag as IGeometry;
                #endregion
            }
            else if (sourceGeometry is IMultipoint)
            {
                //多点
                #region Multipoint
                MultipointClass  objMuliPoint = new MultipointClass();
                IPointCollection objPc        = objMuliPoint as IPointCollection;
                double           x            = 0;
                double           y            = 0;
                double           B            = 0;
                double           L            = 0;
                IPointCollection pcol         = sourceGeometry as IPointCollection;
                object           miss         = Type.Missing;
                for (int j = 0; j < pcol.PointCount; j++)
                {
                    p = pcol.get_Point(j);
                    x = p.X;
                    y = p.Y;
                    this.GetBLFromXY(y, x, ref B, ref L, 0, SourceProjection, SourceStrip, L0, IsBigNumber_Source);

                    this.GetXYFromBL(B, L, ref x, ref y, 0, ObjectProjection, ObjectStrip, IsBigNumber_Object);
                    IPoint objPoint = new PointClass();
                    objPoint.X = y;
                    objPoint.Y = x;
                    objPoint.SpatialReference = ObjectSpatialReference;
                    objPc.AddPoint(objPoint, ref miss, ref miss);
                }
                objMuliPoint.SpatialReference = ObjectSpatialReference;
                ObjGeometry = objMuliPoint as IGeometry;
                #endregion
            }
            else
            {
                //暂未写
                ObjGeometry = null;
            }

            return(ObjGeometry);
        }
        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;
            }
        }
Example #35
0
        public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY)
        {
            interPoints = new List <IntersectPoint>();
            DF2DApplication app   = DF2DApplication.Application;
            bool            ready = true;

            if (app == null || app.Current2DMapControl == null)
            {
                return;
            }
            m_ActiveView = app.Current2DMapControl.ActiveView;
            IScreenDisplay   m_Display = app.Current2DMapControl.ActiveView.ScreenDisplay;
            IGeometry        pGeo      = null;
            IPointCollection pIntersectPC;
            IPointCollection pLandSufPC;
            double           length = 0.0;
            IPoint           fPoint;
            string           mapNum  = "";
            string           mapName = Config.GetConfigValue("SystemName") + "横断面图";

            try
            {
                if (button == 1)
                {
                    ISimpleLineSymbol pLineSym = new SimpleLineSymbol();
                    IRgbColor         pColor   = new RgbColorClass();
                    pColor.Red     = 255;
                    pColor.Green   = 255;
                    pColor.Blue    = 0;
                    pLineSym.Color = pColor;
                    pLineSym.Style = esriSimpleLineStyle.esriSLSSolid;
                    pLineSym.Width = 2;

                    IRubberBand pRubberBand;
                    pRubberBand = new RubberLineClass();
                    IGeometry pLine;
                    pLine = pRubberBand.TrackNew(m_Display, null);

                    object symbol = pLineSym as object;
                    app.Current2DMapControl.DrawShape(pLine, ref symbol);

                    WaitForm.Start("正在查询...", "请稍后");
                    //pGeo = PublicFunction.DoBuffer(pLine,PublicFunction.ConvertPixelsToMapUnits(m_ActiveView, GlobalValue.System_Selection_Option().Tolerate));
                    pGeo = pLine;
                    if (pGeo == null)
                    {
                        return;
                    }
                    length = (pGeo as IPolyline).Length;
                    fPoint = (pGeo as IPolyline).FromPoint;
                    mapNum = getMapNumforPnt(fPoint);

                    if (ready)
                    {
                        double distemp   = 0.0;
                        IPoint tempPoint = null;
                        //foreach (LogicGroup lg in LogicDataStructureManage2D.Instance.RootLogicGroups)
                        foreach (MajorClass mc in LogicDataStructureManage2D.Instance.GetAllMajorClass())
                        {
                            foreach (SubClass sc in mc.SubClasses)
                            {
                                if (!sc.Visible2D)
                                {
                                    continue;
                                }
                                string[] arrFc2DId = mc.Fc2D.Split(';');
                                if (arrFc2DId == null)
                                {
                                    continue;
                                }
                                IFeatureCursor pFeatureCursor = null;
                                IFeature       pFeature       = null;
                                foreach (string fc2DId in arrFc2DId)
                                {
                                    DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId);
                                    if (dffc == null)
                                    {
                                        continue;
                                    }
                                    IFeatureClass fc   = dffc.GetFeatureClass();
                                    FacilityClass facc = dffc.GetFacilityClass();
                                    if (facc.Name != "PipeLine")
                                    {
                                        continue;
                                    }
                                    if (fc == null || pGeo == null)
                                    {
                                        continue;
                                    }
                                    ISpatialFilter pSpatialFilter = new SpatialFilter();
                                    pSpatialFilter.Geometry   = pGeo;
                                    pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                    //pSpatialFilter.WhereClause =sc.Parent.ClassifyField + " =  '" + sc.Name + "'";
                                    pSpatialFilter.WhereClause = mc.ClassifyField + " =  '" + sc.Name + "'";
                                    int count = fc.FeatureCount(pSpatialFilter);
                                    if (count == 0)
                                    {
                                        continue;
                                    }
                                    pFeatureCursor = fc.Search(pSpatialFilter, false);
                                    string fcName = mc.Name;
                                    if (pFeatureCursor == null)
                                    {
                                        continue;
                                    }
                                    double distance;

                                    while ((pFeature = pFeatureCursor.NextFeature()) != null)
                                    {
                                        IGeometry            pPipeLineGeo = pFeature.Shape;
                                        ITopologicalOperator pTopo        = pPipeLineGeo as ITopologicalOperator;
                                        IGeometry            geo          = pTopo.Intersect(pGeo, esriGeometryDimension.esriGeometry0Dimension);
                                        IPoint intersect;
                                        if (geo is IPoint)
                                        {
                                            double distanceF = double.MaxValue;
                                            intersect = geo as IPoint;
                                            if (pGeo is IPolyline)
                                            {
                                                IPolyline line      = pGeo as IPolyline;
                                                IPoint    fromPoint = line.FromPoint;
                                                distanceF = GetDistanceOfTwoPoints(intersect, fromPoint);
                                            }
                                            if (distemp == 0.0)
                                            {
                                                distance = distanceF;
                                                distemp  = distanceF;
                                            }
                                            else
                                            {
                                                distance = Math.Abs(distanceF - distemp);
                                            }
                                            IntersectPoint interPoint = new IntersectPoint(pFeature, intersect, fcName, distance, distanceF);
                                            interPoints.Add(interPoint);
                                        }
                                        if (geo is IPointCollection)
                                        {
                                            IPointCollection geoCol = geo as IPointCollection;
                                            for (int i = 0; i < geoCol.PointCount; i++)
                                            {
                                                intersect = geoCol.get_Point(i) as IPoint;
                                                double distanceF = double.MaxValue;

                                                if (pGeo is IPolyline)
                                                {
                                                    IPolyline line = pGeo as IPolyline;

                                                    IPoint fromPoint = line.FromPoint;
                                                    IPoint toPoint   = line.ToPoint;
                                                    if (distemp == 0.0)
                                                    {
                                                        double distance1 = GetDistanceOfTwoPoints(intersect, fromPoint);
                                                        double distance2 = GetDistanceOfTwoPoints(intersect, toPoint);
                                                        distanceF = distance1 < distance2 ? distance1 : distance2;
                                                        tempPoint = distance1 < distance2 ? fromPoint : toPoint;
                                                    }
                                                    else
                                                    {
                                                        if (tempPoint == null)
                                                        {
                                                            return;
                                                        }
                                                        distanceF = GetDistanceOfTwoPoints(intersect, tempPoint);
                                                    }
                                                }
                                                if (distemp == 0.0)
                                                {
                                                    distance = distanceF;
                                                    distemp  = distanceF;
                                                }
                                                else
                                                {
                                                    distance = Math.Abs(distanceF - distemp);
                                                }
                                                IntersectPoint interPoint = new IntersectPoint(pFeature, intersect, fcName, distance, distanceF);
                                                interPoints.Add(interPoint);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                DrawPipeTransection(interPoints, mapNum, mapName);
            }
            catch (System.Exception ex)
            {
            }
        }
 private void drawpoints(IPointCollection ippoints)
 {
     IGraphicsContainer pgraghicscontainer = axMapControl1.Map as IGraphicsContainer;
     IActiveView pactiveview = pgraghicscontainer as ESRI.ArcGIS.Carto.IActiveView;
     //设定路径颜色
     IRgbColor pcolor = new RgbColorClass();
     pcolor.Red = 255;
     pcolor.Green = 0;
     pcolor.Blue = 0;
     pcolor.Transparency = 100;
     //设置线格式
     ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass();
     simpleMarkerSymbol.Color = pcolor;
     simpleMarkerSymbol.Size = 4;
     //绘出路径线
     IScreenDisplay screenDisplay = pactiveview.ScreenDisplay;
     ISymbol symbol = (ISymbol)simpleMarkerSymbol;
     screenDisplay.StartDrawing(screenDisplay.hDC, System.Convert.ToInt16(esriScreenCache.esriNoScreenCache));
     screenDisplay.SetSymbol(symbol);
     int i;
     for (i = 0; i < ippoints.PointCount; i++)
     {
         screenDisplay.DrawPoint(ippoints.get_Point(i));
     }
     screenDisplay.FinishDrawing();
 }
        /// <summary>
        /// 求解最短路径
        /// </summary>
        /// <param name="_pMap"></param>
        /// <param name="_pGeometricNetwork"></param>
        /// <param name="_pWeightName"></param>
        /// <param name="_pPoints"></param>
        /// <param name="_pDist"></param>
        /// <param name="_pPolyline"></param>
        /// <param name="_pPathCost"></param>
        public void SolvePath(IMap _pMap, IGeometricNetwork _pGeometricNetwork, string _pWeightName, IPointCollection _pPoints, double _pDist, ref IPolyline _pPolyline, ref double _pPathCost)
        {
            try
            { // 这4个参数其实就是一个定位Element的指标
                int intEdgeUserClassID;

                int intEdgeUserID;

                int intEdgeUserSubID;

                int intEdgeID;

                IPoint pFoundEdgePoint;

                double dblEdgePercent;

                ITraceFlowSolverGEN pTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN;

                INetSolver pNetSolver = pTraceFlowSolver as INetSolver;

                //操作是针对逻辑网络的,INetwork是逻辑网络

                INetwork pNetwork = _pGeometricNetwork.Network;

                pNetSolver.SourceNetwork = pNetwork;

                INetElements pNetElements = pNetwork as INetElements;

                int pCount = _pPoints.PointCount;
                //定义一个边线旗数组
                IEdgeFlag[] pEdgeFlagList = new EdgeFlagClass[pCount];

                IPointToEID pPointToEID = new PointToEIDClass();

                pPointToEID.SourceMap = _pMap;

                pPointToEID.GeometricNetwork = _pGeometricNetwork;

                pPointToEID.SnapTolerance = _pDist;

                for (int i = 0; i < pCount; i++)
                {
                    INetFlag pNetFlag = new EdgeFlagClass() as INetFlag;

                    IPoint pEdgePoint = _pPoints.get_Point(i);
                    //查找输入点的最近的边线
                    pPointToEID.GetNearestEdge(pEdgePoint, out intEdgeID, out pFoundEdgePoint, out dblEdgePercent);

                    pNetElements.QueryIDs(intEdgeID, esriElementType.esriETEdge, out intEdgeUserClassID, out intEdgeUserID, out intEdgeUserSubID);

                    pNetFlag.UserClassID = intEdgeUserClassID;

                    pNetFlag.UserID = intEdgeUserID;

                    pNetFlag.UserSubID = intEdgeUserSubID;

                    IEdgeFlag pTemp = (IEdgeFlag)(pNetFlag as IEdgeFlag);
                    pEdgeFlagList[i] = pTemp;
                }
                pTraceFlowSolver.PutEdgeOrigins(ref pEdgeFlagList);

                INetSchema pNetSchema = pNetwork as INetSchema;

                INetWeight pNetWeight = pNetSchema.get_WeightByName(_pWeightName);

                INetSolverWeightsGEN pNetSolverWeights = pTraceFlowSolver as INetSolverWeightsGEN;

                pNetSolverWeights.FromToEdgeWeight = pNetWeight;//开始边线的权重

                pNetSolverWeights.ToFromEdgeWeight = pNetWeight;//终止边线的权重

                object[] pRes = new object[pCount - 1];

                //通过FindPath得到边线和交汇点的集合
                IEnumNetEID  pEnumNetEID_Junctions;

                IEnumNetEID pEnumNetEID_Edges;

                pTraceFlowSolver.FindPath(esriFlowMethod.esriFMConnected,
                 esriShortestPathObjFn.esriSPObjFnMinSum,
                 out pEnumNetEID_Junctions, out pEnumNetEID_Edges, pCount - 1, ref pRes);
                //计算元素成本
                _pPathCost = 0;
                for (int i = 0; i < pRes.Length; i++)
                {
                    double m_Va = (double)pRes[i];

                    _pPathCost = _pPathCost + m_Va;
                }

                IGeometryCollection pNewGeometryColl = _pPolyline as IGeometryCollection;//QI

                ISpatialReference pSpatialReference = _pMap.SpatialReference;

                IEIDHelper pEIDHelper = new EIDHelperClass();

                pEIDHelper.GeometricNetwork = _pGeometricNetwork;

                pEIDHelper.OutputSpatialReference = pSpatialReference;

                pEIDHelper.ReturnGeometries = true;

                IEnumEIDInfo pEnumEIDInfo = pEIDHelper.CreateEnumEIDInfo(pEnumNetEID_Edges);

                int Count = pEnumEIDInfo.Count;

                pEnumEIDInfo.Reset();

                for (int i = 0; i < Count; i++)
                {
                    IEIDInfo pEIDInfo = pEnumEIDInfo.Next();

                    IGeometry pGeometry = pEIDInfo.Geometry;

                    pNewGeometryColl.AddGeometryCollection(pGeometry as IGeometryCollection);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }