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()); }
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())); }