コード例 #1
0
        public void TestIdentifyUninitializedStreamSegment()
        {
            //Arrange
            NetworkContext ctx = new NetworkContext("Hydro", new List <string>()
            {
                "FlowlineMerge"
            }, new List <string>()
            {
                "Hydro_Net_Junctions", "Barriers"
            });

            ctx.LoadGeometricNetwork(GN_Path, null, null);

            //Get FlowDir index
            IFeatureClass fc  = ctx.GetEdgeFeatureClassByAliasName("FlowlineMerge");
            int           idx = AOUtilities.GetFieldIndexByName(fc, "FlowDir");
            IPoint        pnt = new PointClass()
            {
                X = -85.04465103149414,
                Y = 43.27143070627271
            };
            IGeometryArray pntArr = new GeometryArrayClass();

            pntArr.Add(pnt);
            IGeometryArray geomArr = AOUtilities.TransfromGeometriesFrom2(4326, 4269, pntArr);
            IPoint         pnt1    = geomArr.get_Element(0) as IPoint;

            //Act
            StartFlagEdge flag = NetworkHelper.GetStartFlagEdge(ctx, pnt1.X, pnt1.Y, 200, 5, "FlowlineMerge", idx, "0", null);

            //Assert
            Assert.IsNull(flag);
        }
コード例 #2
0
        public void ConstrcutStartEdge()
        {
            //Arrange
            NetworkContext ctx = new NetworkContext("Hydro", new List <string>()
            {
                "FlowlineMerge"
            }, new List <string>()
            {
                "Hydro_Net_Junctions", "Barriers"
            });

            ctx.LoadGeometricNetwork(GN_Path, null, null);
            //Flag
            IPoint pnt = new PointClass();

            pnt.X = -86.291;
            pnt.Y = 43.941;
            IFeatureClass fc  = ctx.GetEdgeFeatureClassByAliasName("FlowlineMerge");
            int           idx = AOUtilities.GetFieldIndexByName(fc, "FlowDir");


            //Act
            StartFlagEdge flag = NetworkHelper.GetStartFlagEdge(ctx, -86.291, 43.941, 100, 5, "FlowlineMerge", idx, "0", null);

            //Assert
            Assert.IsNotNull(flag);
            Assert.IsTrue(flag.FeatureID == 1927894);
        }
コード例 #3
0
        public void TraceStream()
        {
            //Arrange
            NetworkContext ctx = new NetworkContext("Hydro", new List <string>()
            {
                "FlowlineMerge"
            }, new List <string>()
            {
                "Hydro_Net_Junctions", "Barriers"
            });

            ctx.LoadGeometricNetwork(GN_Path, null, null);
            //Flag
            IFeatureClass fc   = ctx.GetEdgeFeatureClassByAliasName("FlowlineMerge");
            int           idx  = AOUtilities.GetFieldIndexByName(fc, "FlowDir");
            StartFlagEdge flag = NetworkHelper.GetStartFlagEdge(ctx, -85.062153, 44.003813, 1000, 5, "FlowlineMerge", idx, "0", null);
            //All Existing Barriers
            List <int> fcid = new List <int>()
            {
                ctx.GetJunctionFeatureClassIdByAliasName("Barriers").FeatureClassID
            };
            //Virtual Barriers
            IPoint pnt = new PointClass();

            pnt.X = -85.021764;
            pnt.Y = 44.122331;
            IPoint pnt1 = new PointClass();

            pnt1.X = -84.974754;
            pnt1.Y = 44.162720;
            IPoint pnt2 = new PointClass();

            pnt2.X = -84.896625;
            pnt2.Y = 44.128;
            List <IPoint> pnts = new List <IPoint>()
            {
                pnt, pnt1, pnt2
            };
            StopperJunctions stoppers1 = NetworkHelper.GetStoppers(ctx, pnts, true, 1000, 5, "FlowlineMerge", "Hydro_Net_Junctions", null);

            //Act
            //Do upstream first
            List <int> ftrList = AOUtilities.StreamTrace(ctx.GeometricNetwork, flag, fcid, stoppers1, true, 1000, null);

            //Assert
            Assert.IsNotNull(ftrList);
            List <string> ids = new List <string>();

            foreach (var ftr in ftrList)
            {
                ids.Add(ftr.ToString());
            }
            //System.Diagnostics.Debug.WriteLine(string.Join(",", ids.ToArray()));

            //Act
            //Do upstream again without stoppers to test if the previous setting is gone
            ftrList = AOUtilities.StreamTrace(ctx.GeometricNetwork, flag, fcid, null, true, 1000, null);

            //Assert
            Assert.IsNotNull(ftrList);
            ids = new List <string>();
            foreach (var ftr in ftrList)
            {
                ids.Add(ftr.ToString());
            }
            //System.Diagnostics.Debug.WriteLine(string.Join(",", ids.ToArray()));

            //Act
            //downstream
            ftrList = AOUtilities.StreamTrace(ctx.GeometricNetwork, flag, fcid, null, false, 1000, null);

            //Assert
            Assert.IsNotNull(ftrList);
            ids = new List <string>();
            foreach (var ftr in ftrList)
            {
                ids.Add(ftr.ToString());
            }
            //System.Diagnostics.Debug.WriteLine(string.Join(",", ids.ToArray()));
            IRecordSet records = AOUtilities.GetRecordSetFromFeatureClass(ctx.GetEdgeFeatureClassByAliasName("FlowlineMerge"), ftrList, new List <string>()
            {
                "Shape_Length"
            }, 3857);

            Assert.IsNotNull(records);
            //How to update a feature
            //http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/d/0001000002rs000000.htm

            /*ICursor ftrCursor = records.get_Cursor(true);
             * try
             * {
             *  IRow row = ftrCursor.NextRow();
             *  IFeature ftr = row as IFeature;
             *  esriFeatureType type = ftr.FeatureType;
             *  esriGeometryType t1 = ftr.Shape.GeometryType;
             *
             *  IRow row1 = ftrCursor.NextRow();
             *  IFeature ftr1 = row as IFeature;
             *
             *  ftr.Shape = ftr1.ShapeCopy;
             * }
             * catch(Exception e)
             * {
             *  string err = e.Message;
             * }
             * finally
             * {
             *  AOUtilities.ReleaseCOMObj(ftrCursor);
             * }*/
            JsonObject json = new JsonObject(System.Text.Encoding.UTF8.GetString(Conversion.ToJson(records)));

            Assert.IsNotNull(json);
            //System.Diagnostics.Debug.WriteLine(json.ToJson());
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        private byte[] NetworkTraceHandler(NameValueCollection boundVariables,
                                           JsonObject operationInput,
                                           string outputFormat,
                                           string requestProperties,
                                           out string responseProperties)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            responseProperties = null;

            string traceTypeStr;
            bool   found = operationInput.TryGetString(TracingDirParameterName, out traceTypeStr);

            if (!found || string.IsNullOrEmpty(traceTypeStr))
            {
                throw new ArgumentNullException(TracingDirParameterName + " is required");
            }
            traceTypeStr = traceTypeStr.ToUpper();
            bool?isUpstream = null;

            if ("TRACE_UPSTREAM" == traceTypeStr)
            {
                isUpstream = true;
            }
            else if ("TRACE_DOWNSTREAM" == traceTypeStr)
            {
                isUpstream = false;
            }
            if (false == isUpstream.HasValue)
            {
                throw new ArgumentException("Not valid Trace_Task_type");
            }

            long?outEPSG;

            found = operationInput.TryGetAsLong(OutputEPSGParameterName, out outEPSG);
            if (!found || !outEPSG.HasValue || outEPSG <= 0)
            {
                throw new ArgumentNullException(OutputEPSGParameterName + " is required");
            }
            if (outEPSG < 1)
            {
                throw new ArgumentException(OutputEPSGParameterName + " is not valid");
            }

            JsonObject flagJSON = null;

            object[]     flagArray     = null;
            JsonObject[] flagJsonArray = null;
            if (false == operationInput.TryGetJsonObject(FlagParameterName, out flagJSON) || null == flagJSON)
            {
                throw new ArgumentNullException(FlagParameterName + " is required");
            }
            if (flagJSON.TryGetArray("features", out flagArray))
            {
                try
                {
                    flagJsonArray = flagArray.Cast <JsonObject>().ToArray();
                }
                catch
                {
                    throw new ArgumentException("invalid Flags json format");
                }
            }
            //Found the flag
            List <int> ftrList = null;

            if (null != flagJsonArray && 1 == flagJsonArray.Length)
            {
                JsonObject flagFeature = null;
                if (flagJsonArray[0].TryGetJsonObject("geometry", out flagFeature))
                {
                    if (null == flagFeature)
                    {
                        throw new ArgumentException("invalid Flags json format with geometry");
                    }
                    double?    x, y;
                    long?      epsg;
                    JsonObject srsObj;
                    if (true == flagFeature.TryGetJsonObject("spatialReference", out srsObj))
                    {
                        if (false == srsObj.TryGetAsLong("wkid", out epsg) || epsg <= 0)
                        {
                            throw new ArgumentException("No valid wikd found for flag feature.");
                        }
                    }
                    else
                    {
                        throw new ArgumentException("No spatial reference found for flag feature.");
                    }
                    if (flagFeature.TryGetAsDouble("x", out x) && flagFeature.TryGetAsDouble("y", out y))
                    {
                        if (!x.HasValue || !y.HasValue)
                        {
                            throw new ArgumentException("invalid Flag coordinate");
                        }
                        IPoint pnt1 = new PointClass();
                        pnt1.X = x.Value;
                        pnt1.Y = y.Value;
                        IGeometryArray pntArr1 = new GeometryArrayClass();
                        pntArr1.Add(pnt1);
                        IGeometryArray geomArr = AOUtilities.TransfromGeometriesFrom2((uint)epsg, (uint)this.m_networkEPSG, pntArr1);
                        if (null == geomArr || 1 != geomArr.Count)
                        {
                            throw new ArgumentException("invalid Flag coordinate for reprojection");
                        }
                        pnt1 = geomArr.get_Element(0) as IPoint;
                        StartFlagEdge    flag     = NetworkHelper.GetStartFlagEdge(this.m_networkContext, pnt1.X, pnt1.Y, TracingSOE.m_searchDistance, TracingSOE.m_searchTolerance, FlowLineName, this.m_flowDirFieldIndex, InvalidFlowDirValue, logger);
                        StopperJunctions stoppers = null;
                        if (null != flag)
                        {
                            List <IPoint> barrierPnts      = null;
                            JsonObject    barriersJSON     = null;
                            object[]      barrierArray     = null;
                            JsonObject[]  barrierJsonArray = null;
                            if (true == operationInput.TryGetJsonObject(BarrierParameterName, out barriersJSON) || null != barriersJSON)
                            {
                                if (barriersJSON.TryGetArray("features", out barrierArray))
                                {
                                    try
                                    {
                                        barrierJsonArray = barrierArray.Cast <JsonObject>().ToArray();
                                        barrierPnts      = ParseVirtualBarriers(barrierJsonArray, (uint)epsg);
                                    }
                                    catch
                                    {
                                        throw new ArgumentException("invalid Barriers json format");
                                    }
                                }
                                if (null != barrierPnts && barrierPnts.Count > 0)
                                {
                                    stoppers = NetworkHelper.GetStoppers(this.m_networkContext, barrierPnts, isUpstream.Value, TracingSOE.m_searchDistance, TracingSOE.m_searchTolerance, FlowLineName, JunctionName, logger);
                                }
                            }
                        }
                        ftrList = AOUtilities.StreamTrace(this.m_networkContext.GeometricNetwork, flag, this.m_disabledFeatureClassIDs, stoppers, isUpstream.Value, this.m_maxFeatureCount, logger);
                    }
                }
            }
            IRecordSet records = null;

            if (null != ftrList && ftrList.Count > 0)
            {
                records = AOUtilities.GetRecordSetFromFeatureClass(this.m_networkContext.GetEdgeFeatureClassByAliasName(FlowLineName), ftrList, this.m_outputFields, (uint)outEPSG.Value);
            }
            JsonObject result = new JsonObject();

            if (null != records)
            {
                result.AddJsonObject("value", new JsonObject(System.Text.Encoding.UTF8.GetString(Conversion.ToJson(records))));
            }
            else
            {
                result.AddString("output", "{}");
            }
            watch.Stop();
            this.logger.LogMessage(ServerLogger.msgType.debug, "NetworkTraceHandler", 973, "Tracing taked: " + watch.ElapsedMilliseconds.ToString() + " ms");
            result.AddLong("time(ms)", watch.ElapsedMilliseconds);
            return(Encoding.UTF8.GetBytes(result.ToJson()));
        }