Beispiel #1
0
        /// <summary>
        ///     Determines whether the specified network element corresponds to the required generic junction feature class.
        /// </summary>
        /// <param name="junctionEID">The junction EID.</param>
        /// <returns>
        ///     <c>true</c> if the specified network element corresponds to the required generic junction feature class; otherwise,
        ///     <c>false</c>.
        /// </returns>
        protected bool IsGenericJunction(int junctionEID)
        {
            if (_JunctionsClassID < 0)
            {
                // Determine the generic junction class ID.
                IFeatureClassContainer container   = (IFeatureClassContainer)this.GeometricNetwork;
                IEnumFeatureClass      enumClasses = container.Classes;
                enumClasses.Reset();

                // Iterate through all of the classes that participate in the network.
                IFeatureClass networkClass;
                while ((networkClass = enumClasses.Next()) != null)
                {
                    if (this.IsGenericJunction(networkClass))
                    {
                        _JunctionsClassID = networkClass.ObjectClassID;
                        break;
                    }
                }
            }

            // Determine the class identifier for the element.
            IEIDInfo eidInfo = this.GetEIDInfo(junctionEID, esriElementType.esriETJunction);

            // When the class ID equals the generic junction.
            return(eidInfo.Feature.Class.ObjectClassID == _JunctionsClassID);
        }
Beispiel #2
0
        private void method_6(IGeometricNetwork geometricNetwork)
        {
            INetwork        network        = geometricNetwork.Network;
            IUtilityNetwork utilityNetwork = (IUtilityNetwork)network;
            IEnumNetEID     enumNetEID     = network.CreateNetBrowser((esriElementType)2);
            IEIDHelper      eIDHelperClass = new EIDHelper();

            eIDHelperClass.GeometricNetwork           = (geometricNetwork);
            eIDHelperClass.DisplayEnvelope            = (null);
            eIDHelperClass.OutputSpatialReference     = (null);
            eIDHelperClass.ReturnFeatures             = (false);
            eIDHelperClass.ReturnGeometries           = (true);
            eIDHelperClass.PartialComplexEdgeGeometry = (true);
            IEnumEIDInfo enumEIDInfo = eIDHelperClass.CreateEnumEIDInfo(enumNetEID);

            enumEIDInfo.Reset();
            long num  = (long)enumEIDInfo.Count;
            int  num2 = 0;

            while ((long)num2 < num)
            {
                IEIDInfo          iEIDInfo          = enumEIDInfo.Next();
                int               eID               = iEIDInfo.EID;
                IGeometry         geometry          = iEIDInfo.Geometry;
                esriFlowDirection esriFlowDirection = this.method_7(geometry);
                utilityNetwork.SetFlowDirection(eID, esriFlowDirection);
                num2++;
            }
        }
Beispiel #3
0
        /// <summary>
        ///     Returns the network element information for the specified <paramref name="eid" />.
        /// </summary>
        /// <param name="eid">The eid.</param>
        /// <param name="elementType">Type of the element.</param>
        /// <returns>Returns a <see cref="IEIDInfo" /> representing the network element information</returns>
        protected IEIDInfo GetEIDInfo(int eid, esriElementType elementType)
        {
            if (elementType == esriElementType.esriETEdge)
            {
                if (_EdgesByEID.ContainsKey(eid))
                {
                    return(_EdgesByEID[eid]);
                }
            }
            else if (elementType == esriElementType.esriETJunction)
            {
                if (_JunctionsByEID.ContainsKey(eid))
                {
                    return(_JunctionsByEID[eid]);
                }
            }

            IEIDInfo eidInfo = this.GeometricNetwork.GetEIDInfo(eid, elementType);

            if (elementType == esriElementType.esriETEdge)
            {
                _EdgesByEID.Add(eid, eidInfo);
            }
            else if (elementType == esriElementType.esriETJunction)
            {
                _JunctionsByEID.Add(eid, eidInfo);
            }

            return(eidInfo);
        }
        /// <summary>
        /// 最短路径分析
        /// </summary>
        /// <param name="pMap"></param>
        /// <param name="pGeometricNet"></param>
        /// <param name="pCollection"></param>
        /// <param name="weightName"></param>
        /// <param name="pDisc"></param>
        /// <returns></returns>
        public static IPolyline DistanceFun(IMap pMap, IGeometricNetwork pGeometricNet, IPointCollection pCollection, string weightName, double pDisc)
        {
            //几何网络分析接口
            ITraceFlowSolverGEN pTraceFlowGen = new TraceFlowSolverClass() as ITraceFlowSolverGEN;
            INetSolver          pNetSolver    = pTraceFlowGen as INetSolver;
            //获取网络
            INetwork pNetwork = pGeometricNet.Network;

            //设置该网络为几何分析处理网络
            pNetSolver.SourceNetwork = pNetwork;
            //网络元素
            INetElements pNetElements = pNetwork as INetElements;

            //根据输入点建立旗帜数组
            IJunctionFlag[] pJunctionFlags = GetJunctionFlags(pMap, pGeometricNet, pCollection, pDisc);
            //将旗帜数组添加到处理类中
            pTraceFlowGen.PutJunctionOrigins(ref pJunctionFlags);
            //设置边线的权重 可以考虑使用点权重
            SetWeight(weightName, pTraceFlowGen, pNetwork);
            //获取边线和交汇点的集合
            IEnumNetEID junctionEIDs;
            IEnumNetEID netEIDS;

            object[] pRec = new object[pCollection.PointCount - 1];
            pTraceFlowGen.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out junctionEIDs, out netEIDS, pCollection.PointCount - 1, ref pRec);
            //获取最短路径
            IPolyline           pPolyline           = new PolylineClass();
            IGeometryCollection pGeometryCollection = pPolyline as IGeometryCollection;
            ISpatialReference   pSpatialReference   = pMap.SpatialReference;
            IEIDHelper          pEIDHelper          = new EIDHelperClass();

            pEIDHelper.GeometricNetwork       = pGeometricNet;
            pEIDHelper.OutputSpatialReference = pSpatialReference;
            pEIDHelper.ReturnGeometries       = true;
            IEnumEIDInfo pEnumEIDInfo = pEIDHelper.CreateEnumEIDInfo(netEIDS);
            int          Count        = pEnumEIDInfo.Count;

            pEnumEIDInfo.Reset();
            for (int i = 0; i < Count; i++)
            {
                IEIDInfo  pEIDInfo  = pEnumEIDInfo.Next();
                IGeometry pGeometry = pEIDInfo.Geometry;
                pGeometryCollection.AddGeometryCollection(pGeometry as IGeometryCollection);
            }
            return(pPolyline);
        }
        /// <summary>
        /// Get list EIDInfos by FeatureClass
        /// </summary>
        /// <param name="featureClassId">Id FeatureClass</param>
        /// <param name="junctionEIDs">object junctionEIDs</param>
        /// <param name="eidHelper">object eidHelper</param>
        /// <returns>List of IEIDInfo</returns>
        internal static List <IEIDInfo> GetEIDInfoListByFeatureClass(int featureClassId, IEnumNetEID junctionEIDs, IEIDHelper eidHelper)
        {
            List <IEIDInfo> outputEIDInfoHT = new List <IEIDInfo>();

            IEnumEIDInfo allEnumEidInfo = eidHelper.CreateEnumEIDInfo(junctionEIDs);
            IEIDInfo     eidInfo        = allEnumEidInfo.Next();

            while (eidInfo != null)
            {
                if (eidInfo.Feature.Class.ObjectClassID == featureClassId)
                {
                    outputEIDInfoHT.Add(eidInfo);
                }

                eidInfo = allEnumEidInfo.Next();
            }

            return(outputEIDInfoHT);
        }
        /// <summary>
        ///     Returns the <see cref="IEIDInfo" /> for the specified network element.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="eid">The element ID.</param>
        /// <param name="elementType">Type of the element.</param>
        /// <param name="returnFeatures">if set to <c>true</c> if the created IEIDInfo should contain features.</param>
        /// <param name="returnGeometries">if set to <c>true</c> if the created EIDInfo should contain geometries.</param>
        /// <returns>
        ///     Returns the <see cref="IEIDInfo" /> interface for the network element.
        /// </returns>
        public static IEIDInfo GetEIDInfo(this IGeometricNetwork source, int eid, esriElementType elementType, bool returnFeatures, bool returnGeometries)
        {
            if (source == null)
            {
                return(null);
            }

            IEnumNetEID enumNetEID = source.CreateEnumNetEID(elementType, eid);

            IEIDHelper eidHelper = new EIDHelperClass();

            eidHelper.GeometricNetwork = source;
            eidHelper.ReturnFeatures   = returnFeatures;
            eidHelper.ReturnGeometries = returnGeometries;

            IEnumEIDInfo enumEIDInfo = eidHelper.CreateEnumEIDInfo(enumNetEID);
            IEIDInfo     eidInfo     = enumEIDInfo.Next();

            return(eidInfo);
        }
Beispiel #7
0
        private void method_5(IGeometricNetwork geometricNetwork)
        {
            INetwork        network        = geometricNetwork.Network;
            IUtilityNetwork utilityNetwork = (IUtilityNetwork)network;
            IEnumNetEID     enumNetEID     = network.CreateNetBrowser((esriElementType)2);
            IEIDHelper      eIDHelperClass = new EIDHelper();

            eIDHelperClass.GeometricNetwork           = (geometricNetwork);
            eIDHelperClass.DisplayEnvelope            = (null);
            eIDHelperClass.OutputSpatialReference     = (null);
            eIDHelperClass.ReturnFeatures             = (true);
            eIDHelperClass.ReturnGeometries           = (true);
            eIDHelperClass.PartialComplexEdgeGeometry = (true);
            IEnumEIDInfo enumEIDInfo = eIDHelperClass.CreateEnumEIDInfo(enumNetEID);

            enumEIDInfo.Reset();
            long num  = (long)enumEIDInfo.Count;
            int  num2 = 0;

            while ((long)num2 < num)
            {
                IEIDInfo iEIDInfo = enumEIDInfo.Next();
                int      eID      = iEIDInfo.EID;
                IFeature feature  = iEIDInfo.Feature;
                int      num3     = feature.Fields.FindField("流向");
                if (num3 < 0)
                {
                    utilityNetwork.SetFlowDirection(eID, (esriFlowDirection)1);
                }
                if (Convert.ToBoolean(feature.get_Value(num3)))
                {
                    utilityNetwork.SetFlowDirection(eID, (esriFlowDirection)2);
                }
                else
                {
                    utilityNetwork.SetFlowDirection(eID, (esriFlowDirection)1);
                }
                num2++;
            }
        }
        /// <summary>
        /// object polyline. Distance negative -> upstream
        /// </summary>
        /// <param name="geometricNetwork">object geometricNetwork</param>
        /// <param name="resultEdges">objects resultEdges</param>
        /// <param name="distance">value of distance</param>
        /// <param name="point">object point</param>
        /// <param name="offset">offset of polyline</param>
        /// <param name="messageInfo">info on result</param>
        /// <returns>object IGeometry (polyline or point)</returns>
        internal static IGeometry GetPolylinePosAlong(ESRI.ArcGIS.Geodatabase.IGeometricNetwork geometricNetwork, IEnumNetEID resultEdges, double distance, IPoint point, double?offset, ref string messageInfo)
        {
            IGeometry geometryBag = new GeometryBagClass();

            geometryBag.SpatialReference = point.SpatialReference;
            IGeometryCollection geometryCollection = geometryBag as IGeometryCollection;

            IEIDHelper eidHelper = new EIDHelperClass();

            eidHelper.GeometricNetwork = geometricNetwork;
            eidHelper.ReturnGeometries = true;
            eidHelper.ReturnFeatures   = false;

            IEnumEIDInfo enumEIDinfo = eidHelper.CreateEnumEIDInfo(resultEdges);

            enumEIDinfo.Reset();
            IEIDInfo eidInfo = enumEIDinfo.Next();

            while (eidInfo != null)
            {
                IGeometry geometry = eidInfo.Geometry;
                geometryCollection.AddGeometry(geometry);
                eidInfo = enumEIDinfo.Next();
            }

            ITopologicalOperator unionedPolyline = new PolylineClass();

            unionedPolyline.ConstructUnion(geometryBag as IEnumGeometry);

            IPolyline pl = unionedPolyline as IPolyline;

            if (distance < 0)
            {
                pl.ReverseOrientation();
                distance = Math.Abs(distance);
            }

            IMAware mAware = pl as IMAware;

            mAware.MAware = true;
            IMSegmentation3 mSegmentation = unionedPolyline as IMSegmentation3;

            mSegmentation.SetMsAsDistance(false);

            IPoint ptTmp             = new PointClass();
            double distanceAlong     = 0;
            double distanceFromCurve = 0;
            bool   rightSide         = false;

            pl.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, point, false, ptTmp, ref distanceAlong, ref distanceFromCurve, ref rightSide);
            object mStartArray = mSegmentation.GetMsAtDistance(distanceAlong, false);

            double[]  mStart             = mStartArray as double[];
            double    distanceDownStream = distanceAlong + distance;
            IPolyline resultPolyline     = mSegmentation.GetSubcurveBetweenMs(mStart[0], distanceDownStream) as IPolyline;

            if (resultPolyline.IsEmpty)
            {
                return(point);
            }

            if (mSegmentation.MMax < distanceDownStream)
            {
                messageInfo = "The set distance exceeds the length of network";
            }

            return(Helper.ConstructOffset(resultPolyline, offset));
        }
        private void StartAnalysis(IFeature feature)
        {
            if (feature.FeatureType != esriFeatureType.esriFTSimpleJunction)
            {
                MessageService.Current.Warn("请选择管线点");
                return;
            }
            if (!_pipelineConfig.IsPipelineLayer(feature.Class.AliasName, enumPipelineDataType.Point))
            {
                MessageService.Current.Warn("请选择管线点");
                return;
            }
            double snapDist = CommonUtils.ConvertPixelsToMapUnits(_context.ActiveView,
                                                                  _context.Config.SnapTolerance);
            IBasicLayerInfo lineConfig =
                _plugin.PipeConfig.GetBasicLayerInfo(feature.Class as IFeatureClass) as IBasicLayerInfo;

            if (this._startPoint == null && _startEid == 0)
            {
                //开始记录起始点
                IPipelineLayer oldLayer = _pipelineConfig.GetPipelineLayer(feature.Class.AliasName,
                                                                           enumPipelineDataType.Point);
                if (oldLayer == null)
                {
                    MessageService.Current.Warn("你选择的图层不是合法的管线图层!");
                    return;
                }
                List <IBasicLayerInfo> basicInfos = oldLayer.GetLayers(enumPipelineDataType.Junction);

                IFeatureClass featureClass = basicInfos.Count > 0 ? basicInfos[0].FeatureClass : null;
                if (featureClass == null)
                {
                    MessageService.Current.Warn("管线图层没有构建网络图层!");
                    return;
                }
                INetworkClass networkClass = featureClass as INetworkClass;
                _geometricNetwork = networkClass.GeometricNetwork;
                IPointToEID pnToEid = new PointToEIDClass();
                pnToEid.GeometricNetwork = _geometricNetwork;
                pnToEid.SnapTolerance    = snapDist;
                pnToEid.SourceMap        = _context.FocusMap;
                pnToEid.GetNearestJunction(feature.Shape as IPoint, out _startEid, out _startPoint);
                return;
            }
            IPipelineLayer newLayer = _pipelineConfig.GetPipelineLayer(feature.Class.AliasName,
                                                                       enumPipelineDataType.Point);

            if (newLayer == null)
            {
                MessageService.Current.Warn("你选择的图层不是合法的管线图层!");
                return;
            }
            List <IBasicLayerInfo> basicInfos1 = newLayer.GetLayers(enumPipelineDataType.Junction);

            IFeatureClass featureClass2 = basicInfos1.Count > 0 ? basicInfos1[0].FeatureClass : null;

            if (featureClass2 == null)
            {
                MessageService.Current.Warn("第二个管线图层没有构建网络图层!");
                return;
            }
            INetworkClass networkClass2 = featureClass2 as INetworkClass;

            if (networkClass2.GeometricNetwork != _geometricNetwork)
            {
                if (MessageService.Current.Ask("两个点位属于不同的网络图层,使用第二个网络图层作为分析图层吗?") == false)
                {
                    return;
                }
                _geometricNetwork = networkClass2.GeometricNetwork;
                IPointToEID pnToEid = new PointToEIDClass();
                pnToEid.GeometricNetwork = _geometricNetwork;
                pnToEid.SnapTolerance    = snapDist;
                pnToEid.SourceMap        = _context.FocusMap;
                pnToEid.GetNearestJunction(feature.Shape as IPoint, out _startEid, out _startPoint);
                return;
            }

            try
            {
                IPointToEID pntEid = new PointToEIDClass();
                pntEid.GeometricNetwork = _geometricNetwork;
                pntEid.SourceMap        = _context.FocusMap;
                pntEid.SnapTolerance    = snapDist;

                pntEid.GetNearestJunction(feature.Shape as IPoint, out _endEid, out _endPoint);
                if (_endEid < 1)
                {
                    MessageService.Current.Warn("未能找到第二个分析点!");
                    return;
                }
                if (_startEid == _endEid)
                {
                    MessageService.Current.Warn("起点终点为同一个点!");
                    return;
                }

                INetElements  netElements  = _geometricNetwork.Network as INetElements;
                INetworkClass networkClass = feature.Class as INetworkClass;

                IJunctionFlag[] array   = new JunctionFlag[2];
                INetFlag        netFlag = new JunctionFlag() as INetFlag;

                int userClassID;
                int userID;
                int userSubID;
                netElements.QueryIDs(_endEid, esriElementType.esriETJunction, out userClassID, out userID, out userSubID);
                netFlag.UserClassID = (userClassID);
                netFlag.UserID      = (userID);
                netFlag.UserSubID   = (userSubID);
                IJunctionFlag value = netFlag as IJunctionFlag;
                array.SetValue(value, 0);
                INetFlag netFlag2 = new JunctionFlag() as INetFlag;
                netElements.QueryIDs(_startEid, esriElementType.esriETJunction, out userClassID,
                                     out userID, out userSubID);
                netFlag2.UserClassID = (userClassID);
                netFlag2.UserID      = (userID);
                netFlag2.UserSubID   = (userSubID);
                value = (netFlag2 as IJunctionFlag);
                array.SetValue(value, 1);
                ITraceFlowSolverGEN traceFlowSolverGEN = new TraceFlowSolver() as ITraceFlowSolverGEN;
                INetSolver          netSolver          = traceFlowSolverGEN as INetSolver;
                netSolver.SourceNetwork = _geometricNetwork.Network;
                traceFlowSolverGEN.PutJunctionOrigins(ref array);
                object[]    array2 = new object[1];
                IEnumNetEID enumNetEID;
                IEnumNetEID enumNetEID2;
                traceFlowSolverGEN.FindPath((esriFlowMethod)2, (esriShortestPathObjFn)1, out enumNetEID,
                                            out enumNetEID2, 1, ref array2);
                if (this.ipolyline_0 == null)
                {
                    this.ipolyline_0 = new Polyline() as IPolyline;
                }
                IGeometryCollection geometryCollection = this.ipolyline_0 as IGeometryCollection;
                geometryCollection.RemoveGeometries(0, geometryCollection.GeometryCount);
                if (enumNetEID2.Count <= 0)
                {
                    this.ifeature_0 = null;
                    MessageBox.Show("两点之间不存在路径可以连通!");
                }
                else
                {
                    ShowShortObjectForm showShortObjectForm = new ShowShortObjectForm(_context);
                    showShortObjectForm.pApp = _context;
                    ISpatialReference spatialReference = _context.FocusMap.SpatialReference;
                    IEIDHelper        eIDHelperClass   = new EIDHelper();
                    eIDHelperClass.GeometricNetwork       = (networkClass.GeometricNetwork);
                    eIDHelperClass.OutputSpatialReference = (spatialReference);
                    eIDHelperClass.ReturnGeometries       = (true);
                    eIDHelperClass.ReturnFeatures         = (true);
                    IEnumEIDInfo enumEIDInfo = eIDHelperClass.CreateEnumEIDInfo(enumNetEID2);
                    int          count       = enumEIDInfo.Count;
                    enumEIDInfo.Reset();
                    for (int i = 0; i < count; i++)
                    {
                        IEIDInfo  iEIDInfo = enumEIDInfo.Next();
                        IGeometry geometry = iEIDInfo.Geometry;
                        if (i == 0)
                        {
                            showShortObjectForm.AddPipeName(this.string_0);
                        }
                        showShortObjectForm.AddFeature(iEIDInfo.Feature);
                        geometryCollection.AddGeometryCollection(geometry as IGeometryCollection);
                    }
                    showShortObjectForm.AddShortPath(this.ipolyline_0);
                    showShortObjectForm.AddLenght(this.ipolyline_0.Length);
                    this.ifeature_2 = feature;
                    EsriUtils.ZoomToGeometry(this.ipolyline_0, _context.MapControl.Map, 1.3);
                    FlashUtility.FlashGeometry(this.ipolyline_0, _context.MapControl);
                    this.ifeature_0   = null;
                    _startEid         = 0;
                    _startPoint       = null;
                    _geometricNetwork = null;
                    showShortObjectForm.Show();
                }
            }
            catch (Exception ex)
            {
                this.ifeature_0 = null;
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #10
0
        public void GetFlow(IMap pMap)
        {
            int num4;

            this.m_pPointcol = new MultipointClass();
            this.m_eFlowDirection.Clear();
            this.m_angle.Clear();
            INetwork        network  = NetworkAnalyst.m_pAnalystGN.Network;
            IUtilityNetwork network2 = network as IUtilityNetwork;
            IEnumNetEID     netEIDs  = network.CreateNetBrowser(esriElementType.esriETEdge);
            IEnumNetEID     teid2    = network.CreateNetBrowser(esriElementType.esriETJunction);

            netEIDs.Reset();
            int        count  = netEIDs.Count;
            int        num2   = teid2.Count;
            IEIDHelper helper = new EIDHelperClass
            {
                GeometricNetwork       = NetworkAnalyst.m_pAnalystGN,
                OutputSpatialReference = pMap.SpatialReference,
                ReturnGeometries       = true,
                ReturnFeatures         = true
            };
            IEnumEIDInfo info = helper.CreateEnumEIDInfo(teid2);
            int          num3 = info.Count;

            teid2.Reset();
            info.Reset();
            IPointCollection points = new MultipointClass();
            object           before = Missing.Value;

            for (num4 = 0; num4 < num2; num4++)
            {
                IPoint inPoint = info.Next().Geometry as IPoint;
                points.AddPoint(inPoint, ref before, ref before);
            }
            info = null;
            info = helper.CreateEnumEIDInfo(netEIDs);
            num3 = info.Count;
            netEIDs.Reset();
            info.Reset();
            IList list  = new ArrayList();
            ILine line  = new LineClass();
            IList list2 = new ArrayList();
            int   num5  = 0;

            for (num4 = 0; num4 < count; num4++)
            {
                int edgeEID = netEIDs.Next();
                this.m_eFlowDirection.Add(network2.GetFlowDirection(edgeEID));
                IEIDInfo         info2         = info.Next();
                IGeometry        geometry      = info2.Geometry;
                IEdgeFeature     feature       = info2.Feature as IEdgeFeature;
                IPointCollection points2       = geometry as IPointCollection;
                int                 pointCount = points2.PointCount;
                IPoint              other      = new PointClass();
                IPoint[]            pointArray = new IPoint[pointCount];
                IRelationalOperator @operator  = points as IRelationalOperator;
                IPointCollection    points3    = new MultipointClass();
                int                 num8       = 0;
                for (int i = 0; i < pointCount; i++)
                {
                    other = points2.get_Point(i);
                    if (@operator.Contains(other))
                    {
                        IPoint point3 = points2.get_Point(i);
                        points3.AddPoint(point3, ref before, ref before);
                        pointArray[i] = point3;
                    }
                    else
                    {
                        pointArray[i] = null;
                    }
                }
                IPoint[] pointArray2 = new IPoint[pointCount];
                num8 = points3.PointCount;
                int index = -1;
                if (num5 < (points3.PointCount - 1))
                {
                    for (int j = 0; j < pointCount; j++)
                    {
                        if (pointArray[j] != null)
                        {
                            index++;
                        }
                        if (index == num5)
                        {
                            index = j;
                            break;
                        }
                    }
                    IPoint point4 = new PointClass();
                    pointArray2[index]     = pointArray[index];
                    pointArray2[index + 1] = points2.get_Point(index + 1);
                    point4.X = (pointArray2[index].X + pointArray2[index + 1].X) / 2.0;
                    point4.Y = (pointArray2[index].Y + pointArray2[index + 1].Y) / 2.0;
                    this.m_pPointcol.AddPoint(point4, ref before, ref before);
                    line.FromPoint = pointArray2[index];
                    line.ToPoint   = pointArray2[index + 1];
                    this.m_angle.Add(line.Angle);
                    num5++;
                    if (num5 == (num8 - 1))
                    {
                        num5 = 0;
                    }
                }
            }
            this.ShowFlow(pMap as IActiveView);
        }
Beispiel #11
0
        private void SetButton_Click(object obj, EventArgs eventArgs)
        {
            int count  = this.listJunctionFlag.Count;
            int count2 = this.listEdgeFlag.Count;
            int count3 = this.listJunctionBarrier.Count;
            int count4 = this.listEdgeBarrier.Count;

            if (count < 1 && count2 < 1)
            {
                MessageBox.Show("请用户选择要分析的点或线!");
            }
            else
            {
                IEdgeFlag[]     array        = new EdgeFlag[count2];
                IJunctionFlag[] array2       = new JunctionFlag[count];
                INetwork        network      = null;
                INetworkClass   networkClass = null;
                if (count > 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        IFeature feature = this.listJunctionFlag[i];
                        networkClass = (feature.Class as INetworkClass);
                        network      = networkClass.GeometricNetwork.Network;
                        INetElements           netElements           = network as INetElements;
                        INetFlag               netFlag               = new JunctionFlag() as INetFlag;
                        ISimpleJunctionFeature simpleJunctionFeature = feature as ISimpleJunctionFeature;
                        int userClassID;
                        int userID;
                        int userSubID;
                        netElements.QueryIDs(simpleJunctionFeature.EID, (esriElementType)1, out userClassID, out userID,
                                             out userSubID);
                        netFlag.UserClassID = (userClassID);
                        netFlag.UserID      = (userID);
                        netFlag.UserSubID   = (userSubID);
                        IJunctionFlag junctionFlag = netFlag as IJunctionFlag;
                        array2[i] = junctionFlag;
                    }
                }
                if (count2 > 0)
                {
                    for (int j = 0; j < count2; j++)
                    {
                        IFeature feature2 = this.listEdgeFlag[j];
                        networkClass = (feature2.Class as INetworkClass);
                        network      = networkClass.GeometricNetwork.Network;
                        INetElements       netElements2      = network as INetElements;
                        INetFlag           netFlag2          = new EdgeFlag() as INetFlag;
                        ISimpleEdgeFeature simpleEdgeFeature = feature2 as ISimpleEdgeFeature;
                        int userClassID2;
                        int userID2;
                        int userSubID2;
                        netElements2.QueryIDs(simpleEdgeFeature.EID, (esriElementType)2, out userClassID2, out userID2,
                                              out userSubID2);
                        netFlag2.UserClassID = (userClassID2);
                        netFlag2.UserID      = (userID2);
                        netFlag2.UserSubID   = (userSubID2);
                        IEdgeFlag edgeFlag = netFlag2 as IEdgeFlag;
                        array[j] = edgeFlag;
                    }
                }
                ITraceFlowSolverGEN    traceFlowSolverGEN    = new TraceFlowSolver() as ITraceFlowSolverGEN;
                INetSolver             netSolver             = traceFlowSolverGEN as INetSolver;
                INetElementBarriersGEN netElementBarriersGEN = new NetElementBarriers();
                netElementBarriersGEN.Network     = (network);
                netElementBarriersGEN.ElementType = (esriElementType)(1);
                int[] array3 = new int[count3];
                int   num    = 0;
                if (count3 > 0)
                {
                    for (int k = 0; k < count3; k++)
                    {
                        IFeature feature3 = this.listJunctionBarrier[k];
                        networkClass = (feature3.Class as INetworkClass);
                        network      = networkClass.GeometricNetwork.Network;
                        INetElements netElements3 = network as INetElements;
                        new EdgeFlag();
                        ISimpleJunctionFeature simpleJunctionFeature2 = feature3 as ISimpleJunctionFeature;
                        int num2;
                        int num3;
                        netElements3.QueryIDs(simpleJunctionFeature2.EID, (esriElementType)1, out num, out num2,
                                              out num3);
                        array3[k] = num2;
                    }
                    netElementBarriersGEN.SetBarriers(num, ref array3);
                    netSolver.set_ElementBarriers((esriElementType)1, (INetElementBarriers)netElementBarriersGEN);
                }
                INetElementBarriersGEN netElementBarriersGEN2 = new NetElementBarriers();
                netElementBarriersGEN2.Network     = (network);
                netElementBarriersGEN2.ElementType = (esriElementType)(2);
                int[] array4 = new int[count4];
                if (count4 > 0)
                {
                    for (int l = 0; l < count4; l++)
                    {
                        IFeature feature4 = this.listEdgeBarrier[l];
                        networkClass = (feature4.Class as INetworkClass);
                        network      = networkClass.GeometricNetwork.Network;
                        INetElements netElements4 = network as INetElements;
                        new EdgeFlag();
                        ISimpleEdgeFeature simpleEdgeFeature2 = feature4 as ISimpleEdgeFeature;
                        int num4;
                        int num5;
                        netElements4.QueryIDs(simpleEdgeFeature2.EID, (esriElementType)2, out num, out num4, out num5);
                        array4[l] = num4;
                    }
                    netElementBarriersGEN2.SetBarriers(num, ref array4);
                    netSolver.set_ElementBarriers((esriElementType)2, (INetElementBarriers)netElementBarriersGEN2);
                }
                netSolver.SourceNetwork = (network);
                if (count > 0)
                {
                    traceFlowSolverGEN.PutJunctionOrigins(ref array2);
                }
                if (count2 > 0)
                {
                    traceFlowSolverGEN.PutEdgeOrigins(ref array);
                }
                IEnumNetEID enumNetEID  = null;
                IEnumNetEID enumNetEID2 = null;
                object[]    array5      = new object[1];
                if (this.WayCom.SelectedIndex == 0)
                {
                    traceFlowSolverGEN.FindSource(0, (esriShortestPathObjFn)1, out enumNetEID, out enumNetEID2,
                                                  count + count2, ref array5);
                }
                if (this.WayCom.SelectedIndex == 1)
                {
                    traceFlowSolverGEN.FindSource((esriFlowMethod)1, (esriShortestPathObjFn)1, out enumNetEID,
                                                  out enumNetEID2, count + count2, ref array5);
                }
                IPolyline           polyline           = new Polyline() as IPolyline;
                IGeometryCollection geometryCollection = polyline as IGeometryCollection;
                ISpatialReference   spatialReference   = this.m_iApp.FocusMap.SpatialReference;
                IEIDHelper          iEIDHelper         = new EIDHelper();
                iEIDHelper.GeometricNetwork       = (networkClass.GeometricNetwork);
                iEIDHelper.OutputSpatialReference = (spatialReference);
                iEIDHelper.ReturnGeometries       = (true);
                iEIDHelper.ReturnFeatures         = (true);
                int selectedIndex = this.LayerCom.SelectedIndex;
                if (selectedIndex >= 0 && this.MapControl != null)
                {
                    this.LayerCom.SelectedItem.ToString();
                    IFeatureLayer ifeatureLayer_ = ((TrackingAnalyForm.LayerInfo) this.LayerCom.SelectedItem)._layer;
                    if (ifeatureLayer_ != null)
                    {
                        IFeatureSelection featureSelection = (IFeatureSelection)ifeatureLayer_;
                        featureSelection.Clear();
                        if (enumNetEID2 != null)
                        {
                            IEnumEIDInfo enumEIDInfo = iEIDHelper.CreateEnumEIDInfo(enumNetEID2);
                            int          count5      = enumEIDInfo.Count;
                            enumEIDInfo.Reset();
                            for (int m = 0; m < count5; m++)
                            {
                                IEIDInfo iEIDInfo = enumEIDInfo.Next();
                                featureSelection.Add(iEIDInfo.Feature);
                                IGeometry geometry = iEIDInfo.Geometry;
                                geometryCollection.AddGeometryCollection(geometry as IGeometryCollection);
                            }
                        }
                        featureSelection.SelectionSet.Refresh();
                        IActiveView activeView = this.m_iApp.ActiveView;
                        activeView.Refresh();
                        CMapOperator.ShowFeatureWithWink(this.m_iApp.ActiveView.ScreenDisplay, polyline);
                    }
                }
            }
        }
        public static List <int> StreamTrace(IGeometricNetwork geometricNetwork, StartFlagEdge edge, List <int> disabledFeatureClassIds, StopperJunctions stoppers, bool isUpStream, int maxFeatureCount, ServerLogger logger)
        {
            esriFlowMethod direction = isUpStream ? esriFlowMethod.esriFMUpstream : esriFlowMethod.esriFMDownstream;

            if (null == geometricNetwork || null == edge || maxFeatureCount <= 0)
            {
                return(null);
            }
            ITraceFlowSolverGEN traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN;
            INetSolver          netSolver       = traceFlowSolver as INetSolver;

            netSolver.SourceNetwork = geometricNetwork.Network;
            INetFlag netFlag = new EdgeFlagClass();

            netFlag.UserClassID = edge.FeatureClassID;
            netFlag.UserID      = edge.FeatureID;
            //no idea when to assign -1, when to do 0
            netFlag.UserSubID = -1;
            traceFlowSolver.PutEdgeOrigins(new IEdgeFlag[1] {
                netFlag as IEdgeFlag
            });
            if (null != disabledFeatureClassIds)
            {
                foreach (int il in disabledFeatureClassIds)
                {
                    if (il > 0)
                    {
                        netSolver.DisableElementClass(il);
                    }
                }
            }
            if (null != stoppers && null != stoppers.Stoppers && stoppers.Stoppers.Length > 0)
            {
                INetElementBarriersGEN netBarriersGEN = null;
                netBarriersGEN             = new NetElementBarriersClass() as INetElementBarriersGEN;
                netBarriersGEN.ElementType = esriElementType.esriETJunction;
                netBarriersGEN.Network     = geometricNetwork.Network;
                netBarriersGEN.SetBarriers(stoppers.FeatureClassID, stoppers.Stoppers);
                netSolver.set_ElementBarriers(esriElementType.esriETJunction, netBarriersGEN as INetElementBarriers);
            }

            IEnumNetEID junctionEIDs = null;
            IEnumNetEID edgeEIDs     = null;

            traceFlowSolver.TraceIndeterminateFlow = false;
            try
            {
                traceFlowSolver.FindFlowElements(direction, esriFlowElements.esriFEEdges, out junctionEIDs, out edgeEIDs);
                if (null != edgeEIDs)
                {
                    if (edgeEIDs.Count <= maxFeatureCount)
                    {
                        IEIDHelper eidHelper = new EIDHelperClass();
                        eidHelper.GeometricNetwork = geometricNetwork;
                        eidHelper.ReturnGeometries = false;
                        eidHelper.ReturnFeatures   = true;
                        //eidHelper.AddField("FType");
                        IEnumEIDInfo eidInfos = eidHelper.CreateEnumEIDInfo(edgeEIDs);
                        eidInfos.Reset();
                        IEIDInfo   eidInfo = null;
                        List <int> ftrs    = new List <int>();
                        //IFeature cadFtr = null;
                        //int ftype;
                        while ((eidInfo = eidInfos.Next()) != null)
                        {
                            ftrs.Add(eidInfo.Feature.OID);

                            /*cadFtr = eidInfo.Feature;
                             * if (null != cadFtr.get_Value(edgeTypeId) && int.TryParse(cadFtr.get_Value(edgeTypeId).ToString(), out ftype))
                             * {
                             *  if(460 == ftype || 558 == ftype)
                             *      ftrs.Add(cadFtr);
                             * }*/
                        }
                        return(ftrs);
                    }
                }
            }
            catch (Exception e)
            {
                if (null != logger)
                {
                    logger.LogMessage(ServerLogger.msgType.error, typeof(AOUtilities).Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, ErrorCode, e.Message);
                }
            }
            finally
            {
                ReleaseCOMObj(traceFlowSolver);
            }
            return(null);
        }
Beispiel #13
0
        /// <summary>
        /// return a featureSet from EIDs
        /// </summary>
        /// <param name="eids">object EIDs</param>
        /// <param name="featureSets">array JsonObject featureSet</param>
        protected void GetTrace(IEnumNetEID eids, out JsonObject[] featureSets)
        {
            IEIDHelper eidHelper = new EIDHelperClass();

            eidHelper.GeometricNetwork = this.geometricNetwork;
            eidHelper.ReturnGeometries = true;
            eidHelper.ReturnFeatures   = true;

            Dictionary <int, IPair <List <int>, IFeatureClass> > dictionary = new Dictionary <int, IPair <List <int>, IFeatureClass> >();
            IEnumEIDInfo enumEIDinfo = eidHelper.CreateEnumEIDInfo(eids);

            enumEIDinfo.Reset();
            IEIDInfo eidInfo = enumEIDinfo.Next();

            while (eidInfo != null)
            {
                IFeatureClass featureClass   = eidInfo.Feature.Class as IFeatureClass;
                IFeature      feature        = eidInfo.Feature;
                int           featureClassID = featureClass.FeatureClassID;
                if (!dictionary.ContainsKey(featureClassID))
                {
                    IPair <List <int>, IFeatureClass> pair = new Pair <List <int>, IFeatureClass>(new List <int>(), featureClass);
                    dictionary.Add(featureClassID, pair);
                }

                dictionary[featureClassID].First.Add(feature.OID);
                eidInfo = enumEIDinfo.Next();
            }

            List <JsonObject> jsonObjects = new List <JsonObject>();

            foreach (int i in dictionary.Keys)
            {
                IPair <List <int>, IFeatureClass> pair = dictionary[i];
                List <int>    listOIDs     = pair.First;
                IFeatureClass featureClass = pair.Second;

                IQueryFilter2 queryFilter = new QueryFilterClass();
                if (this.OutFields[0] != "*")
                {
                    List <string> listFields = new List <string>();
                    Array.ForEach(
                        this.OutFields,
                        s =>
                    {
                        if (featureClass.Fields.FindField(s) != -1)
                        {
                            listFields.Add(s);
                        }
                    });

                    if (listFields.Count == 0)
                    {
                        queryFilter.SubFields = featureClass.OIDFieldName;
                    }
                    else
                    {
                        listFields.Each((s, index) =>
                        {
                            if (index == 0)
                            {
                                queryFilter.SubFields = s;
                            }
                            else
                            {
                                queryFilter.AddField(s);
                            }
                        });

                        if (!Array.Exists(this.OutFields, s => s == featureClass.OIDFieldName))
                        {
                            queryFilter.AddField(featureClass.OIDFieldName);
                        }

                        if (!Array.Exists(this.OutFields, s => s == featureClass.ShapeFieldName))
                        {
                            queryFilter.AddField(featureClass.ShapeFieldName);
                        }
                    }
                }

                queryFilter.WhereClause = featureClass.OIDFieldName + " IN (" + string.Join(",", Array.ConvertAll <int, string>(listOIDs.ToArray(), s => s.ToString(CultureInfo.InvariantCulture))) + ")";

                IRecordSet recordset = Helper.ConvertToRecordset(featureClass, queryFilter);
                jsonObjects.Add(new JsonObject(Encoding.UTF8.GetString(Conversion.ToJson(recordset))));
            }

            featureSets = jsonObjects.ToArray();
        }
Beispiel #14
0
 /// <summary>
 ///     Gets the node that will be added to the graph.
 /// </summary>
 /// <param name="edge">The edge feature.</param>
 /// <param name="source">The source junction feature.</param>
 /// <param name="target">The target junction feature.</param>
 /// <param name="sourceAlreadyVisited">if set to <c>true</c> if the source junction has already been visited by the trace.</param>
 /// <param name="targetAlreadyVisited">if set to <c>true</c> if the target junction has already been visited by the trace.</param>
 /// <returns>
 ///     Returns an <see cref="AdjacencyNode" /> representing the edge and junctions.
 /// </returns>
 protected override AdjacencyNode GetAdjacencyNode(IEIDInfo edge, IEIDInfo source, IEIDInfo target, bool sourceAlreadyVisited, bool targetAlreadyVisited)
 {
     return(new AdjacencyNode(edge, source, target, sourceAlreadyVisited, targetAlreadyVisited));
 }