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); }
private List <IPoint> ParseVirtualBarriers(JsonObject[] barrierJsonArray, uint epsg)//lazy here, just copy epsg from flag and assume barriers having the same one { List <IPoint> ret = null; if (null != barrierJsonArray && barrierJsonArray.Length > 0) { JsonObject barrierFeature = null; IPoint pnt = null; IGeometryArray pntArr1 = new GeometryArrayClass(); for (int i = 0; i < barrierJsonArray.Length; ++i) { if (barrierJsonArray[i].TryGetJsonObject("geometry", out barrierFeature)) { if (null != barrierFeature) { double?x, y; //int? epsg; if (barrierFeature.TryGetAsDouble("x", out x) && barrierFeature.TryGetAsDouble("y", out y)) { pnt = new PointClass(); pnt.X = x.Value; pnt.Y = y.Value; pntArr1.Add(pnt); } } } } if (pntArr1.Count > 0) { IGeometryArray geomArr = AOUtilities.TransfromGeometriesFrom2(epsg, (uint)this.m_networkEPSG, pntArr1); if (null != geomArr && geomArr.Count > 0) { ret = new List <IPoint>(); for (int i = 0; i < geomArr.Count; ++i) { ret.Add(geomArr.get_Element(i) as IPoint); } } } } return(ret); }
public void CoordinatesReProjection() { //Arrange IPoint pnt1 = new PointClass(); pnt1.X = -9569447.832126; pnt1.Y = 5524225.232441; //pnt1.SpatialReference = AOUtilities.GetSpatialReference(3857); IGeometryArray pntArr1 = new GeometryArrayClass(); pntArr1.Add(pnt1); //Act //The SpatialReference property for all returned geometries will be null. It is the consumers responsibility to assign the //spatial reference to each geometry returned, if desired. In this case, the spatial reference is assumed to be the output spatial reference defined for the Project operation. IGeometryArray geomArr = AOUtilities.TransfromGeometriesFrom2(3857, 4269, pntArr1); //It appears IGeometryServer2.Project will NOT throw an error if the coordinates don't match the given epsg //instead, it simply returns the input coordinates as output... IGeometryArray geomArr1 = AOUtilities.TransfromGeometriesFrom2(4326, 4269, pntArr1); //Assert Assert.IsNotNull(geomArr); Assert.IsNotNull(geomArr1); Assert.AreEqual <int>(pntArr1.Count, geomArr.Count); Assert.AreEqual <int>(pntArr1.Count, geomArr1.Count); IPoint pnt2 = geomArr.get_Element(0) as IPoint; Assert.IsNotNull(pnt2); pnt2 = geomArr1.get_Element(0) as IPoint; Assert.IsNotNull(pnt2); //Act geomArr1 = AOUtilities.TransfromGeometriesFrom2(4269, 4326, geomArr); //Assert Assert.IsNotNull(geomArr1); Assert.AreEqual <int>(geomArr1.Count, geomArr.Count); pnt2 = geomArr1.get_Element(0) as IPoint; IPoint pnt3 = geomArr.get_Element(0) as IPoint; Assert.IsNotNull(pnt2); //Since the output geometry will not have spatial reference assigned, we can't verify if the output are in the desired projection through this shortcut. //Assert.IsTrue(4326 == pnt2.SpatialReference.FactoryCode); //Assert.IsTrue(4269 == pnt3.SpatialReference.FactoryCode); //Arrange pntArr1.RemoveAll(); pntArr1.Add(pnt2); //Act geomArr = AOUtilities.TransfromGeometriesFrom2(4269, 3857, pntArr1); //Assert Assert.IsNotNull(geomArr); Assert.AreEqual <int>(pntArr1.Count, geomArr.Count); pnt2 = geomArr.get_Element(0) as IPoint; Assert.IsNotNull(pnt2); Assert.IsTrue((Math.Abs(pnt2.X - pnt1.X) < 1e-7) && (Math.Abs(pnt2.Y - pnt1.Y) < 1e-7)); //Arrange pnt1.X = double.MinValue; pnt1.Y = double.PositiveInfinity; pntArr1.RemoveAll(); pntArr1.Add(pnt1); //Act geomArr = AOUtilities.TransfromGeometriesFrom2(3857, 4269, pntArr1); pnt2 = geomArr.get_Element(0) as IPoint; //Assert Assert.IsTrue(pnt2.IsEmpty); double x = pnt2.X; }
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())); }