Example #1
0
 private void openGeoNetwork()
 {
     string [email protected]"C:\ArcGIS91_Demos\Sewer9\data\sewer3.mdb";
     IFeatureWorkspace pFWS=Utility.openPDB(fpath);
     IFeatureDataset pFdataset=pFWS.OpenFeatureDataset("urban");
     INetworkCollection pNetworkCollection=pFdataset as INetworkCollection;
     //�õ�Sewer Network����TRACE
     pGeometricNetwork=pNetworkCollection.get_GeometricNetworkByName("Sewer_Network");
 }
        /// <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);
            }
        }
 //初始化
 private bool InitializeNetworkAndMap(IFeatureDataset Featuredataset,System.Collections.ArrayList array1,System.Collections.ArrayList array2,int flag)
 {
     IFeatureClassContainer ipFeatureClassContainer;
     IFeatureClass ipFeatureClass;
     IGeoDataset ipGeoDataset;
     ILayer ipLayer;
     IFeatureLayer ipFeatureLayer;
     IEnvelope ipEnvelope, ipMaxEnvelope;
     double dblSearchTol;
     INetworkCollection ipNetworkCollection = Featuredataset as INetworkCollection;
     int count = ipNetworkCollection.GeometricNetworkCount;
     barrierarray1 =(System.Collections.ArrayList)array1.Clone();
     barrierarray2 = (System.Collections.ArrayList)array2.Clone();
     barrierflag = flag;
     //获取几何网络工作空间
     m_ipGeometricNetwork = ipNetworkCollection.get_GeometricNetwork(0);
     INetwork ipNetwork = m_ipGeometricNetwork.Network;
     if (m_ipMap != null)
     {
         m_ipMap = new MapClass();
         ipFeatureClassContainer = m_ipGeometricNetwork as IFeatureClassContainer;
         count = ipFeatureClassContainer.ClassCount;
         for (int i = 0; i < count; i++)
         {
             ipFeatureClass = ipFeatureClassContainer.get_Class(i);
             ipFeatureLayer = new FeatureLayerClass();
             ipFeatureLayer.FeatureClass = ipFeatureClass;
             m_ipMap.AddLayer(ipFeatureLayer);
         }
     }
     count = m_ipMap.LayerCount;
     ipMaxEnvelope = new EnvelopeClass();
     for (int i = 0; i < count; i++)
     {
         ipLayer = m_ipMap.get_Layer(i);
         ipFeatureLayer = ipLayer as IFeatureLayer;
         ipGeoDataset = ipFeatureLayer as IGeoDataset;
         ipEnvelope = ipGeoDataset.Extent;
         ipMaxEnvelope.Union(ipEnvelope);
     }
     m_ipPointToEID = new PointToEIDClass();
     m_ipPointToEID.SourceMap = m_ipMap;
     m_ipPointToEID.GeometricNetwork = m_ipGeometricNetwork;
     double dblWidth = ipMaxEnvelope.Width;
     double dblHeight = ipMaxEnvelope.Height;
     if (dblWidth > dblHeight)
         dblSearchTol = dblWidth / 100;
     else
         dblSearchTol = dblHeight / 100;
     m_ipPointToEID.SnapTolerance = dblSearchTol;
     return true;
 }
Example #4
0
        //����׷�ٵĽ��
        public static void FindStreamTraceResult(AxMapControl ppAxMapControl, INetFlag ipNetFlag, IGeometricNetwork pGeoNetwork)
        {
            try
            {

                IEnumNetEID m_ipEnumNetEID_Junctions, m_ipEnumNetEID_Edges;//����������������Junctions��Edges
                IJunctionFlag[] pArrayJFlag = new IJunctionFlag[1];
                pArrayJFlag[0] = ipNetFlag as IJunctionFlag;
                ITraceFlowSolverGEN ipTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN;

                //get the inetsolver interface
                INetSolver ipNetSolver = ipTraceFlowSolver as INetSolver;
                ipNetSolver.SourceNetwork = pGeoNetwork.Network;

                ipTraceFlowSolver.PutJunctionOrigins(ref pArrayJFlag);

                ipTraceFlowSolver.TraceIndeterminateFlow = false;

                object[] totalCost = new object[1];

                //ipTraceFlowSolver.FindSource(esriFlowMethod.esriFMUpstream,esriShortestPathObjFn.esriSPObjFnMinSum,out m_ipEnumNetEID_Junctions,out m_ipEnumNetEID_Edges,1,ref totalCost);

                ipTraceFlowSolver.FindFlowElements(esriFlowMethod.esriFMUpstream,
                    esriFlowElements.esriFEEdges,
                    out m_ipEnumNetEID_Junctions,
                    out m_ipEnumNetEID_Edges);

                //ma
                //SpatialHelperFunction.pathToPolyline(pGeoNetwork, ppAxMapControl.ActiveView, m_ipEnumNetEID_Edges);
                //UpStreamFindParcels(ppAxMapControl, m_ipEnumNetEID_Edges,pGeoNetwork);
            }
            catch (Exception eX)
            {
                MessageBox.Show(eX.Message);

            }
        }
Example #5
0
        //��˷׷�ٲ��ҹ����漰�ĵؿ�
        public static void UpStreamFindParcels(AxMapControl ppAxMapControl, IEnumNetEID pEnumResultEdges, IGeometricNetwork pGeoNetwork)
        {
            try
            {

                IFeatureLayer pFeatLayerSewerLines = FindFeatLayer("Sewer Lines", ppAxMapControl);
                IFeatureLayer pFeatLayerParcels = FindFeatLayer("Parcels", ppAxMapControl);
                //����ѡ���Sewer�������д������ΰ�

                IGeometryCollection pGeomBag = new GeometryBagClass();
                object missing = Type.Missing;
                int lEID;
                int iUserClassID;
                int iUserID;
                int iUserSubID;
                INetElements pNetElements = pGeoNetwork.Network as INetElements;
                pEnumResultEdges.Reset();
                IFeature pFeature;

                for (int j = 0; j <= pEnumResultEdges.Count - 1; j++)
                {
                    lEID = pEnumResultEdges.Next();
                    pNetElements.QueryIDs(lEID, esriElementType.esriETEdge, out iUserClassID, out iUserID, out iUserSubID);
                    pFeature = pFeatLayerSewerLines.FeatureClass.GetFeature(iUserID);
                    pGeomBag.AddGeometry(pFeature.Shape, ref missing, ref missing);
                    // MessageBox.Show(iUserClassID.ToString()+","+iUserID.ToString()+","+iUserSubID.ToString());
                }
                //���пռ����˵��Ӳ��������ڲ��ҵؿ���Ϣ
                ISpatialFilter pSpatialFilter = new SpatialFilterClass();
                pSpatialFilter.Geometry = pGeomBag as IGeometry;
                pSpatialFilter.GeometryField = "Shape";
                pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                pSpatialFilter.SearchOrder = esriSearchOrder.esriSearchOrderSpatial;

                //��ý��浽�ĵؿ���Ϣ
                IFeatureCursor pFeatCursor = pFeatLayerParcels.FeatureClass.Search(pSpatialFilter, false);
                //���ӱ�ѡ��ĵؿ����ݵ���ͼ��ͼ��ͼ��������
                ICompositeGraphicsLayer pComGraphicLayer = new CompositeGraphicsLayerClass();
                ILayer pLayer = pComGraphicLayer as ILayer;
                pLayer.Name = "��Ӱ��ĵؿ�";
                IGraphicsContainer pGraphicContainer = pComGraphicLayer as IGraphicsContainer;
                //������ѡ��ĵؿ鵽ͼ��������
                ISimpleFillSymbol pSymFill = new SimpleFillSymbolClass();
                IFillSymbol pFillSymbol = pSymFill as IFillSymbol;
                IRgbColor pRgbColor = new RgbColorClass();
                pRgbColor.Red = 0;
                pRgbColor.Green = 200;
                pRgbColor.Blue = 100;
                pFillSymbol.Color = pRgbColor as IColor;
                ICartographicLineSymbol pCartoLine = new CartographicLineSymbolClass();
                IRgbColor pRgbColor2 = new RgbColorClass();
                pRgbColor2.Red = 100;
                pRgbColor2.Green = 200;
                pRgbColor2.Blue = 100;
                pCartoLine.Width = 2;
                pCartoLine.Color = pRgbColor2 as IColor;
                pFillSymbol.Outline = pCartoLine;
                //����������еؿ�����������
                IArray pFeatArray = new ArrayClass();
                pFeature = pFeatCursor.NextFeature();
                while (pFeature != null)
                {
                    IElement pPolyElement = new PolygonElementClass();
                    IFillShapeElement pFillShapeElement = pPolyElement as IFillShapeElement;
                    pPolyElement.Geometry = pFeature.Shape;
                    pFillShapeElement.Symbol = pFillSymbol;
                    pGraphicContainer.AddElement(pPolyElement, 0);
                    pFeatArray.Add(pFeature);
                    pFeature = pFeatCursor.NextFeature();
                }
                ppAxMapControl.AddLayer(pGraphicContainer as ILayer);
                ppAxMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
                //ma
                //frmUpstreamCreateOwnerList frmUpstreamCreateOwnerList1 = new frmUpstreamCreateOwnerList(ppAxMapControl,pFeatLayerParcels, pFeatArray);
                //frmUpstreamCreateOwnerList1.Show();
            }
            catch (Exception eX)
            {
                MessageBox.Show(eX.Message);

            }
        }
Example #6
0
        //�������ĸ߳�����
        public static void ProfileGetRelatedSewerElevData(AxMapControl ppAxMapControl, IGeometricNetwork pGeoNetwork, IEnumNetEID pResultEdges, IEnumNetEID pResultJunctions)
        {
            try
            {
                //��ñ������Զ�Ӧ������׷�ٽ��
                IArray pSewerElevArray = new ArrayClass();
                IEIDHelper pEIDHelper = new EIDHelperClass();
                pEIDHelper.GeometricNetwork = pGeoNetwork;
                pEIDHelper.ReturnFeatures = true;
                pEIDHelper.ReturnGeometries = true;
                pEIDHelper.PartialComplexEdgeGeometry = true;
                pEIDHelper.AddField("Component_Key2");
                IEnumEIDInfo pEnumEIDInfo = pEIDHelper.CreateEnumEIDInfo(pResultEdges);
                //�������߻�����ص������߼�¼
                pEnumEIDInfo.Reset();
                IEIDInfo pEIDInfo = pEnumEIDInfo.Next();
                IFeature pFeature = pEIDInfo.Feature;
                IGeometry pFeatGeo = pEIDInfo.Geometry;
                //�������л�ù�ϵ
                IEnumRelationshipClass pEnumRelationshipCls = pFeature.Class.get_RelationshipClasses(esriRelRole.esriRelRoleOrigin);
                pEnumRelationshipCls.Reset();
                IRelationshipClass pRelationshipCls = pEnumRelationshipCls.Next();
                //�����ȷ�Ĺ�ϵ��
                string s = "SewerToMainline";
                while (pRelationshipCls != null)
                {
                    if (pRelationshipCls.ForwardPathLabel.ToUpper() == s.ToUpper())
                        break;
                    else
                        pRelationshipCls = pEnumRelationshipCls.Next();
                }
                //��ѯ���ɹ�����ÿ������ص����ݣ������1-1�Ĺ�ϵ����ֻ����һ����¼
                //  because the arcs are ordered and directional, if the start node is an
                //  fnode then get subsequent tnode's for the rest of the arcs, else if the
                //  start node is a tnode, get subsequent fnode's.  Related data has elev
                //  attributes for up and down stream manhole elevs, so related to from and to node of arc.
                // get the first junction in the network trace results to determine if the
                //first junction is a from-node or a to-node for graphing sewer line elev
                if (pRelationshipCls != null)
                {
                    ISet pMainlineRelatedSet;
                    IRow pMainlineRow;
                    IEIDHelper pEIDHelper2 = new EIDHelperClass();
                    pEIDHelper2.GeometricNetwork = pGeoNetwork;
                    pEIDHelper2.ReturnFeatures = true;
                    pEIDHelper2.ReturnGeometries = true;
                    pEIDHelper2.PartialComplexEdgeGeometry = true;
                    IEnumEIDInfo pEnumEIDInfo2 = pEIDHelper2.CreateEnumEIDInfo(pResultJunctions);
                    pEnumEIDInfo2.Reset();
                    //pFeature is the first arc in the network trace results
                    // check the junctions on the first arc to see which is the starting
                    // junction, this determines which sewer elev attribute (ups_elev, dwn_elev)
                    // will be used to calculate the sewer line profile
                    IEdgeFeature pEdgeFeat = pFeature as IEdgeFeature;
                    string strStartAttr;
                    string strMHelevAttr;
                    double lastelev = 0;
                    int lastnodeEID;
                    if (pEnumEIDInfo2.Next().EID == pEdgeFeat.FromJunctionEID)
                    {
                        // trace is in the direction of flow, flow goes down hill
                        strStartAttr = "Ups_elev";
                        strMHelevAttr = "Dwn_elev";
                    }
                    else
                    {
                        //trace is in the opposite direction of flow, flow goes up hill
                        strStartAttr = "Dwn_elev";
                        strMHelevAttr = "Ups_elev";
                    }
                    lastnodeEID = pEnumEIDInfo2.Next().EID;
                    // create a polyline from the result junctions, make the polyline in the
                    //direction of the trace, not in the direction of the original arcs/edges
                    IPolyline pPolyline = new PolylineClass();
                    IPointCollection pPointColl = pPolyline as IPointCollection;
                    pEnumEIDInfo2.Reset();
                    object missing = Type.Missing;
                    for (int i = 0; i <= pEnumEIDInfo2.Count - 1; i++)
                    {
                        pPointColl.AddPoint(pEnumEIDInfo2.Next().Geometry as IPoint, ref missing, ref missing);
                    }
                    ISegmentCollection pSegColl = pPolyline as ISegmentCollection;
                    //�򻯶����
                    ITopologicalOperator pTopoOp = pPolyline as ITopologicalOperator;
                    pTopoOp.Simplify();
                    pPolyline.SimplifyNetwork();
                    pPolyline.Densify(50, 0.01);
                    pResultEdges.Reset();
                    pEnumEIDInfo2.Reset();
                    IPolyline pNewSegPolyline;
                    IPolyline pPolyLineFeat;
                    IRelationalOperator pRelOpFeat;
                    ISegmentCollection pNewSegColl;
                    ISegmentCollection pSegmentColl = pPolyline as ISegmentCollection;
                    for (int i = 0; i <= pResultEdges.Count - 1; i++)
                    {
                        pMainlineRelatedSet = pRelationshipCls.GetObjectsRelatedToObject(pFeature);
                        pMainlineRelatedSet.Reset();
                        pMainlineRow = pMainlineRelatedSet.Next() as IRow;
                        pPolyLineFeat = pFeature.Shape as IPolyline;
                        pRelOpFeat = pPolyLineFeat as IRelationalOperator;
                        for (int j = 0; j <= pSegmentColl.SegmentCount - 1; j++)
                        {
                            pNewSegPolyline = new PolylineClass();
                            pNewSegColl = pNewSegPolyline as ISegmentCollection;
                            pNewSegColl.AddSegment(pSegmentColl.get_Segment(j), ref missing, ref missing);
                            if (pRelOpFeat.Contains(pNewSegPolyline as IGeometry))
                            {
                                if (j == 0)
                                {
                                    pSewerElevArray.Add(pMainlineRow.get_Value(pMainlineRow.Fields.FindField(strStartAttr)));
                                    lastelev = Convert.ToDouble(pMainlineRow.get_Value(pMainlineRow.Fields.FindField(strMHelevAttr)));
                                }
                                else
                                {
                                    if (lastelev == Convert.ToDouble(pMainlineRow.get_Value(pMainlineRow.Fields.FindField(strMHelevAttr))))
                                    {
                                        pSewerElevArray.Add(-99);
                                    }
                                    else
                                    {
                                        pSewerElevArray.Add(lastelev);
                                        lastelev = Convert.ToDouble(pMainlineRow.get_Value(pMainlineRow.Fields.FindField(strMHelevAttr)));
                                    }
                                }
                            }
                        }
                        // get the next feature and check to see what direction it's going and
                        //adjust the variables accordingly
                        if (i < pResultEdges.Count - 1)
                        {
                            lastnodeEID = pEdgeFeat.ToJunctionEID;
                            pFeature = pEnumEIDInfo.Next().Feature;
                            pEdgeFeat = pFeature as IEdgeFeature;
                            if (pEdgeFeat.FromJunctionEID == lastnodeEID)
                                strMHelevAttr = "Dwn_elev";
                            else
                                strMHelevAttr = "Ups_elev";

                        }
                        else
                        {
                            pSewerElevArray.Add(pMainlineRow.get_Value(pMainlineRow.Fields.FindField(strMHelevAttr)));

                        }
                    }
                    ProfileCreateGraph(ppAxMapControl, pPolyline, pSewerElevArray);
                }
            }
            catch (Exception eX)
            {
                MessageBox.Show(eX.Message);

            }
        }
        private static void ProfileGetRelatedElevData(IApplication app, List<ProfileGraphDetails> ProfileGraph, IGeometricNetwork pGeometricNet,
                  IEnumNetEID pResultEdges, IEnumNetEID pResultJunctions, int CurrentDetail,
                  ref IFeatureLayer pFLManhole, ref IFeatureLayer pFLMain, ref IFeatureLayer pFLTap)
        {
            List<mainDetails> SewerColMains = null;
            List<manholeDetails> SewerColManholes = null;
            List<tapDetails> SewerColTap = null;

            IEIDHelper pEIDHelperEdges = null;
            IEnumEIDInfo pEnumEIDInfoEdges = null;

            IEIDHelper pEIDHelperJunctions = null;
            IEnumEIDInfo pEnumEIDInfoJunctions = null;

            IPolyline pPolyline = null;
            IPointCollection pPtColl = null;

            IEIDInfo pEIDInfo = null;
            IPoint pNewPt = null;
            ISegmentCollection pSegColl = null;
            IMSegmentation pMSegmentation = null;
            IMAware pMAware = null;

            IPointCollection pPtCollection = null;
            IEnumVertex pEnumVertex;

            IHitTest pHtTest = null;
            IPoint pHitPntOne = null;
            IPoint pHitPntTwo = null;
            IFeature pFeature = null;
            Hashtable pFeatureAdded = null;
            mainDetails mainDet = null;

            IEdgeFeature pEdge = null;

            IPoint pGeoOne = null;
            IPoint pGeoTwo = null;
            IField pFld = null;
            IJunctionFeature pJunc = null;
            tapDetails tapDet = null;
            manholeDetails manDet = null;
            IFeatureLayer pFl = null;
            ISpatialFilter pSpatFilt = null;
            IFeatureCursor pFC = null;

            try
            {

                SewerColMains = new List<mainDetails>();
                SewerColManholes = new List<manholeDetails>();
                SewerColTap = new List<tapDetails>();

                pEIDHelperEdges = new EIDHelper();
                pEIDHelperEdges.GeometricNetwork = pGeometricNet;
                pEIDHelperEdges.ReturnFeatures = true;

                pEIDHelperEdges.ReturnGeometries = true;
                pEIDHelperEdges.PartialComplexEdgeGeometry = true;
                pEnumEIDInfoEdges = pEIDHelperEdges.CreateEnumEIDInfo(pResultEdges);

                pEnumEIDInfoEdges.Reset();  //edges

                pEIDHelperJunctions = new EIDHelperClass();
                pEIDHelperJunctions.GeometricNetwork = pGeometricNet;
                pEIDHelperJunctions.ReturnFeatures = true;
                pEIDHelperJunctions.ReturnGeometries = true;
                pEIDHelperJunctions.PartialComplexEdgeGeometry = true;
                pEnumEIDInfoJunctions = pEIDHelperJunctions.CreateEnumEIDInfo(pResultJunctions);
                pEnumEIDInfoJunctions.Reset();// junctions

                pPolyline = new PolylineClass();
                pPolyline.SpatialReference = (pFLMain as IGeoDataset).SpatialReference;

                pPtColl = (IPointCollection)pPolyline;  //QI

                for (int i = 0; i < pEnumEIDInfoJunctions.Count; i++)
                {

                    pEIDInfo = pEnumEIDInfoJunctions.Next();
                    pNewPt = (IPoint)pEIDInfo.Geometry;

                    pPtColl.AddPoint(pNewPt);

                }

                pSegColl = (ISegmentCollection)pPolyline;

                pPolyline.Densify(50, 0.01);

                pMAware = (IMAware)pPolyline;//'QI
                pMAware.MAware = true;
                pMSegmentation = (IMSegmentation)pPolyline;
                // get the M values, put the distance in m, 0 to Length
                pMSegmentation.SetMsAsDistance(false);

                pPtCollection = (IPointCollection)pPolyline;

                pEnumVertex = pPtCollection.EnumVertices;
                pEnumVertex.Reset();

                pHtTest = pPolyline as IHitTest;

                pHitPntOne = new PointClass();
                pHitPntTwo = new PointClass();
                double pHitDistOne = -1;
                double pHitDistTwo = -1;
                int pHitPrtOne = -1;
                int pHitPrtTwo = -1;
                int pHitSegOne = -1;
                int pHitSegTwo = -1;
                bool pHitSideOne = false;
                bool pHitSideTwo = false;

                pFeatureAdded = new Hashtable();

                pEnumEIDInfoEdges.Reset();  //edges
                int intUpStreamFld = pFLMain.FeatureClass.Fields.FindField(ProfileGraph[CurrentDetail].Line_UpStreamElevationField);
                int intDownStreamFld = pFLMain.FeatureClass.Fields.FindField(ProfileGraph[CurrentDetail].Line_DownStreamElevationField);
                if (intDownStreamFld < 0)
                {
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19c") + ProfileGraph[CurrentDetail].Line_DownStreamElevationField + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19b"));
                }
                if (intUpStreamFld < 0)
                {
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19d") + ProfileGraph[CurrentDetail].Line_UpStreamElevationField + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19b"));
                }
                for (int i = 0; i < pResultEdges.Count; i++)
                {
                    pEIDInfo = pEnumEIDInfoEdges.Next();
                    pFeature = pEIDInfo.Feature;
                    if (((IDataset)pFeature.Class).Name != ((IDataset)pFLMain.FeatureClass).Name)
                        continue;
                    if (pFeatureAdded.ContainsValue(pFeature.OID))
                        continue;

                    mainDet = new mainDetails();

                    pEdge = (IEdgeFeature)pFeature;

                    pGeoOne = (IPoint)pEdge.FromJunctionFeature.get_OriginalGeometryForJunctionElement(0);
                    pGeoTwo = (IPoint)pEdge.ToJunctionFeature.get_OriginalGeometryForJunctionElement(0);

                    pFeature = ((IFeatureClass)pFeature.Class).GetFeature(pFeature.OID);

                    bool bHitOne = pHtTest.HitTest(pGeoOne, .1,
                                            esriGeometryHitPartType.esriGeometryPartVertex,
                                            pHitPntOne, ref pHitDistOne, ref pHitPrtOne, ref pHitSegOne, ref pHitSideOne);
                    bool bHitTwo = pHtTest.HitTest(pGeoTwo, .1,
                                   esriGeometryHitPartType.esriGeometryPartVertex,
                                   pHitPntTwo, ref pHitDistTwo, ref pHitPrtTwo, ref pHitSegTwo, ref pHitSideTwo);
                    if (bHitOne && bHitTwo)
                    {
                        if (pHitPntOne.M < pHitPntTwo.M)
                        {
                            mainDet.UpM = pHitPntOne.M;
                            mainDet.DownM = pHitPntTwo.M;
                            if (intUpStreamFld > 0)
                            {
                                if (pFeature.get_Value(intUpStreamFld).ToString() != "")
                                {
                                    mainDet.UpElev = Convert.ToDouble(pFeature.get_Value(intUpStreamFld));
                                }
                                else
                                    mainDet.UpElev = -9999;
                            }
                            else
                                mainDet.UpElev = -9999;

                            if (intDownStreamFld > 0)
                            {
                                if (pFeature.get_Value(intDownStreamFld).ToString() != "")
                                {
                                    mainDet.DownElev = Convert.ToDouble(pFeature.get_Value(intDownStreamFld));
                                }
                                else
                                    mainDet.DownElev = -9999;
                            }
                            else
                                mainDet.DownElev = -9999;
                        }
                        else
                        {
                            mainDet.DownM = pHitPntOne.M;
                            mainDet.UpM = pHitPntTwo.M;
                            if (intUpStreamFld > 0)
                            {
                                if (pFeature.get_Value(intUpStreamFld) != null && pFeature.get_Value(intUpStreamFld).ToString() != "")
                                {
                                    mainDet.DownElev = Convert.ToDouble(pFeature.get_Value(intUpStreamFld));
                                }
                                else
                                    mainDet.DownElev = -9999;
                            }
                            else
                                mainDet.DownElev = -9999;

                            if (intDownStreamFld > 0)
                            {
                                if (pFeature.get_Value(intDownStreamFld) != null && pFeature.get_Value(intDownStreamFld).ToString() != "")
                                {
                                    mainDet.UpElev = Convert.ToDouble(pFeature.get_Value(intDownStreamFld));
                                }
                                else
                                    mainDet.UpElev = -9999;
                            }
                            else
                                mainDet.UpElev = -9999;

                        }
                        string label = "";
                        for (int l = 0; l < ProfileGraph[CurrentDetail].Line_Labels.Length; l++)
                        {
                            if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Line_Labels[l]) > 0)
                            {
                                int fldIdx = pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Line_Labels[l]);

                                pFld = pFeature.Fields.get_Field(fldIdx);

                                if (pFeature.get_Value(fldIdx) != null)
                                {
                                    if (label == "")
                                    {
                                        label = Globals.GetDomainDisplay(pFeature.get_Value(fldIdx), pFeature, pFld);
                                    }
                                    else
                                    {

                                        label = label + "\r\n" + Globals.GetDomainDisplay(pFeature.get_Value(fldIdx), pFeature, pFld);

                                    }
                                }
                            }
                        }

                        mainDet.Label = label;

                    }

                    if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Line_IDField) > 0)
                    {
                        if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Line_IDField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Line_IDField)).ToString() != "")
                        {
                            mainDet.MainID = Convert.ToString(pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Line_IDField)));
                        }
                        else
                            mainDet.MainID = "Unk";
                    }
                    else
                        mainDet.MainID = "Unk";

                    pFeatureAdded.Add(pFeature.OID, pFeature.OID);
                    SewerColMains.Add(mainDet);

                }

                pFeatureAdded = new Hashtable();

                pEnumEIDInfoJunctions.Reset();
                for (int i = 0; i < pEnumEIDInfoJunctions.Count; i++)
                {

                    pEIDInfo = pEnumEIDInfoJunctions.Next();
                    pFeature = pEIDInfo.Feature;
                    if (pFLTap != null)
                    {
                        if (((IDataset)pFeature.Class).Name == ((IDataset)pFLTap.FeatureClass).Name)
                        {
                            pJunc = (IJunctionFeature)pFeature;
                            pFeature = ((IFeatureClass)pFeature.Class).GetFeature(pFeature.OID);
                            pHitPntOne = new PointClass();
                            bool bHit = pHtTest.HitTest(pFeature.Shape as IPoint, .1,
                                                    esriGeometryHitPartType.esriGeometryPartVertex,
                                                    pHitPntOne, ref pHitDistOne, ref pHitPrtOne, ref pHitSegOne, ref pHitSideOne);

                            if (bHit)
                            {
                                tapDet = new tapDetails();

                                tapDet.M = pHitPntOne.M;

                                if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].PointAlong_IDField) > 0)
                                {
                                    if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].PointAlong_IDField)) != null &&
                                        pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].PointAlong_IDField)).ToString() != "")
                                    {
                                        tapDet.tapID = pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].PointAlong_IDField)).ToString();
                                    }
                                    else
                                        tapDet.tapID = "Unk";
                                }
                                else
                                    tapDet.tapID = "Unk";

                                string label = "";
                                for (int l = 0; l < ProfileGraph[CurrentDetail].PointAlong_Labels.Length; l++)
                                {
                                    if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].PointAlong_Labels[l]) > 0)
                                    {
                                        int fldIdx = pFeature.Fields.FindField(ProfileGraph[CurrentDetail].PointAlong_Labels[l]);

                                        pFld = pFeature.Fields.get_Field(fldIdx);

                                        if (pFeature.get_Value(fldIdx) != null)
                                        {
                                            if (label == "")
                                            {
                                                label = Globals.GetDomainDisplay(pFeature.get_Value(fldIdx), pFeature, pFld);
                                            }
                                            else
                                            {

                                                label = label + "\r\n" + Globals.GetDomainDisplay(pFeature.get_Value(fldIdx), pFeature, pFld);

                                            }
                                        }
                                    }
                                }

                                tapDet.tapLabel = label;
                                SewerColTap.Add(tapDet);
                            }

                        }
                    }
                    if (((IDataset)pFeature.Class).Name == ((IDataset)pFLManhole.FeatureClass).Name)
                    {
                        if (pFeatureAdded.ContainsValue(pFeature.OID))
                            continue;

                        pJunc = (IJunctionFeature)pFeature;
                        pFeature = ((IFeatureClass)pFeature.Class).GetFeature(pFeature.OID);
                        pHitPntOne = new PointClass();
                        bool bHit = pHtTest.HitTest(pFeature.Shape as IPoint, .1,
                                                esriGeometryHitPartType.esriGeometryPartVertex,
                                                pHitPntOne, ref pHitDistOne, ref pHitPrtOne, ref pHitSegOne, ref pHitSideOne);

                        if (bHit)
                        {
                            manDet = new manholeDetails();

                            manDet.M = pHitPntOne.M;

                            if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_TopElevationField) > 0)
                            {
                                if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_TopElevationField)) != null &&
                                    pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_TopElevationField)).ToString() != "")
                                {
                                    manDet.Top = (double)pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_TopElevationField));
                                }
                                else
                                    manDet.Top = -9999;
                            }
                            else
                                manDet.Top = -9999;

                            if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationField) > 0)
                            {
                                if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationField)) != null &&
                                    pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationField)).ToString() != "")
                                {
                                    manDet.Bottom = (double)pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationField));
                                    if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationTypeField) > 0)
                                    {
                                        if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationTypeField)) != null &&
                                            pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationTypeField)).ToString() != "")
                                        {
                                            if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationTypeField)).ToString().ToUpper() == "INVERT")
                                                manDet.Bottom = manDet.Top - (double)pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationTypeField));
                                        }
                                    }

                                }
                                else
                                    manDet.Bottom = -9999;
                            }
                            else
                                manDet.Bottom = -9999;

                            //if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertElevationField) > 0)
                            //{
                            //    if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertElevationField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertElevationField)).ToString() != "")
                            //    {
                            //        manDet.InvertElev = (double)pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertElevationField));
                            //    }
                            //    else
                            //        manDet.InvertElev = -9999;
                            //}
                            //else
                            //    manDet.InvertElev = -9999;

                            //if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertField) > 0)
                            //{
                            //    if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertField)).ToString() != "")
                            //    {
                            //        manDet.Invert = (double)pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertField));
                            //    }
                            //    else
                            //        manDet.Invert = -9999;
                            //}
                            //else
                            //    manDet.Invert = -9999;

                            //if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_RimElevationField) > 0)
                            //{
                            //    if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_RimElevationField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_RimElevationField)).ToString() != "")
                            //    {
                            //        manDet.Rim = (double)pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_RimElevationField));
                            //    }
                            //    else
                            //        manDet.Rim = -9999;
                            //}
                            //else
                            //    manDet.Rim = -9999;

                            if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_IDField) > 0)
                            {
                                if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_IDField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_IDField)).ToString() != "")
                                {
                                    manDet.ManholeID = pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_IDField)).ToString();
                                }
                                else
                                    manDet.ManholeID = "UNK";
                            }
                            else
                                manDet.ManholeID = "UNK";

                            pFeatureAdded.Add(pFeature.OID, pFeature.OID);
                            SewerColManholes.Add(manDet);
                        }
                    }

                }
                if (ProfileGraph[CurrentDetail].Lines_Along != null)
                {
                    if (ProfileGraph[CurrentDetail].Lines_Along.Length > 0)
                    {

                        pSpatFilt = new SpatialFilterClass();
                        pSpatFilt.Geometry = pPolyline;
                        pSpatFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                        for (int i = 0; i < ProfileGraph[CurrentDetail].Lines_Along.Length; i++)
                        {
                            bool FCorLayerTemp = true;
                            pFl = (IFeatureLayer)Globals.FindLayer(app, ProfileGraph[CurrentDetail].Lines_Along[i].Layer_Name, ref FCorLayerTemp);
                            if (pFl != null)
                            {

                                intUpStreamFld = pFl.FeatureClass.Fields.FindField(ProfileGraph[CurrentDetail].Lines_Along[i].Line_UpStreamElevationField);
                                intDownStreamFld = pFl.FeatureClass.Fields.FindField(ProfileGraph[CurrentDetail].Lines_Along[i].Line_DownStreamElevationField);
                                int intIdFld = pFl.FeatureClass.Fields.FindField(ProfileGraph[CurrentDetail].Lines_Along[i].Line_IDField);
                                if (intIdFld < 0)
                                {
                                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19f") + ProfileGraph[CurrentDetail].Lines_Along[i].Line_IDField + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19e") + ProfileGraph[CurrentDetail].Lines_Along[i].Layer_Name);
                                }
                                if (intDownStreamFld < 0)
                                {
                                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19c") + ProfileGraph[CurrentDetail].Lines_Along[i].Line_DownStreamElevationField + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19e") + ProfileGraph[CurrentDetail].Lines_Along[i].Layer_Name);
                                }
                                if (intUpStreamFld < 0)
                                {
                                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19d") + ProfileGraph[CurrentDetail].Lines_Along[i].Line_UpStreamElevationField + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19e") + ProfileGraph[CurrentDetail].Lines_Along[i].Layer_Name);
                                }

                                pSpatFilt.GeometryField = pFl.FeatureClass.ShapeFieldName;

                                pFC = pFl.Search(pSpatFilt, true);

                            }
                        }
                    }
                }

                ProfileCreateGraph(app, ProfileGraph, pPolyline, SewerColMains, SewerColManholes, SewerColTap, CurrentDetail);

            }
            catch (Exception Ex)
            {
                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + "ProfileGetRelatedSewerElevData " + Ex.Message);
            }
            finally
            {

                SewerColMains = null;
                SewerColManholes = null;
                SewerColTap = null;

                pEIDHelperEdges = null;
                pEnumEIDInfoEdges = null;

                pEIDHelperJunctions = null;
                if (pEnumEIDInfoJunctions != null)
                    Marshal.ReleaseComObject(pEnumEIDInfoJunctions);

                pEnumEIDInfoJunctions = null;

                pPolyline = null;
                pPtColl = null;

                pEIDInfo = null;
                pNewPt = null;
                pSegColl = null;
                pMSegmentation = null;
                pMAware = null;

                pPtCollection = null;
                pEnumVertex = null;

                pHtTest = null;
                pHitPntOne = null;
                pHitPntTwo = null;
                pFeature = null;
                pFeatureAdded = null;
                mainDet = null;

                pEdge = null;

                pGeoOne = null;
                pGeoTwo = null;
                pFld = null;
                pJunc = null;
                tapDet = null;
                manDet = null;
                pFl = null;
                pSpatFilt = null;
                if (pFC != null)
                    Marshal.ReleaseComObject(pFC);

                pFC = null;

            }
        }
Example #8
0
        private static Dictionary<IFeature, int> GetFeaturesFromNetEID(IGeometricNetwork geomNet, IEnumNetEIDBuilder enumEIDBuilder)
        {
            string fileName = "eidGeomLines.txt";
            if (((IEnumNetEID)enumEIDBuilder).ElementType == esriElementType.esriETJunction)
            {
                fileName = "eidGeomPoints.txt";
            }
            Dictionary<IFeature, int> featuresInPath = new Dictionary<IFeature, int>();
            using (System.IO.StreamWriter sw = System.IO.File.CreateText("C:\\temp\\" + fileName))
            {
                sw.Write("[");

                IEIDHelper eidHelper = new EIDHelperClass();
                //eidHelper.AddField("OBJECTID");
                //eidHelper.AddField("SHAPE");
                eidHelper.ReturnGeometries = true;
                int multiplier = 1;
                if (((IEnumNetEID)enumEIDBuilder).ElementType == esriElementType.esriETEdge)
                {
                    multiplier = -1;
                }
                eidHelper.ReturnFeatures = true;
                eidHelper.GeometricNetwork = geomNet;
                IEnumEIDInfo enumEIDInfo = eidHelper.CreateEnumEIDInfo(enumEIDBuilder as IEnumNetEID);
                enumEIDInfo.Reset();
                for (int i = 0; i < enumEIDInfo.Count; i++)
                {
                    IEIDInfo eidInfo = enumEIDInfo.Next();
                    try
                    {
                        IFeature fe = eidInfo.Feature;
                        int eid = eidInfo.EID;
                        featuresInPath.Add(fe, eidInfo.EID);
                        sw.Write("[");
                        sw.Write(eid * multiplier);
                        sw.Write(",");
                        sw.Write("[");
                        if (fe.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
                        {
                            #region Loop through the point collection of the polyline and write out to the file
                            IPointCollection pc = fe.Shape as IPointCollection;
                            for (int j = 0; j < pc.PointCount; j++)
                            {
                                sw.Write("[");
                                sw.Write(pc.get_Point(j).X + "," + pc.get_Point(j).Y);
                                sw.Write("]");
                                if (j + 1 < pc.PointCount)
                                {
                                    sw.Write("],");
                                }
                            }
                            #endregion
                        }
                        else if (fe.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                        {
                            IPoint pnt = fe.Shape as IPoint;
                            sw.Write(pnt.X.ToString() + "," + pnt.Y.ToString());
                            sw.Write("]");
                        }
                        if (i + 1 < enumEIDInfo.Count)
                        {
                            sw.Write(",");//more geometries coming!
                        }
                    }
                    catch { }
                }
                sw.Write("]"); // This closes off all the geoemtries
                sw.Close();
            }

            return featuresInPath;
        }
Example #9
0
        private bool ShutdownArcMap()
        {
            IApplication pApp;
            IDocument pDoc;
            IMxDocument pMXDoc;
            IDocumentDirty2 pDocDirty;

            Type t = Type.GetTypeFromProgID("esriFramework.AppRef");
            System.Object obj = Activator.CreateInstance(t);
            pApp = obj as IApplication;
            pDoc = pApp.Document;
            pMXDoc = (IMxDocument)pDoc;
            pDocDirty = (IDocumentDirty2)pMXDoc;
            pDocDirty.SetClean();
            Workspace = null;
            ScriptEngine.BroadcastProperty("Workspace", this.Workspace, this);
            ScriptEngine.BroadcastProperty("FeatureClass", null, this);
            _SDMGR = null;
            _PTMGR = null;
            pSelection = null;
            m_pGN = null;
            pSC = null;
            pEditor = null;
            pDoc = null;
            pMXDoc = null;
            pApp.Shutdown();
            //Process iProc = Process.GetCurrentProcess();
            //iProc.Kill();

            Logger.WriteLine("Closing Arcmap");
            return true;
        }
Example #10
0
 public void setGNetwork(IGeometricNetwork _mNetwork)
 {
     m_ipGeometricNetwork=_mNetwork;
 }
Example #11
0
        private bool PlaceFlag(string sClassName, string sOID)
        {
            IFeatureClass pFC;
            IFeatureWorkspace pFWKS;
            IFeature pFeat;
            INetElements pNetElements;
            ISimpleJunctionFeature pJunc;
            INetworkAnalysisExt pNetworkAnalysisExt;
            IMxDocument pMXDoc;
            IApplication pApp;
            IMxApplication pMXApp;
            INetworkAnalysisExtFlags pNetworkAnalysisExtFlags;
            UID pUID;
            ITraceFlowSolverGEN pTraceFlowSolver;
            INetSolver pNetSolver;
            Miner.Interop.IMMTraceUIUtilities pTraceUtils;
            IPolycurve pPoly;
            int iCLSID;
            int iOID;
            int iSUBID;

            try
            {
                SW1.Reset();
                SW1.Start();

                Type t = Type.GetTypeFromProgID("esriFramework.AppRef");
                System.Object obj = Activator.CreateInstance(t);
                pApp = obj as IApplication;
                pMXApp = (IMxApplication)pApp;
                pMXDoc = (IMxDocument)pApp.Document;
                pUID = new UID();
                pUID.Value = "esriEditorExt.UtilityNetworkAnalysisExt";
                pNetworkAnalysisExt = (INetworkAnalysisExt)pApp.FindExtensionByCLSID(pUID);
                pNetworkAnalysisExtFlags = (INetworkAnalysisExtFlags)pNetworkAnalysisExt;
                pNetElements = (INetElements)pNetworkAnalysisExt.CurrentNetwork.Network;
                pTraceUtils = new Miner.Interop.MMTraceUIUtilities();

                pFWKS = (IFeatureWorkspace)Workspace;
                pFC = pFWKS.OpenFeatureClass(sClassName);
                if (pFC != null)
                {
                    pFeat = pFC.GetFeature(Convert.ToInt32(sOID));
                    INetworkFeature pNetFeat = (INetworkFeature)pFeat;
                    m_pGN = pNetFeat.GeometricNetwork;
                    if (pFeat != null)
                    {
                        pTraceFlowSolver = (ITraceFlowSolverGEN)new TraceFlowSolver();
                        pNetSolver = (INetSolver)pTraceFlowSolver;
                        if (pFeat.FeatureType == esriFeatureType.esriFTSimpleJunction)
                        {
                            pJunc = (ISimpleJunctionFeature)pFeat;
                            pNetElements.QueryIDs(pJunc.EID, esriElementType.esriETEdge, out iCLSID, out iOID, out iSUBID);
                            //pJFlag = (INetFlag)new JunctionFlag();
                            //pJFlag.UserClassID = iCLSID;
                            //pJFlag.UserID = iOID;
                            //pJFlag.UserSubID = iSUBID;
                            IFlagDisplay pFlagDisplay = new JunctionFlagDisplay();
                            pFlagDisplay.Symbol = (ISymbol)CreateMarkerSymbol(0);
                            pFlagDisplay.Geometry = (IPoint)pFeat.ShapeCopy;
                            //Set pNetSolver.SourceNetwork = pNetElements
                            pNetworkAnalysisExtFlags.AddJunctionFlag((IJunctionFlagDisplay)pFlagDisplay);
                        }
                        else
                        {
                            IPoint pPoint;
                            pPoint = new Point();
                            double dDist;
                            dDist = .5;
                            pPoly = (IPolycurve)pFeat.ShapeCopy;
                            pPoly.QueryPoint(esriSegmentExtension.esriNoExtension, dDist, true, pPoint);
                            IFlagDisplay pFlagDisplay = new EdgeFlagDisplay();
                            IEdgeFeature pEdge = (IEdgeFeature)pFeat;
                            IObjectClass pOC = (IObjectClass)pFeat.Table;
                            int iEID = pNetElements.GetEID(pOC.ObjectClassID, pFeat.OID, 0, esriElementType.esriETEdge);
                            //pNetElements.QueryIDs(pEdge.ToJunctionEID, esriElementType.esriETEdge, out iCLSID, out iOID, out iSUBID);
                            pFlagDisplay.FeatureClassID = pOC.ObjectClassID;
                            pFlagDisplay.FID = pFeat.OID;
                            pFlagDisplay.SubID = 0;
                            //pFlagDisplay.Geometry = pPoint;
                            pFlagDisplay.Symbol = (ISymbol)CreateMarkerSymbol(0);
                            ISimpleMarkerSymbol pSMS = (ISimpleMarkerSymbol)pFlagDisplay.Symbol;
                            IColor pColor;
                            pColor = new RgbColor();
                            pColor.RGB = 100;
                            pSMS.Size = 10;
                            pNetworkAnalysisExtFlags.AddEdgeFlag((IEdgeFlagDisplay)pFlagDisplay);
                        }
                    }
                }
                SW1.Stop();
                RecordActionTime("PLACEFLAG" , SW1.ElapsedMilliseconds);
                return true;
            }
            catch (Exception EX)
            {
                Logger.WriteLine("Error in PlaceFlags " + EX.Message + " " + EX.StackTrace);
                return false;
            }
        }
Example #12
0
        private IDictionary<int, SelectedObjects> GetClassIDs(IGeometricNetwork pGN)
        {
            IDictionary<int, SelectedObjects> dicIDs;
            IEnumFeatureClass pEFC;
            IFeatureClass pFC;
            IDataset pDS;
            SelectedObjects pSelObjs;

            try
            {
                dicIDs = new Dictionary<int, SelectedObjects>();
                pEFC = pGN.get_ClassesByType(ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTComplexEdge);
                pFC = pEFC.Next();
                while (pFC != null)
                {
                    if (!dicIDs.ContainsKey(pFC.FeatureClassID))
                    {
                        pDS = (IDataset)pFC;
                        pSelObjs = new SelectedObjects(pFC);
                        dicIDs.Add(pFC.FeatureClassID, pSelObjs);
                    }
                    pFC = pEFC.Next();
                }

                pEFC = pGN.get_ClassesByType(ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimpleEdge);
                pFC = pEFC.Next();
                while (pFC != null)
                {
                    if (!dicIDs.ContainsKey(pFC.FeatureClassID))
                    {
                        pDS = (IDataset)pFC;
                        pSelObjs = new SelectedObjects(pFC);
                        dicIDs.Add(pFC.FeatureClassID, pSelObjs);
                    }
                    pFC = pEFC.Next();
                }

                pEFC = pGN.get_ClassesByType(ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimpleJunction);
                pFC = pEFC.Next();
                while (pFC != null)
                {
                    if (!dicIDs.ContainsKey(pFC.FeatureClassID))
                    {
                        pDS = (IDataset)pFC;
                        pSelObjs = new SelectedObjects(pFC);
                        dicIDs.Add(pFC.FeatureClassID, pSelObjs);
                    }
                    pFC = pEFC.Next();
                }
                Marshal.ReleaseComObject(pEFC);
                return dicIDs;
            }
            catch (Exception EX)
            {
                this.Logger.WriteLine("GetClassIDs Error" + EX.Message + " " + EX.StackTrace);

                return null;
            }
        }
        /// <summary>
        /// 将几何网络添加到地图上
        /// </summary>
        /// <param name="_pMap"></param>
        /// <param name="_pGeometricNetwork"></param>
        void LoadGeometric(IMap _pMap,IGeometricNetwork _pGeometricNetwork)
        {
            IFeatureClassContainer pFtContainer = _pGeometricNetwork as IFeatureClassContainer;

            int pCount = pFtContainer.ClassCount;

            for (int i = 0; i < pCount; i++)
            {
            IFeatureLayer pFeatureLayer = new FeatureLayerClass();

            pFeatureLayer.FeatureClass = pFtContainer.get_Class(i);

            _pMap.AddLayer(pFeatureLayer as ILayer);
            }
        }
Example #14
0
        private void PopulateListView(Dictionary<int, int> pathDictionary, INetwork network, IGeometricNetwork geomNet)
        {
            IEnumNetEID netJuncEIDS = GetEnumNetEID(-1, pathDictionary, network, geomNet, esriElementType.esriETJunction);
            IEnumNetEID netEdgeEIDS = GetEnumNetEID(-1, pathDictionary, network, geomNet, esriElementType.esriETEdge);
            Dictionary<IFeature, int>   junctionsInPath = GetFeaturesFromNetEID(_geomNet, (IEnumNetEIDBuilder) netJuncEIDS);
            Dictionary<IFeature, int> edgesInPath = GetFeaturesFromNetEID(_geomNet, (IEnumNetEIDBuilder)netEdgeEIDS);

            //GetFeaturesFromNetEID(_geomNet, (IEnumNetEIDBuilder)netJuncEIDS);
            //GetFeaturesFromNetEID(_geomNet, (IEnumNetEIDBuilder)netEdgeEIDS);
            AddToListView(junctionsInPath);
        }
        public ZGeometricNetwork(IGeometricNetwork geometricNetwork)
            : base(geometricNetwork as IDataset)
        {
            // Initialize collections
            this.NetworkClasses = new ObservableCollection<ZNetworkClass>();
            this.Weights = new ObservableCollection<ZNetWeight>();
            this.EdgeRules = new ObservableCollection<ZRule>();
            this.JunctionRules = new ObservableCollection<ZRule>();

            // Report addition
            GeometricNetworkViewModel.Default.AddMessage(string.Format("Finding network classes..."), MessageType.Information);

            // Add network classes
            IEnumFeatureClass enumFeatureClass1 = geometricNetwork.get_ClassesByType(esriFeatureType.esriFTSimpleJunction);
            IEnumFeatureClass enumFeatureClass2 = geometricNetwork.get_ClassesByType(esriFeatureType.esriFTSimpleEdge);
            IEnumFeatureClass enumFeatureClass3 = geometricNetwork.get_ClassesByType(esriFeatureType.esriFTComplexEdge);
            foreach (IEnumFeatureClass enumFeatureClass in new IEnumFeatureClass[] { enumFeatureClass1, enumFeatureClass2, enumFeatureClass3 }) {
                IFeatureClass featureClass = enumFeatureClass.Next();
                while (featureClass != null) {
                    INetworkClass networkClass = featureClass as INetworkClass;
                    if (networkClass != null) {
                        // Create network class
                        ZNetworkClass znc = new ZNetworkClass(networkClass);

                        // Add class to collection
                        this.NetworkClasses.Add(znc);

                        // Report addition
                        GeometricNetworkViewModel.Default.AddMessage(string.Format("Adding class: {0}", znc.Path.Table), MessageType.Information);
                    }
                    featureClass = enumFeatureClass.Next();
                }
            }

            // Add weights and weight associations
            INetwork network = geometricNetwork.Network;
            INetSchema netSchema = (INetSchema)network;
            for (int i = 0; i < netSchema.WeightCount; i++) {
                // Create network weight
                INetWeight netWeight = netSchema.get_Weight(i);
                IEnumNetWeightAssociation enumNetWeightAssocation = netSchema.get_WeightAssociations(i);
                ZNetWeight znw = new ZNetWeight(this, netWeight, enumNetWeightAssocation);

                // Add weight to collection
                this.Weights.Add(znw);

                // Report addition
                GeometricNetworkViewModel.Default.AddMessage(string.Format("Adding weight: {0}", znw.Name), MessageType.Information);
            }

            // Add connectivity rules
            IEnumRule rules = geometricNetwork.Rules;
            IRule rule = rules.Next();
            while (rule != null) {
                if (rule is IJunctionConnectivityRule) {
                    // Create junction rule
                    IJunctionConnectivityRule junctionConnectivityRule = (IJunctionConnectivityRule)rule;
                    ZJunctionConnectivityRule jcr = new ZJunctionConnectivityRule(this, junctionConnectivityRule);

                    // Add junction rule
                    this.JunctionRules.Add(jcr);

                    // Report
                    GeometricNetworkViewModel.Default.AddMessage(string.Format("Adding junction rule: {0}", jcr.Id), MessageType.Information);
                }
                else if (rule is IEdgeConnectivityRule) {
                    // Create edge rule
                    IEdgeConnectivityRule edgeConnectivityRule = (IEdgeConnectivityRule)rule;
                    ZEdgeConnectivityRule ecr = new ZEdgeConnectivityRule(this, edgeConnectivityRule);

                    // Add edge rule
                    this.EdgeRules.Add(ecr);

                    // Report
                    GeometricNetworkViewModel.Default.AddMessage(string.Format("Adding edge rule: {0}", ecr.Id), MessageType.Information);
                }

                rule = rules.Next();
            }
        }
Example #16
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="circBreaker"></param>
        private void TraceFeeder(INetworkFeature circBreaker)
        {
            #region Initialize some variables

            listView1.Items.Clear();
            Int32 phaseABit = (int) Math.Pow(2, 28); // 268435456
            Int32 phaseBBit = (int) Math.Pow(2, 29); // 536870912
            Int32 phaseCBit = (int) Math.Pow(2, 30); // 1073741824

            #endregion

            #region Create a queue of junctions to visit and a hash table for path information

            Queue<int> junctionsToVisit = new Queue<int>();
            Dictionary<int, int> pathHash = new Dictionary<int, int>();
            int startEID = ((ISimpleJunctionFeature) circBreaker).EID;
            junctionsToVisit.Enqueue(startEID);
            pathHash.Add(startEID, -99999999);

            #endregion

            #region Get the MMElectricTraceWeight and create a ForwardStar so that we can stop the trace when we reach an open point

            _network = circBreaker.GeometricNetwork.Network;
            _geomNet = circBreaker.GeometricNetwork;
            INetSchema netSchema = (INetSchema) _network;
            INetWeight mmElectricTraceWeight = netSchema.get_WeightByName("MMElectricTraceWeight");
            IForwardStarGEN fStar =
                (IForwardStarGEN) _network.CreateForwardStar(false, mmElectricTraceWeight, null, null, null);

            #endregion

            while (junctionsToVisit.Count > 0)
            {
                #region Orient the Forward Star at the current junction EID

                int eid = junctionsToVisit.Dequeue();
                int adjEdgeCount = 0;
                fStar.FindAdjacent(0, eid, out adjEdgeCount);

                #endregion

                #region Declare and initialize arrays to hold edges and junctions, weights, and orientations

                int[] adjJuncEIDS = new int[adjEdgeCount];
                object[] adjJuncWeights = new object[adjEdgeCount];
                int[] adjEdgeEIDS = new int[adjEdgeCount];
                object[] adjEdgeWeights = new object[adjEdgeCount];
                    // We don't use this, but we still have to declare the array
                bool[] adjRevOrientations = new bool[adjEdgeCount];
                    // We don't use this, but we still have to declare the array

                #endregion

                #region Query the adjacent junctions and edges (while we are at it, get the weights too)

                fStar.QueryAdjacentJunctions(ref adjJuncEIDS, ref adjJuncWeights);
                fStar.QueryAdjacentEdges(ref adjEdgeEIDS, ref adjRevOrientations, ref adjEdgeWeights);

                #endregion

                #region Loop through all of the connected edges

                for (int i = 0; i < adjEdgeCount; i++)
                {
                    #region Get the connected edge and junction

                    int connectedEdgeEID = -1*adjEdgeEIDS[i];
                    int oppositeJuncEID = adjJuncEIDS[i];

                    #endregion

                    #region Check to see if the adjacent junctions has already been added to the paths hashtable

                    if (pathHash.ContainsKey(oppositeJuncEID) == false)
                    {
                        #region Add the opposite junction and the connected edge to the paths hashtable

                        pathHash.Add(oppositeJuncEID, connectedEdgeEID);
                        pathHash.Add(connectedEdgeEID, eid);

                        #endregion

                        #region If the opposite junction is closed on at least one phase (A or B or C), then enque the opposite junction

                        Int32 juncWeight = System.Convert.ToInt32(adjJuncWeights[i]);
                        if ((juncWeight & phaseABit) == 0 || (juncWeight & phaseBBit) == 0 ||
                            (juncWeight & phaseCBit) == 0 || (juncWeight == 0))
                        {
                            junctionsToVisit.Enqueue(oppositeJuncEID);
                        }

                        #endregion
                    }

                    #endregion
                }

                #endregion
            }
            _pathHash = pathHash;
            PopulateListView(pathHash, _network, _geomNet);
        }
Example #17
0
 //初始化几何网络和地图
 private bool InitializeNetworkAndMap(IFeatureDataset FeatureDataset)
 {
     IFeatureClassContainer ipFeatureClassContainer;
     IFeatureClass ipFeatureClass;
     IGeoDataset ipGeoDataset;
     ILayer ipLayer;
     IFeatureLayer ipFeatureLayer;
     IEnvelope ipEnvelope, ipMaxEnvelope;
     double dblSearchTol;
     INetworkCollection ipNetworkCollection = FeatureDataset as INetworkCollection;
     int count = ipNetworkCollection.GeometricNetworkCount;
     //获取第一个几何网络工作空间
     m_ipGeometricNetwork = ipNetworkCollection.get_GeometricNetwork(0);
     INetwork ipNetwork = m_ipGeometricNetwork.Network;
     if (m_ipMap != null)
     {
         //m_ipMap = new MapClass();
         ipFeatureClassContainer = m_ipGeometricNetwork as IFeatureClassContainer;
         count = ipFeatureClassContainer.ClassCount;
         for (int i = 0; i < count; i++)
         {
             ipFeatureClass = ipFeatureClassContainer.get_Class(i);
             ipFeatureLayer = new FeatureLayerClass();
             ipFeatureLayer.FeatureClass = ipFeatureClass;
             for (int j = 0; j < m_ipMap.LayerCount; j++)
             {
                 if (m_ipMap.get_Layer(j).Name.ToUpper() == ipFeatureLayer.Name.ToUpper())
                 {
                     continue;
                 }
             }
             m_ipMap.AddLayer(ipFeatureLayer);
         }
         m_ipActiveView.Refresh();
     }
     count = m_ipMap.LayerCount;
     ipMaxEnvelope = new EnvelopeClass();
     for (int i = 0; i < count; i++)
     {
         ipLayer = m_ipMap.get_Layer(i);
         ipFeatureLayer = ipLayer as IFeatureLayer;
         ipGeoDataset = ipFeatureLayer as IGeoDataset;
         ipEnvelope = ipGeoDataset.Extent;
         ipMaxEnvelope.Union(ipEnvelope);
     }
     m_ipPointToEID = new PointToEIDClass();
     m_ipPointToEID.SourceMap = m_ipMap;
     m_ipPointToEID.GeometricNetwork = m_ipGeometricNetwork;
     double dblWidth = ipMaxEnvelope.Width;
     double dblHeight = ipMaxEnvelope.Height;
     if (dblWidth > dblHeight)
         dblSearchTol = dblWidth / 100;
     else
         dblSearchTol = dblHeight / 100;
     m_ipPointToEID.SnapTolerance = dblSearchTol;
     return true;
 }
        public static string TracePath(double[] Xs, double[] Ys, string GeoNetName, IApplication app, IMap map, bool traceIndeterminate,
                                   double snapTol, bool selectEdges, out IEnumNetEID juncEIDs, out IEnumNetEID edgeEIDs, out IGeometricNetwork gn)
        {
            gn = null;

            juncEIDs = null;
            edgeEIDs = null;

            List<INetFlag> pNetFlags = null;
            IFlagDisplay pFlagDisplay = null;

            IJunctionFlag[] junctionFlags = null;
            IEdgeFlag[] edgeFlags = null;

            ITraceFlowSolverGEN traceFlowSolver = null;

            List<IEdgeFlag> pEdgeFlags = null;
            List<IJunctionFlag> pJunctionFlags = null;
            INetElementBarriers pEdgeElementBarriers;
            INetElementBarriers pJunctionElementBarriers;
            ISelectionSetBarriers pSelectionSetBarriers;
            List<IGeometricNetwork> gnList = null;
            INetworkAnalysisExt pNetAnalysisExt = null;
            UID pID = null;
            try
            {
                gnList = Globals.GetGeometricNetworks(ref map);
                if (gnList == null)
                {
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_17a"));
                    return "";
                }

                int gnIdx = -1;

                gnIdx = Globals.GetGeometricNetwork(ref gnList, GeoNetName);
                if (gnIdx != -1)
                {
                    gn = (IGeometricNetwork)gnList[gnIdx];
                }

                pNetFlags = new List<INetFlag>();

                //  INetFlag[] netFlags = new INetFlag[Xs.Length];

                for (int i = 0; i < Xs.Length; i++)
                {
                    IPoint snappedPoint = null; int EID = -1;
                    if (gn == null)
                    {

                        pNetFlags.Add(Globals.GetJunctionFlag(Xs[i], Ys[i], ref map, ref gnList, snapTol, ref gnIdx,
                                    out snappedPoint, out EID, out  pFlagDisplay, true) as INetFlag);

                        //Set network to trace
                        if (gnIdx > -1)
                            gn = gnList[gnIdx] as IGeometricNetwork;

                    }
                    else
                    {
                        pNetFlags.Add(Globals.GetJunctionFlagWithGN(Xs[i], Ys[i], ref map, ref gn, ref snapTol, out snappedPoint, out EID, out  pFlagDisplay, true) as INetFlag);

                    }
                }

                if (gn == null || pNetFlags.Count < 1)
                {
                    return (A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_17b"));

                }

                if (app != null)
                {

                    pID = new UID();

                    pID.Value = "esriEditorExt.UtilityNetworkAnalysisExt";
                    pNetAnalysisExt = (INetworkAnalysisExt)app.FindExtensionByCLSID(pID);
                    Globals.SetCurrentNetwork(ref pNetAnalysisExt, ref gn);
                    traceFlowSolver = Globals.CreateTraceFlowSolverFromToolbar(ref pNetAnalysisExt, out pEdgeFlags, out pJunctionFlags, out pEdgeElementBarriers, out pJunctionElementBarriers, out pSelectionSetBarriers) as ITraceFlowSolverGEN;

                }
                else
                {
                    traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN;
                    INetSolver netSolver = traceFlowSolver as INetSolver;

                    netSolver.SourceNetwork = gn.Network;

                }

                traceFlowSolver.TraceIndeterminateFlow = traceIndeterminate;

                if (pEdgeFlags != null)
                {
                    foreach (IEdgeFlag pEdFl in pEdgeFlags)
                    {
                        pNetFlags.Add((INetFlag)pEdFl);

                    }
                }
                if (pJunctionFlags != null)
                {

                    foreach (IJunctionFlag pJcFl in pJunctionFlags)
                    {
                        pNetFlags.Add((INetFlag)pJcFl);
                    }
                }
                //if (startNetFlag != null)
                //{

                //    pNetFlags.Add((INetFlag)startNetFlag);

                //}

                Globals.AddFlagsToTraceSolver(pNetFlags.ToArray(), ref traceFlowSolver, out junctionFlags, out edgeFlags);
                int intCount = 1;
                System.Object[] segCosts = new System.Object[1];
                segCosts[0] = new System.Object();

                traceFlowSolver.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinMax,
                    out juncEIDs, out edgeEIDs, intCount, ref segCosts);

                //Select junction features
                map.ClearSelection();
                IJunctionFlag[] junctionFlag = null;
                Globals.SelectJunctions(ref map, ref  gn, ref juncEIDs, ref junctionFlag, "", "", "", true);
                if (selectEdges)
                    Globals.SelectEdges(ref map, ref gn, ref edgeEIDs);
                edgeEIDs.Reset();

                //Draw edge graphics
                IEnvelope env = Globals.DrawEdges(ref map, ref gn, ref edgeEIDs);

                return edgeEIDs.Count.ToString();

            }
            catch (Exception Ex)
            {
                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_17a") + "\n" + Ex.Message);
                return "";

            }
        }
Example #19
0
        /// <summary>
        /// Get the workspace from map which has geometric network
        /// </summary>
        /// <param name="map"></param>
        /// <returns></returns>
        public static IWorkspace GetGeoNetworkWorkspaceFromMap(IMap map, out IGeometricNetwork firstGeoNetwork)
        {
            IWorkspace workspace = null;
            firstGeoNetwork = null;
            try
            {
                IDictionary<IWorkspace, int> workspaces = DisplayMap.GetWorkspacesFromMap(map);
                if (workspaces == null) return null;

                foreach (KeyValuePair<IWorkspace, int> ws in workspaces)
                {
                    IList<IGeometricNetwork> geoNetworks = DisplayMap.GetGeometricNetworksFromWorkspace(ws.Key);
                    if (geoNetworks != null && geoNetworks.Count > 0)
                    {
                        firstGeoNetwork = geoNetworks[0];
                        workspace = ws.Key;
                        break;
                    }
                }

            }
            catch (Exception ex)
            {
                //_logger.LogException(ex);
            }
            return workspace;
        }
Example #20
0
        public static void ProfileFindPath(AxMapControl ppAxMapControl, IArray pNetFlagArray, IGeometricNetwork pGeoNetwork)
        {
            try
            {

                IEnumNetEID m_ipEnumNetEID_Junctions, m_ipEnumNetEID_Edges;//����������������Junctions��Edges
                IJunctionFlag[] pArrayJFlag = new IJunctionFlag[2];
                pArrayJFlag[0] = pNetFlagArray.get_Element(0) as IJunctionFlag;
                pArrayJFlag[1] = pNetFlagArray.get_Element(1) as IJunctionFlag;
                ITraceFlowSolverGEN ipTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN;

                //get the inetsolver interface
                INetSolver ipNetSolver = ipTraceFlowSolver as INetSolver;
                ipNetSolver.SourceNetwork = pGeoNetwork.Network;

                ipTraceFlowSolver.PutJunctionOrigins(ref pArrayJFlag);

                ipTraceFlowSolver.TraceIndeterminateFlow = false;

                object[] totalCost = new object[1];

                //ipTraceFlowSolver.FindSource(esriFlowMethod.esriFMUpstream,esriShortestPathObjFn.esriSPObjFnMinSum,out m_ipEnumNetEID_Junctions,out m_ipEnumNetEID_Edges,1,ref totalCost);

                ipTraceFlowSolver.FindPath(esriFlowMethod.esriFMConnected,
                    esriShortestPathObjFn.esriSPObjFnMinMax,
                    out m_ipEnumNetEID_Junctions,
                    out m_ipEnumNetEID_Edges, 1, ref totalCost);
                //��������еĽ����Ԫ��
                pNetFlagArray.RemoveAll();
                //ma
                //              SpatialHelperFunction.pathToPolyline(pGeoNetwork, ppAxMapControl.ActiveView, m_ipEnumNetEID_Edges);
                //ProfileGetRelatedSewerElevData(ppAxMapControl,pGeoNetwork,m_ipEnumNetEID_Edges, m_ipEnumNetEID_Junctions  );
            }
            catch (Exception eX)
            {
                MessageBox.Show(eX.Message);

            }
        }
Example #21
0
        public static void initNetwork(IFeatureDataset pFeaDataset,IMap pMap,out IGeometricNetwork m_ipGeometricNetwork)
        {
            INetworkCollection pNetworkCollection;
            //IGeometricNetwork m_ipGeometricNetwork;
            INetwork pNetwork;
            IFeatureClassContainer ipFeatureClassContainer;
            IFeatureClass ipFeatureClass;
            IFeatureLayer ipFeatureLayer;
            IDataset pDataset;

            //get the network collection
            pNetworkCollection=pFeaDataset as INetworkCollection;

            if(pNetworkCollection.GeometricNetworkCount==0)
            {
                MessageBox.Show("������û������");
                m_ipGeometricNetwork=null;
                return;
            }

            m_ipGeometricNetwork=pNetworkCollection.get_GeometricNetworkByName("Water_Network");

            //m_ipGeometricNetwork.

            //Use the INetwork interface when you want to query the network for general information
            //such as the status of the network or the number of edges in your network.

            pNetwork=m_ipGeometricNetwork.Network;

            //Add each of the Feature Classes in this Geometric Network as a map Layer

            ipFeatureClassContainer=pNetworkCollection as IFeatureClassContainer;

            if(ipFeatureClassContainer.ClassCount==0)
            {
                MessageBox.Show("û������featureClass");
                m_ipGeometricNetwork=null;
                return;
            }

            for(int ii=0;ii<ipFeatureClassContainer.ClassCount;ii++)
            {

                ipFeatureClass=ipFeatureClassContainer.get_Class(ii);

                pDataset=ipFeatureClass as IDataset;

                if(pDataset.Name=="water_arc"||pDataset.Name.Equals("water_point")||pDataset.Name.Equals("Water_Network_Junctions"))
                {

                    ipFeatureLayer=new FeatureLayerClass();

                    ipFeatureLayer.FeatureClass=ipFeatureClass;

                    ipFeatureLayer.Name=pDataset.Name;

                    pMap.AddLayer(ipFeatureLayer);
                }

            }
        }
Example #22
0
        //////////////////////////////////�����������ǰ���ý����С��
        public static void ProfileSetJunctionFlag(AxMapControl ppAxMapControl, ref IArray pNetFlagArray, IPoint pPoint, IGeometricNetwork pGeoNetwork)
        {
            try
            {

                //�����ͼ��ѡ��
                ppAxMapControl.ActiveView.FocusMap.ClearSelection();
                INetElements pNetElements = pGeoNetwork.Network as INetElements;
                IPointToEID pPtToEID = new PointToEIDClass();
                int pJunctionID = 0;
                int iUserClassID;
                int iUserID;
                int iUserSubID;
                IPoint pLocation;

                pPtToEID.SourceMap = ppAxMapControl.ActiveView.FocusMap;
                pPtToEID.GeometricNetwork = pGeoNetwork;
                pPtToEID.SnapTolerance = ppAxMapControl.ActiveView.Extent.Envelope.Width / 100;
                pPtToEID.GetNearestJunction(pPoint, out pJunctionID, out pLocation);
                if (pJunctionID == 0)
                {
                    MessageBox.Show("û�в������ٽ��ĵ�");
                }
                else
                {

                    pNetElements.QueryIDs(pJunctionID, esriElementType.esriETJunction, out iUserClassID, out iUserID, out iUserSubID);
                    INetFlag ipNetFlag = new JunctionFlagClass();
                    ipNetFlag.UserClassID = iUserClassID;
                    ipNetFlag.UserID = iUserID;
                    ipNetFlag.UserSubID = iUserSubID;

                    IMarkerSymbol pMarkerSym = new SimpleMarkerSymbolClass();
                    IRgbColor pRGBColor = new RgbColorClass();
                    pRGBColor.Red = 255;
                    pRGBColor.Green = 0;
                    pRGBColor.Blue = 0;
                    pMarkerSym.Color = pRGBColor;
                    pMarkerSym.Size = 20;
                    //���Ƹõ�
                    IScreenDisplay pScreenDisplay = ppAxMapControl.ActiveView.ScreenDisplay;
                    pScreenDisplay.StartDrawing(pScreenDisplay.hDC, 0);
                    pScreenDisplay.SetSymbol(pMarkerSym as ISymbol);
                    pScreenDisplay.DrawPoint(pLocation);
                    pScreenDisplay.FinishDrawing();
                    if (pLocation != null)
                    {
                        pNetFlagArray.Add(ipNetFlag);
                    }
                    if (pNetFlagArray.Count == 2)
                    {

                        //����׷�ٽ��
                        ProfileFindPath(ppAxMapControl, pNetFlagArray, pGeoNetwork);
                    }
                }

            }
            catch (Exception eX)
            {
                MessageBox.Show(eX.Message);

            }
        }
Example #23
0
        public static void pathToPolyline(IGeometricNetwork pGeometricNetwork,IActiveView pActiveView,IEnumNetEID pEnumNetEID_Edges)
        {
            try
            {

                IEIDHelper piEIDHelper=new EIDHelperClass();

                piEIDHelper.GeometricNetwork=pGeometricNetwork;

                piEIDHelper.OutputSpatialReference=pActiveView.FocusMap.SpatialReference;

                piEIDHelper.ReturnFeatures=true;

                IPolyline mPolyline=new PolylineClass();

                mPolyline.SpatialReference=pActiveView.FocusMap.SpatialReference;

                IEIDInfo ipEIDInfo;

                IEnumEIDInfo piEnumEIDInfo;

                IGeometry ipGeometry=null;

                piEnumEIDInfo=piEIDHelper.CreateEnumEIDInfo(pEnumNetEID_Edges);

                IGeometryCollection pGeoCollection=mPolyline as IGeometryCollection;

                piEnumEIDInfo.Reset();

                object objMiss=Type.Missing;

                for(int ii=0;ii<piEnumEIDInfo.Count;ii++)
                {

                    ipEIDInfo=piEnumEIDInfo.Next();

                    ipGeometry=ipEIDInfo.Feature.Shape;

                    if(ipGeometry!=null)
                        Utility.drawPolyline(pActiveView,ipGeometry as IPolyline);

                }

                //return ipGeometry as IPolyline;
            }
            catch(Exception e)
            {
                MessageBox.Show(e.Message);

            }
            finally
            {

            }
        }
Example #24
0
        public static void UpStreamTrace(AxMapControl ppAxMapControl, IPoint pPoint, IGeometricNetwork pGeoNetwork)
        {
            try
            {
                //�����ͼ��ѡ��
                ppAxMapControl.ActiveView.FocusMap.ClearSelection();
                INetElements pNetElements = pGeoNetwork.Network as INetElements;
                IPointToEID pPtToEID = new PointToEIDClass();
                int pJunctionID = 0;
                int iUserClassID;
                int iUserID;
                int iUserSubID;
                IPoint pLocation;

                pPtToEID.SourceMap = ppAxMapControl.ActiveView.FocusMap;
                pPtToEID.GeometricNetwork = pGeoNetwork;
                pPtToEID.SnapTolerance = ppAxMapControl.ActiveView.Extent.Envelope.Width / 100;
                pPtToEID.GetNearestJunction(pPoint, out pJunctionID, out pLocation);
                if (pJunctionID == 0)
                {
                    MessageBox.Show("û�в������ٽ��ĵ�");
                }
                else
                {
                    pNetElements.QueryIDs(pJunctionID, esriElementType.esriETJunction, out iUserClassID, out iUserID, out iUserSubID);
                    INetFlag ipNetFlag = new JunctionFlagClass();
                    ipNetFlag.UserClassID = iUserClassID;
                    ipNetFlag.UserID = iUserID;
                    ipNetFlag.UserSubID = iUserSubID;

                    IMarkerSymbol pMarkerSym = new SimpleMarkerSymbolClass();
                    IRgbColor pRGBColor = new RgbColorClass();
                    pRGBColor.Red = 255;
                    pRGBColor.Green = 0;
                    pRGBColor.Blue = 0;
                    pMarkerSym.Color = pRGBColor;
                    pMarkerSym.Size = 20;
                    //�����µ�Flag

                    IEdgeFlagDisplay pEdgeFlagDisplay = new EdgeFlagDisplayClass();
                    IFlagDisplay pFlagDisplay = pEdgeFlagDisplay as IFlagDisplay;
                    pFlagDisplay.Symbol = pMarkerSym as ISymbol;
                    pFlagDisplay.Geometry = pLocation;
                    pFlagDisplay.FeatureClassID = iUserClassID;
                    pFlagDisplay.FID = iUserID;
                    pFlagDisplay.SubID = iUserSubID;

                    //���Ƹõ�
                    IScreenDisplay pScreenDisplay = ppAxMapControl.ActiveView.ScreenDisplay;
                    pScreenDisplay.StartDrawing(pScreenDisplay.hDC, 0);
                    pScreenDisplay.SetSymbol(pMarkerSym as ISymbol);
                    pScreenDisplay.DrawPoint(pLocation as IGeometry);
                    pScreenDisplay.FinishDrawing();
                    //����׷�ٽ��
                    FindStreamTraceResult(ppAxMapControl, ipNetFlag, pGeoNetwork);
                }
            }
            catch (Exception eX)
            {
                MessageBox.Show(eX.Message);

            }
        }
Example #25
0
 //������ʩ�������
 private void menuItem68_Click(object sender, EventArgs e)
 {
     axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair;
     m_BasicOperationTool = "isProfileAnalysis";
     IMap pMap = axMapControl1.ActiveView.FocusMap;
     pMap.DelayDrawing(true);
     CleanUpApp();
     //�����ʩ���������еIJ���
     IEnvelope pEnv = new EnvelopeClass();
     pEnv.XMin = 561900;
     pEnv.YMin = 42450;
     pEnv.XMax = 563800;
     pEnv.YMax = 43676;
     axMapControl1.ActiveView.Extent = pEnv;
     //�򿪸ù����漰����ͼ��
     IArray pLayerNameArray = new ArrayClass();
     pLayerNameArray.Add("Sewer Fixtures");
     pLayerNameArray.Add("Sewer Lines");
     pLayerNameArray.Add("Parcels");
     pLayerNameArray.Add("Roads");
     SetLayersForApp(pLayerNameArray);
     //ΪWater fixtures��������ͼ�㶨��
     IFeatureLayer pFeatLayer = Utility.FindFeatLayer("Sewer Fixtures", this);
     IFeatureLayerDefinition pFeatLayerDef = pFeatLayer as IFeatureLayerDefinition;
     pFeatLayerDef.DefinitionExpression = "[NODE_TYPE] = 'MH'";
     IFeatureLayer pFeatLayer2 = Utility.FindFeatLayer("Sewer Lines", this);
     pFeatLayerDef = pFeatLayer2 as IFeatureLayerDefinition;
     pFeatLayerDef.DefinitionExpression = "[LINE_TYPE] = 'MG'";
     //����ѡ��ͼ��
     for (int i = 0; i <= pMap.LayerCount - 1; i++)
     {
         if (pMap.get_Layer(i) is IFeatureLayer)
         {
             pFeatLayer2 = pMap.get_Layer(i) as IFeatureLayer;
             if (pFeatLayer2.Name == "Sewer Fixtures")
                 pFeatLayer2.Selectable = true;
             else
                 pFeatLayer2.Selectable = false;
         }
     }
     //���ָ���ļ�������
     string sUtilityNetPath;
     sUtilityNetPath = Application.StartupPath + @"\..\..\..\Data\Sewer9\data\sewer3.mdb";
     pGeoNetwork = Utility.openGeoNetwork(sUtilityNetPath, "urban", "Sewer_Network");
     pMap.DelayDrawing(false);
     axMapControl1.ActiveView.Refresh();
 }
 private void CloseWorkspace()
 {
     m_ipGeometricNetwork = null;
     m_ipPoints = null;
     m_ipPointToEID = null;
     m_ipEnumNetEID_Junctions = null;
     m_ipEnumNetEID_Edges = null;
     m_ipPolyline = null;
 }
Example #27
0
 private IEnumNetEID GetEnumNetEID(int eidToStartFrom, Dictionary<int, int> pathDictionary, INetwork network, IGeometricNetwork geomNet, esriElementType elemType)
 {
     IEnumNetEIDBuilder enumEIDBuilder = new EnumNetEIDArrayClass();
     enumEIDBuilder.Network = network;
     enumEIDBuilder.ElementType = elemType;
     if (eidToStartFrom == -1)//Add all elements to the return dictionary
     {
         foreach (KeyValuePair<int, int> kvp in pathDictionary)
         {
             int eid = kvp.Key;
             //Only add to the builder if the element type (junction or edge) is of the type we are looking for
             if (((eid < 0) && elemType == esriElementType.esriETEdge) || ((eid > 0) && elemType == esriElementType.esriETJunction))
             {
                 enumEIDBuilder.Add(Math.Abs( eid));
             }
         }
     }
     else
     {
         int eid = eidToStartFrom;
         while (eid != -99999999) // -99999999 means that there is no parent
         {
             if (((eid < 0) && elemType == esriElementType.esriETEdge) || ((eid > 0) && elemType == esriElementType.esriETJunction))
             {
                 enumEIDBuilder.Add(Math.Abs( eid));
             }
             //Get the junction or edge that feeds this junction or edge
             eid = pathDictionary[eid];
         }
     }
     return   enumEIDBuilder as IEnumNetEID;
 }
 private IFeatureClass GetFeatureClassByClassId(int classId, IGeometricNetwork geomNetwork)
 {
     IEnumFeatureClass enumFC;
     IFeatureClass fc;
     enumFC = geomNetwork.get_ClassesByType(esriFeatureType.esriFTSimpleEdge);
     fc = enumFC.Next();
     while (fc != null)
     {
         if (fc.FeatureClassID == classId) return fc;
         fc = enumFC.Next();
     }
     enumFC = geomNetwork.get_ClassesByType(esriFeatureType.esriFTComplexEdge);
     fc = enumFC.Next();
     while (fc != null)
     {
         if (fc.FeatureClassID == classId) return fc;
         fc = enumFC.Next();
     }
     return null;
 }
Example #29
0
        //上朔追踪查找管线涉及的地块
        public static void UpStreamFindParcels(MainFrm pMainFrm, IEnumNetEID pEnumResultEdges, IGeometricNetwork pGeoNetwork)
        {
            try
            {
                AxMapControl axMap = pMainFrm.getMapControl();
                IFeatureLayer pFeatLayerSewerLines = FindFeatLayer("Sewer Lines", pMainFrm);
                IFeatureLayer pFeatLayerParcels = FindFeatLayer("Parcels", pMainFrm);
                //从所选择的Sewer线特征中创建几何包
               
                IGeometryCollection pGeomBag = new GeometryBagClass();
                object missing = Type.Missing;
                int lEID;
                int iUserClassID;
                int iUserID;
                int iUserSubID;
                INetElements pNetElements = pGeoNetwork.Network as INetElements;
                pEnumResultEdges.Reset();
                IFeature pFeature;

                for (int j = 0; j <= pEnumResultEdges.Count - 1; j++)
                {
                    lEID = pEnumResultEdges.Next();
                    pNetElements.QueryIDs(lEID, esriElementType.esriETEdge, out iUserClassID, out iUserID, out iUserSubID);
                    pFeature = pFeatLayerSewerLines.FeatureClass.GetFeature(iUserID);
                    pGeomBag.AddGeometry(pFeature.Shape, ref missing, ref missing);
                    // MessageBox.Show(iUserClassID.ToString()+","+iUserID.ToString()+","+iUserSubID.ToString());
                }                                
                                //进行空间拓扑叠加操作以用于查找地块信息
                ISpatialFilter pSpatialFilter = new SpatialFilterClass();
                pSpatialFilter.Geometry = pGeomBag as IGeometry ;
                pSpatialFilter.GeometryField = "Shape";
                pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                pSpatialFilter.SearchOrder = esriSearchOrder.esriSearchOrderSpatial;
                                
                
                //获得交叉到的地块信息
                 IFeatureCursor pFeatCursor=pFeatLayerParcels.FeatureClass.Search(pSpatialFilter, false);
                //增加被选择的地块数据到地图的图形图层数据中
                ICompositeGraphicsLayer pComGraphicLayer = new CompositeGraphicsLayerClass();
                ILayer pLayer = pComGraphicLayer as ILayer ;
                pLayer.Name = "受影响的地块";
                IGraphicsContainer pGraphicContainer = pComGraphicLayer as IGraphicsContainer;
                //增加所选择的地块到图形容器中
                ISimpleFillSymbol pSymFill=new SimpleFillSymbolClass();
                IFillSymbol pFillSymbol=pSymFill as IFillSymbol;
                IRgbColor pRgbColor=new RgbColorClass();
                pRgbColor.Red=0;
                pRgbColor.Green=200;
                pRgbColor.Blue=100;
                pFillSymbol.Color=pRgbColor as IColor;
                ICartographicLineSymbol pCartoLine=new CartographicLineSymbolClass();
                IRgbColor pRgbColor2=new RgbColorClass();
                pRgbColor2.Red=100;
                pRgbColor2.Green=200;
                pRgbColor2.Blue=100;
                pCartoLine.Width=2;
                pCartoLine.Color =pRgbColor2 as IColor;
                pFillSymbol.Outline=pCartoLine;
                //创建存放所有地块特征的数组
                IArray pFeatArray = new ArrayClass();
                pFeature=pFeatCursor.NextFeature();
                while (pFeature != null)
                {
                    IElement pPolyElement = new PolygonElementClass();
                    IFillShapeElement pFillShapeElement = pPolyElement as IFillShapeElement;
                    pPolyElement.Geometry = pFeature.Shape;
                    pFillShapeElement.Symbol = pFillSymbol;
                    pGraphicContainer.AddElement(pPolyElement, 0);
                    pFeatArray.Add(pFeature);
                    pFeature = pFeatCursor.NextFeature();
                }
                axMap.AddLayer(pGraphicContainer as ILayer);
                axMap.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,null,null);
                frmUpstreamCreateOwnerList frmUpstreamCreateOwnerList1 = new frmUpstreamCreateOwnerList(pMainFrm,pFeatLayerParcels, pFeatArray);
                frmUpstreamCreateOwnerList1.Show();
            }
            catch (Exception eX)
            {
                MessageBox.Show(eX.Message);

            }

        }