A4WaterUtilities.GeoNetTools.CalculateFlowAccumAtLocation C# (CSharp) Method

CalculateFlowAccumAtLocation() public static method

public static CalculateFlowAccumAtLocation ( List sumFlowAcc, IApplication app, double snapTol ) : void
sumFlowAcc List
app IApplication
snapTol double
return void
        public static void CalculateFlowAccumAtLocation(List<FlowLayerDetails> sumFlowAcc, IApplication app, double snapTol)
        {
            IMap pMap = null;

            IFeatureLayer pFLayer = null;

            IFeatureCursor pFCursor = null;
            IFeature pFeature = null;

            IPointToEID pPointToEid = null;

            string retAcc = "";
            int lSumFieldLoc;

            int lEID;
            IPoint pSnappedPoint = null;
            INetElements pNetElements = null;
            try
            {
                if (app == null)
                    return;
                pMap = ((app.Document as IMxDocument).FocusMap);
                if (pMap == null)
                    return;
                if (sumFlowAcc == null)
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20c"));
                if (sumFlowAcc.Count == 0)
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20c"));
                bool flowCalced = false;
                foreach (FlowLayerDetails sumAcc in sumFlowAcc)
                {
                    if (flowCalced == true)
                        break;

                    bool boolFoundAsLayer = true;

                    pFLayer = Globals.FindLayer(app, sumAcc.LayerName, ref boolFoundAsLayer) as IFeatureLayer;
                    if (pFLayer == null)
                    {
                        //MessageBox.Show(sumAcc.LayerName + " feature layer not found.\nAny selected features in this layer will be analyzed for acculmuation.");
                        continue;
                    }

                    if (pFLayer.FeatureClass == null)
                    {
                        MessageBox.Show(sumAcc.LayerName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20a"));
                        continue;
                    }

                    lSumFieldLoc = pFLayer.FeatureClass.Fields.FindField(sumAcc.SumFlowField);
                    if (lSumFieldLoc == -1)
                    {
                        MessageBox.Show(sumAcc.LayerName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20b") + sumAcc.SumFlowField + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20e"));
                        return;
                    }

                    lEID = -1;
                    //Convert pixcel search distance to real world (map units)
                    //dRWSearchTolerance = c_iSearchTolerance;

                    //Find the closest network junction element to the user specified point

                    pPointToEid = new PointToEIDClass();
                    pPointToEid.GeometricNetwork = ((INetworkClass)pFLayer.FeatureClass).GeometricNetwork;
                    pPointToEid.SourceMap = pMap;
                    pPointToEid.SnapTolerance = snapTol;
                    bool bTest = false;
                    if (pFLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline || pFLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryLine)
                    {
                        double dblPercAlong = 0;

                        pPointToEid.GetNearestEdge((app.Document as IMxDocument).CurrentLocation, out lEID, out pSnappedPoint, out dblPercAlong);

                        if (pSnappedPoint == null)
                            continue;
                        if (lEID == 0)
                            continue;
                        //Get the complete id for the network element
                        pNetElements = (((INetworkClass)pFLayer.FeatureClass).GeometricNetwork.Network) as INetElements;

                        bTest = pNetElements.IsValidElement(lEID, esriElementType.esriETEdge);
                        pFeature = Globals.GetFeatureByEID(lEID, ((INetworkClass)pFLayer.FeatureClass).GeometricNetwork, pMap, esriElementType.esriETEdge);
                    }
                    else if (pFLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint)
                    {
                        pPointToEid.GetNearestJunction((app.Document as IMxDocument).CurrentLocation, out lEID, out pSnappedPoint);

                        if (pSnappedPoint == null)
                            continue;
                        if (lEID == 0)
                            continue;
                        //Get the complete id for the network element
                        pNetElements = (((INetworkClass)pFLayer.FeatureClass).GeometricNetwork.Network) as INetElements;

                        bTest = pNetElements.IsValidElement(lEID, esriElementType.esriETJunction);
                        pFeature = Globals.GetFeatureByEID(lEID, ((INetworkClass)pFLayer.FeatureClass).GeometricNetwork, pMap, esriElementType.esriETJunction);
                    }
                    if (bTest && pFeature != null)
                    {

                        retAcc = Globals.ReturnAccumulation(ref app, ref pFeature, sumAcc.WeightName, sumAcc.FlowDirection);
                        if (Globals.IsNumeric(retAcc))
                        {
                            MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_20b") + pFeature.OID + A4LGSharedFunctions.Localizer.GetString("In") + pFLayer.Name + A4LGSharedFunctions.Localizer.GetString("Is") + retAcc + ".");
                            //pFeature.set_Value(lSumFieldLoc, retAcc);
                            //pFeature.Store();
                        }
                    }
                    flowCalced = true;

                }

                if (flowCalced == false)
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20f"));

            }
            catch (Exception ex)
            {
                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_20a") + "\n" + ex.Message);
            }
            finally
            {

                pMap = null;
                pFLayer = null;
                if (pFCursor != null)
                    Marshal.ReleaseComObject(pFCursor);
                pFCursor = null;
                pFeature = null;

                pSnappedPoint = null;
                pNetElements = null;
            }
        }